Search in sources :

Example 31 with ApiConnector

use of net.juniper.contrail.api.ApiConnector in project cloudstack by apache.

the class FloatingIpPoolModel method update.

@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);
        }
    }
    for (ModelObject successor : successors()) {
        successor.update(controller);
    }
}
Also used : FloatingIpPool(net.juniper.contrail.api.types.FloatingIpPool) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ApiConnector(net.juniper.contrail.api.ApiConnector) ContrailManager(org.apache.cloudstack.network.contrail.management.ContrailManager) IOException(java.io.IOException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InternalErrorException(com.cloud.exception.InternalErrorException) IOException(java.io.IOException)

Example 32 with ApiConnector

use of net.juniper.contrail.api.ApiConnector in project cloudstack by apache.

the class InstanceIpModel method update.

@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();
    }
}
Also used : VirtualNetwork(net.juniper.contrail.api.types.VirtualNetwork) VirtualMachineInterface(net.juniper.contrail.api.types.VirtualMachineInterface) ApiConnector(net.juniper.contrail.api.ApiConnector) InstanceIp(net.juniper.contrail.api.types.InstanceIp) InternalErrorException(com.cloud.exception.InternalErrorException)

Example 33 with ApiConnector

use of net.juniper.contrail.api.ApiConnector in project cloudstack by apache.

the class NetworkPolicyModel method update.

@Override
public void update(ModelController controller) throws InternalErrorException, IOException {
    ApiConnector api = controller.getApiAccessor();
    if (_project == null) {
        s_logger.debug("Project is null for the policy: " + _name);
        throw new IOException("Project is null for the policy: " + _name);
    }
    NetworkPolicy policy = _policy;
    if (policy == null) {
        try {
            String policyId = api.findByName(NetworkPolicy.class, _project, _name);
            if (policyId != null) {
                policy = _policy = (NetworkPolicy) api.findById(NetworkPolicy.class, policyId);
            }
            if (policy == null) {
                policy = new NetworkPolicy();
                policy.setUuid(_uuid);
                policy.setName(_name);
                policy.setParent(_project);
            }
        } catch (IOException ex) {
            s_logger.warn("network-policy read", ex);
            return;
        }
    }
    policy.setEntries(_policyMap);
    if (_policy == null) {
        try {
            api.create(policy);
        } catch (Exception ex) {
            s_logger.debug("network policy create", ex);
            throw new CloudRuntimeException("Failed to create network policy", ex);
        }
        _policy = policy;
    } else {
        try {
            api.update(policy);
        } catch (IOException ex) {
            s_logger.warn("network policy update", ex);
            throw new CloudRuntimeException("Unable to update network policy", ex);
        }
    }
    for (ModelObject successor : successors()) {
        successor.update(controller);
    }
}
Also used : NetworkPolicy(net.juniper.contrail.api.types.NetworkPolicy) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ApiConnector(net.juniper.contrail.api.ApiConnector) IOException(java.io.IOException) InternalErrorException(com.cloud.exception.InternalErrorException) IOException(java.io.IOException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 34 with ApiConnector

use of net.juniper.contrail.api.ApiConnector in project cloudstack by apache.

the class VirtualMachineModel method update.

@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);
        }
    }
    for (ModelObject successor : successors()) {
        successor.update(controller);
    }
}
Also used : Project(net.juniper.contrail.api.types.Project) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ApiConnector(net.juniper.contrail.api.ApiConnector) IOException(java.io.IOException) InternalErrorException(com.cloud.exception.InternalErrorException) IOException(java.io.IOException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VirtualMachine(net.juniper.contrail.api.types.VirtualMachine)

Example 35 with ApiConnector

use of net.juniper.contrail.api.ApiConnector in project cloudstack by apache.

the class ServerDBSyncImpl method deleteDomain.

public void deleteDomain(net.juniper.contrail.api.types.Domain vnc, StringBuffer syncLogMesg) throws IOException {
    final ApiConnector api = _manager.getApiConnector();
    api.read(vnc);
    syncLogMesg.append("Domain# DB: none; VNC: " + vnc.getName() + "(" + vnc.getUuid() + "); action: delete\n");
    /* delete all projects under this domain */
    try {
        deleteChildren(vnc.getProjects(), net.juniper.contrail.api.types.Project.class, syncLogMesg);
    } catch (Exception ex) {
        s_logger.warn("deleteDomain", ex);
    }
    api.delete(vnc);
    syncLogMesg.append("Domain# VNC: " + vnc.getName() + " deleted\n");
}
Also used : ApiConnector(net.juniper.contrail.api.ApiConnector) InternalErrorException(com.cloud.exception.InternalErrorException) IOException(java.io.IOException)

Aggregations

ApiConnector (net.juniper.contrail.api.ApiConnector)44 IOException (java.io.IOException)26 InternalErrorException (com.cloud.exception.InternalErrorException)15 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)9 ArrayList (java.util.ArrayList)8 NetworkVO (com.cloud.network.dao.NetworkVO)6 List (java.util.List)6 VMInstanceVO (com.cloud.vm.VMInstanceVO)5 ContrailManagerImpl (org.apache.cloudstack.network.contrail.management.ContrailManagerImpl)5 VlanDao (com.cloud.dc.dao.VlanDao)4 ApiConnectorMock (net.juniper.contrail.api.ApiConnectorMock)4 ObjectReference (net.juniper.contrail.api.ObjectReference)4 ServiceInstance (net.juniper.contrail.api.types.ServiceInstance)4 VirtualMachineInterface (net.juniper.contrail.api.types.VirtualMachineInterface)4 VirtualNetwork (net.juniper.contrail.api.types.VirtualNetwork)4 ContrailManager (org.apache.cloudstack.network.contrail.management.ContrailManager)4 Test (org.junit.Test)4 VlanVO (com.cloud.dc.VlanVO)3 NicVO (com.cloud.vm.NicVO)3 UserVmDao (com.cloud.vm.dao.UserVmDao)3