Package net.juniper.contrail.api

Examples of net.juniper.contrail.api.ApiConnector


        return _uuid.compareTo(other._uuid);
    }

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

        if (_policyModel != null) {
            _policyModel.removeSuccessor(this);
        }

        try {
            api.delete(VirtualNetwork.class, _uuid);
        } catch (IOException ex) {
            s_logger.warn("virtual-network delete", ex);
        }
    }
View Full Code Here


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

        assert _initialized;

        ApiConnector api = controller.getApiAccessor();
        VlanDao vlanDao = controller.getVlanDao();
        VirtualNetwork vn = _vn;
       
        if (!isDynamicNetwork()) {
            _vn = (VirtualNetwork) controller.getApiAccessor().findById(VirtualNetwork.class, _uuid);
            return;
        }
       
        assert _uuid != null : "uuid is not set";

        if (_vn == null) {
            vn = _vn = (VirtualNetwork) controller.getApiAccessor().findById(VirtualNetwork.class, _uuid);
            if (vn == null) {
                vn = new VirtualNetwork();
                if (_projectId != null) {
                    Project project;
                    try {
                        project = (Project) api.findById(Project.class, _projectId);
                    } catch (IOException ex) {
                        s_logger.debug("project read", ex);
                        throw new CloudRuntimeException("Failed to read project", ex);                   
                    }
                    vn.setParent(project);
                }
                vn.setName(_name);
                vn.setUuid(_uuid);
            }
        }

        if (_policyModel == null) {
            vn.clearNetworkPolicy();
        } else if (!_policyModel.hasPolicyRules()) {
            vn.clearNetworkPolicy();
            _policyModel.removeSuccessor(this);
        } else {
            vn.setNetworkPolicy(_policyModel.getPolicy(), new VirtualNetworkPolicyType(
                    new VirtualNetworkPolicyType.SequenceType(1, 0), null));
        }
    
        if (_ipam == null) {
            NetworkIpam ipam = null;
            try {
                String ipam_id = api.findByName(NetworkIpam.class, null, "default-network-ipam");
                if (ipam_id == null) {
                    s_logger.debug("could not find default-network-ipam");
                    return;
                }
                ipam = (NetworkIpam) api.findById(NetworkIpam.class, ipam_id);
                if (ipam == null) {
                    s_logger.debug("could not find NetworkIpam with ipam_id: " + ipam_id);
                    return;
                }
            } catch (IOException ex) {
                s_logger.error(ex);
                return;
            }
            _ipam = ipam;
        }

        if (_prefix != null) {
            VnSubnetsType subnet = new VnSubnetsType();
            String[] addr_pair = _prefix.split("\\/");
            subnet.addIpamSubnets(new SubnetType(addr_pair[0], Integer.parseInt(addr_pair[1])), _gateway);
            vn.setNetworkIpam(_ipam, subnet);
        } else if (_trafficType == TrafficType.Public) {
            vn.clearNetworkIpam();
            /* Subnet information for Public is stored in the vlan table */
            List<VlanVO> vlan_list = vlanDao.listVlansByNetworkId(_id);
            for (VlanVO vlan : vlan_list) {
                String cidr = NetUtils.ipAndNetMaskToCidr(vlan.getVlanGateway(), vlan.getVlanNetmask());
                int slash = cidr.indexOf('/');
                String ip_addr = cidr.substring(0, slash);
                int plen = Integer.parseInt(cidr.substring(slash + 1));
                VnSubnetsType subnet = new VnSubnetsType();
                subnet.addIpamSubnets(new SubnetType(ip_addr, plen), vlan.getVlanGateway());
                vn.addNetworkIpam(_ipam, subnet);
            }
        }

        if (_vn == null) {
            try {
                api.create(vn);
            } catch (Exception ex) {
                s_logger.debug("virtual-network create", ex);
                throw new CloudRuntimeException("Failed to create virtual-network", ex);
            }
            _vn = vn;
        } else {
            try {
                api.update(vn);
            } catch (IOException ex) {
                s_logger.warn("virtual-network update", ex);
                throw new CloudRuntimeException("Unable to update virtual-network object", ex);
            }           
        }
