Search in sources :

Example 1 with InstanceIp

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

the class NetworkProviderTest method dbSyncTest.

@Test
public void dbSyncTest() {
    Network network = lookupTestNetwork("test-db-only-net");
    if (network == null) {
        network = createTestNetwork("test-db-only-net");
    }
    UserVm vm = _server.createVM("test-db-only-vm", network);
    try {
        createFloatingIp(network, vm);
    } catch (Exception e) {
        fail("unable to create floating ip");
    }
    /* reset ApiServer objects to default config only, so above created objects
         * exists only in cludstack db but not in api server
         */
    ((ApiConnectorMock) _api).initConfig();
    /* reset model cached objects */
    _contrailMgr.getDatabase().initDb();
    /* Create one object of each type directly in api-server - these objects does not exist in cloudstack */
    net.juniper.contrail.api.types.Domain domain = new net.juniper.contrail.api.types.Domain();
    domain.setName("test-vnc-only-domain--1");
    domain.setUuid(UUID.randomUUID().toString());
    try {
        assertTrue(_api.create(domain));
    } catch (IOException ex) {
        fail(ex.getMessage());
    }
    Project project = new Project();
    project.setName("test-vnc-only-project-1");
    project.setUuid(UUID.randomUUID().toString());
    project.setParent(domain);
    try {
        assertTrue(_api.create(project));
    } catch (IOException ex) {
        fail(ex.getMessage());
    }
    VirtualNetwork net = new VirtualNetwork();
    net.setName("test-vnc-only-net-1");
    net.setUuid(UUID.randomUUID().toString());
    net.setParent(project);
    NetworkIpam ipam = null;
    try {
        // Find default-network-ipam
        String ipam_id = _api.findByName(NetworkIpam.class, null, "default-network-ipam");
        assertNotNull(ipam_id);
        ipam = (NetworkIpam) _api.findById(NetworkIpam.class, ipam_id);
        assertNotNull(ipam);
    } catch (IOException ex) {
        fail(ex.getMessage());
    }
    VnSubnetsType subnet = new VnSubnetsType();
    subnet.addIpamSubnets(new SubnetType("10.0.2.0", 24), "10.0.2.254");
    net.addNetworkIpam(ipam, subnet);
    VirtualMachine vncVm = new VirtualMachine();
    vncVm.setName("test-vnc-only-vm-1");
    try {
        assertTrue(_api.create(vncVm));
    } catch (IOException ex) {
        fail(ex.getMessage());
    }
    VirtualMachineInterface vmi = new VirtualMachineInterface();
    vmi.setParent(vncVm);
    vmi.setName("test-vnc-only-vmi-1");
    try {
        assertTrue(_api.create(vmi));
        assertTrue(_api.create(net));
    } catch (IOException ex) {
        fail(ex.getMessage());
    }
    InstanceIp ip_obj = new InstanceIp();
    ip_obj.setName(net.getName() + ":0");
    ip_obj.setVirtualNetwork(net);
    ip_obj.setVirtualMachineInterface(vmi);
    try {
        assertTrue(_api.create(ip_obj));
        // Must perform a GET in order to update the object contents.
        assertTrue(_api.read(ip_obj));
        assertNotNull(ip_obj.getAddress());
    } catch (IOException ex) {
        fail(ex.getMessage());
    }
    //now db sync
    if (_dbSync.syncAll(DBSyncGeneric.SYNC_MODE_UPDATE) == ServerDBSync.SYNC_STATE_OUT_OF_SYNC) {
        s_logger.info("# Cloudstack DB & VNC are out of sync - resync done");
    }
    if (_dbSync.syncAll(DBSyncGeneric.SYNC_MODE_CHECK) == ServerDBSync.SYNC_STATE_OUT_OF_SYNC) {
        s_logger.info("# Cloudstack DB & VNC are still out of sync");
        fail("DB Sync failed");
    }
}
Also used : InstanceIp(net.juniper.contrail.api.types.InstanceIp) IOException(java.io.IOException) SubnetType(net.juniper.contrail.api.types.SubnetType) CloudException(com.cloud.exception.CloudException) IOException(java.io.IOException) VirtualNetwork(net.juniper.contrail.api.types.VirtualNetwork) Project(net.juniper.contrail.api.types.Project) UserVm(com.cloud.uservm.UserVm) VirtualMachineInterface(net.juniper.contrail.api.types.VirtualMachineInterface) VirtualNetwork(net.juniper.contrail.api.types.VirtualNetwork) Network(com.cloud.network.Network) NetworkIpam(net.juniper.contrail.api.types.NetworkIpam) Domain(com.cloud.domain.Domain) ApiConnectorMock(net.juniper.contrail.api.ApiConnectorMock) VnSubnetsType(net.juniper.contrail.api.types.VnSubnetsType) VirtualMachine(net.juniper.contrail.api.types.VirtualMachine) Test(org.junit.Test)

Example 2 with InstanceIp

use of net.juniper.contrail.api.types.InstanceIp 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)

Aggregations

InstanceIp (net.juniper.contrail.api.types.InstanceIp)2 VirtualMachineInterface (net.juniper.contrail.api.types.VirtualMachineInterface)2 VirtualNetwork (net.juniper.contrail.api.types.VirtualNetwork)2 Domain (com.cloud.domain.Domain)1 CloudException (com.cloud.exception.CloudException)1 InternalErrorException (com.cloud.exception.InternalErrorException)1 Network (com.cloud.network.Network)1 UserVm (com.cloud.uservm.UserVm)1 IOException (java.io.IOException)1 ApiConnector (net.juniper.contrail.api.ApiConnector)1 ApiConnectorMock (net.juniper.contrail.api.ApiConnectorMock)1 NetworkIpam (net.juniper.contrail.api.types.NetworkIpam)1 Project (net.juniper.contrail.api.types.Project)1 SubnetType (net.juniper.contrail.api.types.SubnetType)1 VirtualMachine (net.juniper.contrail.api.types.VirtualMachine)1 VnSubnetsType (net.juniper.contrail.api.types.VnSubnetsType)1 Test (org.junit.Test)1