Package net.juniper.contrail.api.types

Examples of net.juniper.contrail.api.types.VirtualMachineInterface


        assert vmInterfaceRefs.size() == 1 : "Virtual machine: " + vmUuid +
                " associated with more than one virtual machine interface";
        for (ObjectReference<ApiPropertyBase> vmInterfaceRef :
            vmInterfaceRefs) {
            String vmInterfaceUuid = vmInterfaceRef.getUuid();
            VirtualMachineInterface vmInterface = (VirtualMachineInterface)
                    apiConnector.findById(VirtualMachineInterface.class,
                            vmInterfaceUuid);
            apiConnector.read(vmInterface);
            List<ObjectReference<ApiPropertyBase>> instanceIpRefs =
                    vmInterface.getInstanceIpBackRefs();
            for (ObjectReference<ApiPropertyBase> instanceIpRef :
                Utils.safe(instanceIpRefs)) {
                s_logger.info("Delete instance IP: " +
                        instanceIpRef.getReferredName());
                apiConnector.delete(InstanceIp.class,
                        instanceIpRef.getUuid());
            }
            s_logger.info("Delete virtual machine interface: " +
                    vmInterface.getName());
            apiConnector.delete(VirtualMachineInterface.class,
                    vmInterfaceUuid);
            // Unplug notification to vrouter
            if (vrouterIpAddress == null) {
                s_logger.info("Virtual machine interace: " + vmInterfaceUuid +
View Full Code Here


        apiConnector.read(vm);

        // Virtual machine interface
        String vmInterfaceName = "vmi-" + vmName;
        String vmiUuid = UUID.randomUUID().toString();
        VirtualMachineInterface vmInterface = new VirtualMachineInterface();
        vmInterface.setDisplayName(vmInterfaceName);
        vmInterface.setUuid(vmiUuid);
        vmInterface.setParent(vCenterProject);
        vmInterface.setName(vmiUuid);
        vmInterface.setVirtualNetwork(network);
        vmInterface.addVirtualMachine(vm);
        MacAddressesType macAddrType = new MacAddressesType();
        macAddrType.addMacAddress(macAddress);
        vmInterface.setMacAddresses(macAddrType);
        apiConnector.create(vmInterface);
        String vmInterfaceUuid = apiConnector.findByName(
                VirtualMachineInterface.class, vm, vmInterface.getName());
        s_logger.info("Create virtual machine interface:" + vmInterfaceName +
                ": " + vmInterfaceUuid + "vmiUuid :" + vmiUuid);

        // Instance Ip
        String instanceIpName = "ip-" + vmName;
        String instIpUuid = UUID.randomUUID().toString();
        InstanceIp instanceIp = new InstanceIp();
        //instanceIp.setParent(vm);   SAS_FIXME
        instanceIp.setDisplayName(instanceIpName);
        instanceIp.setUuid(instIpUuid);
        instanceIp.setName(instIpUuid);
        instanceIp.setVirtualNetwork(network);
        instanceIp.setVirtualMachineInterface(vmInterface);
        apiConnector.create(instanceIp);

        // Read back to get assigned IP address
        //instanceIp = (InstanceIp) apiConnector.find(InstanceIp.class, vm,
         //                                           instanceIp.getName());
        apiConnector.read(instanceIp);
        String vmIpAddress = instanceIp.getAddress();
        s_logger.info("Create instance IP:" + instanceIp.getName() + ": " +
                vmIpAddress);

        // Plug notification to vrouter
        if (vrouterIpAddress == null) {
            s_logger.info("Virtual machine: " + vmName + " host: " + hostName
                + " create notification NOT sent");
            return;
        }
        try {
            ContrailVRouterApi vrouterApi = vrouterApiMap.get(vrouterIpAddress);
            if (vrouterApi == null) {
                   vrouterApi = new ContrailVRouterApi(
                         InetAddress.getByName(vrouterIpAddress),
                         vrouterApiPort, false);
                   vrouterApiMap.put(vrouterIpAddress, vrouterApi);
            }
            vrouterApi.AddPort(UUID.fromString(vmiUuid),
                                         UUID.fromString(vmUuid), vmInterface.getName(),
                                         InetAddress.getByName(vmIpAddress),
                                         Utils.parseMacAddress(macAddress),
                                         UUID.fromString(vnUuid), isolatedVlanId, primaryVlanId);
            s_logger.debug("VRouterAPi Add Port success - port name: " + vmInterface.getName() + "(" + vmInterface.getDisplayName() + ")");
        }catch(Throwable e) {
            s_logger.error("Exception : " + e);
            e.printStackTrace();
        }
    }
View Full Code Here

                VirtualMachine.class, vmUuid);

        // Virtual machine interface
        List<ObjectReference<ApiPropertyBase>> vmInterfaceRefs =
                vm.getVirtualMachineInterfaceBackRefs();
        VirtualMachineInterface vmInterface = null;
        for (ObjectReference<ApiPropertyBase> vmInterfaceRef :
                Utils.safe(vmInterfaceRefs)) {
            vmInterface = (VirtualMachineInterface)
                    apiConnector.findById(VirtualMachineInterface.class,
                            vmInterfaceRef.getUuid());
        }

        if (vmInterface == null) {
            s_logger.info("Virtual machine: " + vmName
                          + " has no network interface");
            return;
        }

        // Instance Ip
        // Read back to get assigned IP address
        List<ObjectReference<ApiPropertyBase>> instanceIpBackRefs =
                vmInterface.getInstanceIpBackRefs();
        InstanceIp instanceIp = null;
        for (ObjectReference<ApiPropertyBase> instanceIpRef :
                Utils.safe(instanceIpBackRefs)) {
            instanceIp = (InstanceIp)
                    apiConnector.findById(InstanceIp.class,
                            instanceIpRef.getUuid());
        }

        if (instanceIp == null) {
            s_logger.info("Virtual machine interface: " + vmInterface.getName()
                          + " has no ip address");
            return;
        }

        String vmIpAddress = instanceIp.getAddress();

        // Plug notification to vrouter
        if (vrouterIpAddress == null) {
            s_logger.info("Virtual machine: " + vmName + " host: " + hostName
                + " create notification NOT sent");
            return;
        }
        try {
            ContrailVRouterApi vrouterApi = vrouterApiMap.get(vrouterIpAddress);
            if (vrouterApi == null) {
                   vrouterApi = new ContrailVRouterApi(
                         InetAddress.getByName(vrouterIpAddress),
                         vrouterApiPort, false);
                   vrouterApiMap.put(vrouterIpAddress, vrouterApi);
            }
            boolean ret = vrouterApi.AddPort(UUID.fromString(vmInterface.getUuid()),
                               UUID.fromString(vmUuid), vmInterface.getName(),
                               InetAddress.getByName(vmIpAddress),
                               Utils.parseMacAddress(macAddress),
                               UUID.fromString(vnUuid), isolatedVlanId, primaryVlanId);
            if ( ret == true) {
                s_logger.debug("VRouterAPi Add Port success - port name: "
                                + vmInterface.getName()
                                + "(" + vmInterface.getDisplayName() + ")");
            } else {
                // log failure but don't worry. Periodic KeepAlive task will
                // attempt to connect to vRouter Agent and replay AddPorts.
                s_logger.debug("VRouterAPi Add Port failed - port name: "
                                + vmInterface.getName()
                                + "(" + vmInterface.getDisplayName() + ")");
            }
        }catch(Throwable e) {
            s_logger.error("Exception : " + e);
            e.printStackTrace();
        }
View Full Code Here

        apiConnector.read(network);
        List<ObjectReference<ApiPropertyBase>> vmInterfaceRefs =
                network.getVirtualMachineInterfaceBackRefs();
        for (ObjectReference<ApiPropertyBase> vmInterfaceRef :
                Utils.safe(vmInterfaceRefs)) {
            VirtualMachineInterface vmInterface = (VirtualMachineInterface)
                    apiConnector.findById(VirtualMachineInterface.class,
                            vmInterfaceRef.getUuid());
            DeleteVirtualMachineInternal(vmInterface);
        }
        apiConnector.delete(VirtualNetwork.class, network.getUuid());    
View Full Code Here

            }
            SortedMap<String, VncVirtualMachineInfo> vmInfos =
                    new TreeMap<String, VncVirtualMachineInfo>();
            for (ObjectReference<ApiPropertyBase> vmInterfaceRef :
                Utils.safe(vmInterfaceRefs)) {
                VirtualMachineInterface vmInterface =
                        (VirtualMachineInterface) apiConnector.findById(
                                VirtualMachineInterface.class,
                                vmInterfaceRef.getUuid());
                apiConnector.read(vmInterface);
                //String vmUuid = vmInterface.getParentUuid();
                List<ObjectReference<ApiPropertyBase>> vmRefs = vmInterface.getVirtualMachine();
                if (vmRefs == null || vmRefs.size() == 0) {
                    s_logger.error("Virtual Machine Interface : " + vmInterface.getDisplayName() +
                            " NO associated virtual machine ");
                }
                if (vmRefs.size() > 1) {
                    s_logger.error("Virtual Machine Interface : " + vmInterface.getDisplayName() +
                                   "(" + vmRefs.size() + ")" + " associated virtual machines ");
                }

                ObjectReference<ApiPropertyBase> vmRef = vmRefs.get(0);
                VirtualMachine vm = (VirtualMachine) apiConnector.findById(
View Full Code Here

    /**
     * API server requires the attr element in an ObjectReference to be present, even when null.
     */
    @Test
    public void testNullAttr() {
        VirtualMachineInterface vmi = new VirtualMachineInterface();
        VirtualNetwork vn = new VirtualNetwork();
        vn.setName("testnet");
        vn.setUuid(UUID.randomUUID().toString());
        vmi.setName("x-0");
        vmi.setVirtualNetwork(vn);
        String jsdata = ApiSerializer.serializeObject("virtual-machine-interface", vmi);
        assertNotSame(jsdata, -1, jsdata.indexOf("\"attr\":null"));
    }
View Full Code Here

            assertTrue(_api.create(vm));
        } catch (IOException ex) {
            fail(ex.getMessage());
        }

        VirtualMachineInterface vmi = new VirtualMachineInterface();
        vmi.setParent(vm);
        vmi.setName("test-vmi");

        try {
            assertTrue(_api.create(vmi));
            assertTrue(_api.create(net));
        } catch (IOException ex) {
View Full Code Here

TOP

Related Classes of net.juniper.contrail.api.types.VirtualMachineInterface

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.