Package net.juniper.contrail.api

Examples of net.juniper.contrail.api.ApiConnector


   
    private ServiceInstance createServiceInstance(ModelController controller) {
        Project project  = null;
        if (_projectId != null) {
            try {
                ApiConnector api = controller.getApiAccessor();
                project = (Project) api.findById(Project.class, _projectId);
           } catch (IOException ex) {
                s_logger.warn("project read", ex);
                throw new CloudRuntimeException("Unable to create service-instance object", ex);           
           }
        }

        ServiceInstance si_obj = new ServiceInstance();
        if (project != null) {
            si_obj.setParent(project);
        }
        si_obj.setName(getName());
        si_obj.setServiceTemplate(_tmpl);
        si_obj.setProperties(new ServiceInstanceType(false, _mgmtName, _leftName, null, _rightName, null,
                new ServiceInstanceType.ServiceScaleOutType(1, false)));
        try {
            ApiConnector api = controller.getApiAccessor();
            api.create(si_obj);
        } catch (IOException ex) {
            s_logger.warn("service-instance create", ex);
            throw new CloudRuntimeException("Unable to create service-instance object", ex);
        }
       
View Full Code Here


        return policyModel;
    }
   
    @Override
    public void delete(ModelController controller) throws IOException {
        ApiConnector api = controller.getApiAccessor();
        clearServicePolicy(controller);
        if (_serviceInstance != null) {
            api.delete(_serviceInstance);
        }
    }
View Full Code Here

    }
   
    private ServiceTemplate locateServiceTemplate(ModelController controller) {
        ServiceTemplate tmpl;
        try {
            ApiConnector api = controller.getApiAccessor();
            tmpl = (ServiceTemplate) api.findById(ServiceTemplate.class, _templateId);
        } catch (IOException ex) {
            s_logger.warn("service-template read", ex);
            throw new CloudRuntimeException("Unable to create service-template object", ex);
        }
        if (tmpl == null) {
            tmpl = new ServiceTemplate();
            tmpl.setName(_templateName);
            tmpl.setUuid(_templateId);
            ServiceTemplateType props = new ServiceTemplateType("in-network", null, _templateUrl, false, null);
            tmpl.setProperties(props);
            try {
                ApiConnector api = controller.getApiAccessor();
                api.create(tmpl);
            } catch (IOException ex) {
                throw new CloudRuntimeException("Unable to create service-template object", ex);
            }
        }
        return tmpl;
View Full Code Here

        return _name.compareTo(other._name);
    }

    @Override
    public void delete(ModelController controller) throws IOException {
        ApiConnector api = controller.getApiAccessor();
        if (_uuid != null) {
            api.delete(InstanceIp.class, _uuid);
        }
        _uuid = null;
    }
View Full Code Here

    @Override
    public void update(ModelController controller)
            throws InternalErrorException, IOException {
        assert _vmiModel != null;
               
        ApiConnector api = controller.getApiAccessor();
        VirtualNetworkModel vnModel = _vmiModel.getVirtualNetworkModel();
        assert vnModel != null;
               
        VirtualMachineInterface vmi = _vmiModel.getVMInterface();
        VirtualNetwork vnet = vnModel.getVirtualNetwork();
        if (vnet == null) {
            vnet = (VirtualNetwork) api.findById(VirtualNetwork.class, _vmiModel.getNetworkUuid());
        }
       
        String ipid = api.findByName(InstanceIp.class, null, _name);
        if (ipid == null) {
            InstanceIp ip_obj = new InstanceIp();
            ip_obj.setName(_name);
            ip_obj.setVirtualNetwork(vnet);
            if (_ipAddress != null) {
                ip_obj.setAddress(_ipAddress);
            }
            ip_obj.setVirtualMachineInterface(vmi);
            if (!api.create(ip_obj)) {
                throw new InternalErrorException("Unable to create instance-ip " +  _name);
            }
            api.read(ip_obj);
            _uuid = ip_obj.getUuid();
            if (_ipAddress == null) {
                if (!api.read(ip_obj)) {
                    throw new InternalErrorException("Unable to read instance-ip " +  _name);
                }
            }
            _ipAddress = ip_obj.getAddress();
        } else {
            // Ensure that the instance-ip has the correct value and is pointing at the VMI.
            InstanceIp ip_obj = (InstanceIp) api.findById(InstanceIp.class, ipid);
            if (ip_obj == null) {
                throw new InternalErrorException("Unable to read instance-ip " +  _name);
            }
            boolean update = false;
            String ipnet_id = ObjectReference.getReferenceListUuid(ip_obj.getVirtualNetwork());
            if (ipnet_id == null || !ipnet_id.equals(_vmiModel.getNetworkUuid())) {
                ip_obj.setVirtualNetwork(vnet);
                update = true;
            }

            if (_ipAddress != null && !ip_obj.getAddress().equals(_ipAddress)) {
                ip_obj.setAddress(_ipAddress);
                update = true;
            }
           
            String vmi_id = ObjectReference.getReferenceListUuid(ip_obj.getVirtualMachineInterface());
            if (vmi_id == null || !vmi_id.equals(_vmiModel.getUuid())) {
                if (vmi != null) {
                    ip_obj.setVirtualMachineInterface(vmi);
                    update = true;
                }
            }

            if (update && !api.update(ip_obj)) {
                throw new InternalErrorException("Unable to update instance-ip: " + ip_obj.getName());
            }
            api.read(ip_obj);
            _uuid = ip_obj.getUuid();
            _ipAddress = ip_obj.getAddress();
        }       
    }