View Full Code Here

            successor.update(controller);
        }
    }

    public void read(ModelController controller) {
        ApiConnector api = controller.getApiAccessor();
        VlanDao vlanDao = controller.getVlanDao();
        try {
            _vn = (VirtualNetwork) api.findById(VirtualNetwork.class, _uuid);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (_vn == null) {
            return;
        }
        if (_ipam == null) {
            NetworkIpam ipam = null;
            try {
                String ipam_id = api.findByName(NetworkIpam.class, null, "default-network-ipam");
                if (ipam_id == null) {
                    s_logger.debug("could not find default-network-ipam");
                    return;
                }
                ipam = (NetworkIpam) api.findById(NetworkIpam.class, ipam_id);
                if (ipam == null) {
                    s_logger.debug("could not find NetworkIpam with ipam_id: " + ipam_id);
                    return;
                }
            } catch (IOException ex) {
View Full Code Here

    @Override
    public boolean verify(ModelController controller) {
        assert _initialized : "initialized is false";
        assert _uuid != null : "uuid is not set";

        ApiConnector api = controller.getApiAccessor();
        VlanDao vlanDao = controller.getVlanDao();

        try {
            _vn = (VirtualNetwork) api.findById(VirtualNetwork.class, _uuid);
        } catch (IOException e) {
            e.printStackTrace();
        }

        if (_vn == null) {
View Full Code Here

        }
        if (right.getTrafficType() == TrafficType.Guest) {
            _networkModel.checkNetworkPermissions(owner, right);
        }
       
        final ApiConnector api = _manager.getApiConnector();
        VirtualNetworkModel leftModel = _manager.getDatabase().lookupVirtualNetwork(left.getUuid(),
                _manager.getCanonicalName(left), left.getTrafficType());
        if (leftModel == null) {
            throw new CloudRuntimeException("Unable to read virtual-network object");
        }
        VirtualNetworkModel rightModel = _manager.getDatabase().lookupVirtualNetwork(right.getUuid(),
                _manager.getCanonicalName(right), right.getTrafficType());
        if (rightModel == null) {
            throw new CloudRuntimeException("Unable to read virtual-network object");
        }

        net.juniper.contrail.api.types.Project project;
        try {
            project = _manager.getVncProject(owner.getDomainId(), owner.getAccountId());
        } catch (IOException ex) {
            s_logger.warn("read project", ex);
            throw new CloudRuntimeException(ex);
        }
       
        try {
            final String srvid = api.findByName(ServiceInstance.class, project, name);
            if (srvid != null) {
                throw new InvalidParameterValueException("service-instance " + name + " already exists uuid=" + srvid);
            }
        } catch (IOException ex) {
            s_logger.warn("service-instance lookup", ex);
View Full Code Here

     * @param controller
     * @param serviceUuid
     */
    private void buildServiceInstance(ModelController controller, String serviceUuid) {
        ContrailManager manager = controller.getManager();
        ApiConnector api = controller.getApiAccessor();
        _serviceUuid = serviceUuid;
       
        ServiceInstance siObj;
        try {
            siObj = (ServiceInstance) api.findById(ServiceInstance.class, serviceUuid);
        } catch (IOException ex) {
            s_logger.warn("service-instance read", ex);
            throw new CloudRuntimeException("Unable to read service-instance object", ex);
        }
        ServiceInstanceModel siModel;
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(VirtualMachine.class, _uuid);
        } catch (IOException ex) {
            s_logger.warn("virtual-machine delete", ex);
        }

View Full Code Here

    }
   
    @Override
    public void update(ModelController controller) throws InternalErrorException, IOException {
        assert _initialized;
        ApiConnector api = controller.getApiAccessor();

        VirtualMachine vm = _vm;
        if (vm == null) {
            _vm = vm = (VirtualMachine) api.findById(VirtualMachine.class, _uuid);
            if (vm == null) {
                vm = new VirtualMachine();
                if (_projectId != null) {
                    Project project;
                    try {
                        project = (Project) api.findById(Project.class, _projectId);
                    } catch (IOException ex) {
                        s_logger.debug("project read", ex);
                        throw new CloudRuntimeException("Failed to read project", ex);                   
                    }
                    vm.setParent(project);
                }
                vm.setName(_instanceName);
                vm.setUuid(_uuid);
            }
        }

        if (_serviceModel != null) {
            vm.setServiceInstance(_serviceModel.getServiceInstance());
        }

        if (_vm == null) {
            try {
                api.create(vm);
            } catch (Exception ex) {
                s_logger.debug("virtual-machine create", ex);
                throw new CloudRuntimeException("Failed to create virtual-machine", ex);
            }
            _vm = vm;
        } else {
            try {
                api.update(vm);
            } catch (IOException ex) {
                s_logger.warn("virtual-machine update", ex);
                throw new CloudRuntimeException("Unable to update virtual-machine object", ex);
            }           
        }
View Full Code Here

   
    @Override
    public boolean verify(ModelController controller) {
        assert _initialized : "initialized is false";
        assert _uuid != null : "uuid is not set";
        ApiConnector api = controller.getApiAccessor();
        try {
            _vm = (VirtualMachine) api.findById(VirtualMachine.class, _uuid);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (_vm == null) {
            return false;
View Full Code Here

    /**
     * Recreate the model object from the Contrail API which is the master for this type of object.
     * @param siObj
     */
    public void build(ModelController controller, ServiceInstance siObj) {
        ApiConnector api = controller.getApiAccessor();
        _serviceInstance = siObj;
        _fq_name = StringUtils.join(siObj.getQualifiedName(), ':');
        ServiceInstanceType props = siObj.getProperties();
        // TODO: read management network names and cache network objects.
        ObjectReference ref = siObj.getServiceTemplate().get(0);
        if (ref != null) {
            try {
                ServiceTemplate tmpl = (ServiceTemplate) api.findById(ServiceTemplate.class, ref.getUuid());
                _templateId = tmpl.getUuid();
            } catch (IOException ex) {
                s_logger.warn("service-template read", ex);
            }
        }
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.