Examples of NicTO


Examples of com.cloud.agent.api.to.NicTO

        NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), _networkModel.getNetworkRate(network.getId(), vm.getId()),
                _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network));

        //1) Unplug the nic
        if (vm.getState() == State.Running) {
            NicTO nicTO = toNicTO(nicProfile, vmProfile.getVirtualMachine().getHypervisorType());
            s_logger.debug("Un-plugging nic " + nic + " for vm " + vm + " from network " + network);
            boolean result = unplugNic(network, nicTO, vmTO, context, dest);
            if (result) {
                s_logger.debug("Nic is unplugged successfully for vm " + vm + " in network " + network);
                long isDefault = (nic.isDefaultNic()) ? 1 : 0;
View Full Code Here

Examples of com.cloud.agent.api.to.NicTO

            NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), _networkModel.getNetworkRate(network.getId(), vm.getId()),
                    _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network));

            //1) Unplug the nic
            if (vm.getState() == State.Running) {
                NicTO nicTO = toNicTO(nicProfile, vmProfile.getVirtualMachine().getHypervisorType());
                s_logger.debug("Un-plugging nic for vm " + vm + " from network " + network);
                boolean result = unplugNic(network, nicTO, vmTO, context, dest);
                if (result) {
                    s_logger.debug("Nic is unplugged successfully for vm " + vm + " in network " + network);
                } else {
View Full Code Here

Examples of com.cloud.agent.api.to.NicTO

            boolean sourceNat, String vlanId, String vlanGateway, String vlanNetmask, String vifMacAddress, Integer networkRate, TrafficType trafficType, String name) throws InternalErrorException {

        try {
            VM router = getVM(conn, vmName);

            NicTO nic = new NicTO();
            nic.setMac(vifMacAddress);
            nic.setType(trafficType);
            if (vlanId == null) {
                nic.setBroadcastType(BroadcastDomainType.Native);
            } else {
                nic.setBroadcastType(BroadcastDomainType.Vlan);
                nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(vlanId));
            }
            nic.setDeviceId(0);
            nic.setNetworkRateMbps(networkRate);
            nic.setName(name);

            Network network = getNetwork(conn, nic);

            // Determine the correct VIF on DomR to associate/disassociate the
            // IP address with
            VIF correctVif = getCorrectVif(conn, router, network);

            // If we are associating an IP address and DomR doesn't have a VIF
            // for the specified vlan ID, we need to add a VIF
            // If we are disassociating the last IP address in the VLAN, we need
            // to remove a VIF
            boolean addVif = false;
            boolean removeVif = false;
            if (add && correctVif == null) {
                addVif = true;
            }

            if (addVif) {
                // Add a new VIF to DomR
                String vifDeviceNum = getLowestAvailableVIFDeviceNum(conn, router);

                if (vifDeviceNum == null) {
                    throw new InternalErrorException("There were no more available slots for a new VIF on router: " + router.getNameLabel(conn));
                }

                nic.setDeviceId(Integer.parseInt(vifDeviceNum));

                correctVif = createVif(conn, vmName, router, nic);
                correctVif.plug(conn);
                // Add iptables rule for network usage
                networkUsage(conn, privateIpAddress, "addVif", "eth" + correctVif.getDevice(conn));
View Full Code Here

Examples of com.cloud.agent.api.to.NicTO

        return null;
    }
   
    protected VIF getCorrectVif(Connection conn, VM router, IpAddressTO ip) throws XmlRpcException, XenAPIException {
        NicTO nic = new NicTO();
        nic.setType(ip.getTrafficType());
        nic.setName(ip.getNetworkName());
        if (ip.getVlanId() == null) {
            nic.setBroadcastType(BroadcastDomainType.Native);
        } else {
            nic.setBroadcastType(BroadcastDomainType.Vlan);
            nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(ip.getVlanId()));
        }
        Network network = getNetwork(conn, nic);
        // Determine the correct VIF on DomR to associate/disassociate the
        // IP address with
        Set<VIF> routerVIFs = router.getVIFs(conn);
View Full Code Here

Examples of com.cloud.agent.api.to.NicTO

            Set<VM> vms = VM.getByNameLabel(conn, vmName);
            if ( vms == null || vms.isEmpty() ) {
                return new UnPlugNicAnswer(cmd, false, "Can not find VM " + vmName);
            }
            VM vm = vms.iterator().next();
            NicTO nic = cmd.getNic();
            String mac = nic.getMac();
            VIF vif = getVifByMac(conn, vm, mac);
            if ( vif != null ) {
                vif.unplug(conn);
                Network network = vif.getNetwork(conn);
                vif.destroy(conn);
View Full Code Here

Examples of com.cloud.agent.api.to.NicTO

            Set<VM> vms = VM.getByNameLabel(conn, vmName);
            if ( vms == null || vms.isEmpty() ) {
                return new PlugNicAnswer(cmd, false, "Can not find VM " + vmName);
            }
            VM vm = vms.iterator().next();
            NicTO nic = cmd.getNic();
            VIF vif = getVifByMac(conn, vm, nic.getMac());
            if ( vif != null ) {
                String msg = " Plug Nic failed due to a VIF with the same mac " + nic.getMac() + " exists";
                s_logger.warn(msg);
                return new PlugNicAnswer(cmd, false, msg);
            }
            String deviceId = getUnusedVIFNum(conn, vm);
            nic.setDeviceId(Integer.parseInt(deviceId));
            vif = createVif(conn, vmName, vm, nic);
            vif.plug(conn);
            return new PlugNicAnswer(cmd, true, "success");
        } catch (Exception e) {
            String msg = " Plug Nic failed due to " + e.toString();
View Full Code Here

Examples of com.cloud.agent.api.to.NicTO

     * @param cmd
     * @return
     */
    private SetupGuestNetworkAnswer execute(SetupGuestNetworkCommand cmd) {
        Connection conn = getConnection();
        NicTO nic = cmd.getNic();
        String domrIP = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
        String domrGIP = cmd.getAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP);
        String domrName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
        String gw = cmd.getAccessDetail(NetworkElementCommand.GUEST_NETWORK_GATEWAY);
        String cidr = Long.toString(NetUtils.getCidrSize(nic.getNetmask()));;
        String domainName = cmd.getNetworkDomain();
        String dns = cmd.getDefaultDns1();
        if (dns == null || dns.isEmpty()) {
            dns = cmd.getDefaultDns2();
        } else {
            String dns2= cmd.getDefaultDns2();
            if ( dns2 != null && !dns2.isEmpty()) {
                dns += "," + dns2;
            }
        }
        try {
            Set<VM> vms = VM.getByNameLabel(conn, domrName);
            if ( vms == null || vms.isEmpty() ) {
                return new SetupGuestNetworkAnswer(cmd, false, "Can not find VM " + domrName);
            }
            VM vm = vms.iterator().next();
            String mac = nic.getMac();
            VIF domrVif = null;
            for ( VIF vif : vm.getVIFs(conn)) {
                String lmac = vif.getMAC(conn);
                if ( lmac.equals(mac) ) {
                    domrVif = vif;
                    break;
                }
            }
            if ( domrVif == null ) {
                return new SetupGuestNetworkAnswer(cmd, false, "Can not find vif with mac " + mac + " for VM " + domrName);
            }

            String args = "vpc_guestnw.sh " + domrIP + (cmd.isAdd()?" -C":" -D");
            String dev = "eth" + domrVif.getDevice(conn);
            args += " -d " + dev;
            args += " -i " + domrGIP;
            args += " -g " + gw;
            args += " -m " + cidr;
            args += " -n " + NetUtils.getSubNet(domrGIP, nic.getNetmask());
            if ( dns != null && !dns.isEmpty() ) {
                args += " -s " + dns;
            }
            if ( domainName != null && !domainName.isEmpty() ) {
                args += " -e " + domainName;
View Full Code Here

Examples of com.cloud.agent.api.to.NicTO

           
            for (int i = 0; i < aclRules.length; i++) {
                sb.append(aclRules[i]).append(',');
            }
           
            NicTO nic = cmd.getNic();
            VIF vif = getVifByMac(conn, router, nic.getMac());
            String args = "vpc_acl.sh " + routerIp;
            args += " -d " + "eth" + vif.getDevice(conn);
            args += " -i " + nic.getIp();
            args += " -m " + Long.toString(NetUtils.getCidrSize(nic.getNetmask()));
            args += " -a " + sb.toString();
            callResult = callHostPlugin(conn, "vmops", "routerProxy", "args", args);
            if (callResult == null || callResult.isEmpty()) {
                //FIXME - in the future we have to process each rule separately; now we temporarily set every rule to be false if single rule fails
                for (int i=0; i < results.length; i++) {
View Full Code Here

Examples of com.cloud.agent.api.to.NicTO

        }
    }

    private void VifHotPlug(Connect conn, String vmName, String vlanId,
            String macAddr) throws InternalErrorException, LibvirtException {
        NicTO nicTO = new NicTO();
        nicTO.setMac(macAddr);
        nicTO.setType(TrafficType.Public);
        if (vlanId == null) {
            nicTO.setBroadcastType(BroadcastDomainType.Native);
        } else {
            nicTO.setBroadcastType(BroadcastDomainType.Vlan);
            nicTO.setBroadcastUri(BroadcastDomainType.Vlan.toUri(vlanId));
        }

        Domain vm = getDomain(conn, vmName);
        vm.attachDevice(_vifDriver.plug(nicTO, "Other PV (32-bit)").toString());
    }
View Full Code Here

Examples of com.cloud.agent.api.to.NicTO

        vm.attachDevice(_vifDriver.plug(nicTO, "Other PV (32-bit)").toString());
    }

    private PlugNicAnswer execute(PlugNicCommand cmd) {
        Connect conn;
        NicTO nic = cmd.getNic();
        String vmName = cmd.getVmName();
        try {
            conn = LibvirtConnection.getConnection();
            Domain vm = getDomain(conn, vmName);
            List<InterfaceDef> pluggedNics = getInterfaces(conn, vmName);
            Integer nicnum = 0;
            for (InterfaceDef pluggedNic : pluggedNics) {
                if (pluggedNic.getMacAddress().equalsIgnoreCase(nic.getMac())) {
                    s_logger.debug("found existing nic for mac "+ pluggedNic.getMacAddress() + " at index "+nicnum);
                    return new PlugNicAnswer(cmd, true, "success");
                }
                nicnum++;
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.