View Full Code Here

        return _uuid.compareTo(other._uuid);
    }

    @Override
    public void delete(ModelController controller) throws IOException {
        ApiConnector api = controller.getApiAccessor();
        for (ModelObject successor: successors()) {
            successor.delete(controller);
        }

        try {
            api.delete(FloatingIp.class, _uuid);
        } catch (IOException ex) {
            s_logger.warn("floating ip delete", ex);
        }
    }
View Full Code Here

    @Override
    public void update(ModelController controller) throws InternalErrorException, IOException {

        assert _initialized;

        ApiConnector api = controller.getApiAccessor();
        ContrailManager manager = controller.getManager();
        FloatingIp fip = _fip;

        if (_fip == null) {
            _fip = fip = (FloatingIp) controller.getApiAccessor().findById(FloatingIp.class, _uuid);
            if (fip == null) {
                fip = new FloatingIp();
                fip.setUuid(_uuid);
                fip.setAddress(_addr);
                fip.setName(_name);
                fip.setParent(_fipPoolModel.getFloatingIpPool());
            }
        }

        IPAddressVO ipAddrVO = controller.getIPAddressDao().findById(_id);
        assert ipAddrVO != null : "can not find address object in db";
        Long vmId = ipAddrVO.getAssociatedWithVmId();
        Long networkId = ipAddrVO.getAssociatedWithNetworkId();
        if (vmId == null || networkId == null) {
            s_logger.debug("Floating ip is not yet associated to either vm or network");
            return;
        }
        NicVO nic = controller.getNicDao().findByNtwkIdAndInstanceId(networkId, vmId);
        assert nic != null : "can not find nic for the given network and vm in db";

        VMInstanceVO vm = controller.getVmDao().findById(vmId);
        assert vm != null : "can not find vm in db";

        VirtualMachineModel vmModel = manager.getDatabase().lookupVirtualMachine(vm.getUuid());
        assert vmModel != null : "can not find vm model";

        VMInterfaceModel vmiModel = vmModel.getVMInterface(nic.getUuid());
        assert vmiModel != null && vmiModel.getVMInterface() != null : "can not find virtual machine interface";

        fip.setVirtualMachineInterface(vmiModel.getVMInterface());

        if (_fip == null) {
            try {
                api.create(fip);
            } catch (Exception ex) {
                s_logger.debug("floating ip create", ex);
                throw new CloudRuntimeException("Failed to create floating ip", ex);
            }
            _fip = fip;
        } else {
            try {
                api.update(fip);
            } catch (IOException ex) {
                s_logger.warn("floating ip update", ex);
                throw new CloudRuntimeException("Unable to update floating ip object", ex);
            }           
        }
View Full Code Here

        return 0;
    }

    @Override
    public void delete(ModelController controller) throws IOException {
        ApiConnector api = controller.getApiAccessor();
        for (ModelObject successor: successors()) {
            successor.delete(controller);
        }
        try {
            if (_fipPool != null) {
                api.delete(_fipPool);
            }
            _fipPool = null;
        } catch (IOException ex) {
            s_logger.warn("floating ip pool delete", ex);
        }
View Full Code Here

    @Override
    public void update(ModelController controller) throws InternalErrorException, IOException {

        assert _vnModel != null : "vn model is not set";

        ApiConnector api = controller.getApiAccessor();
        ContrailManager manager = controller.getManager();
        FloatingIpPool fipPool = _fipPool;

        if (fipPool == null) {
            String fipPoolName = manager.getDefaultPublicNetworkFQN() + ":PublicIpPool";
            _fipPool = fipPool = (FloatingIpPool) controller.getApiAccessor().findByFQN(FloatingIpPool.class, fipPoolName);
            if (fipPool == null) {
                fipPool = new FloatingIpPool();
                fipPool.setName(_name);
                fipPool.setParent(_vnModel.getVirtualNetwork());
            }
        }

        if (_fipPool == null) {
            try {
                api.create(fipPool);
            } catch (Exception ex) {
                s_logger.debug("floating ip pool create", ex);
                throw new CloudRuntimeException("Failed to create floating ip pool", ex);
            }
            _fipPool = fipPool;
        } else {
            try {
                api.update(fipPool);
            } catch (IOException ex) {
                s_logger.warn("floating ip pool update", ex);
                throw new CloudRuntimeException("Unable to update floating ip ppol object", ex);
            }           
        }
View Full Code Here

    public void delete(ModelController controller) throws IOException {
        for (ModelObject successor: successors()) {
            successor.delete(controller);
        }

        ApiConnector api = controller.getApiAccessor();
        api.delete(VirtualMachineInterface.class, _uuid);       
    }
View Full Code Here

TOP

Related Classes of net.juniper.contrail.api.ApiConnector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.