Examples of VIF


Examples of com.xensource.xenapi.VIF

            // Create the vif map.
            Map<VIF, Network> vifMap = new HashMap<VIF, Network>();
            for (Map.Entry<NicTO, Object> entry : nicToNetwork.entrySet()) {
                if (entry.getValue() instanceof Network) {
                    Network network = (Network)entry.getValue();
                    VIF vif = getVifByMac(connection, vmToMigrate, entry.getKey().getMac());
                    vifMap.put(vif, network);
                } else {
                    throw new CloudRuntimeException("The object " + entry.getValue() + " passed is not of type Network.");
                }
            }
View Full Code Here

Examples of com.xensource.xenapi.VIF

     * @throws XenAPIException
     */
    private void enableXenServerNetwork(Connection conn, Network nw,
            String vifNameLabel, String networkDesc) throws XenAPIException, XmlRpcException {
        /* Make sure there is a physical bridge on this network */
        VIF dom0vif = null;
        Pair<VM, VM.Record> vm = getControlDomain(conn);
        VM dom0 = vm.first();
        // Create a VIF unless there's not already another VIF
        Set<VIF> dom0Vifs = dom0.getVIFs(conn);
        for (VIF vif:dom0Vifs) {
            vif.getRecord(conn);
            if (vif.getNetwork(conn).getUuid(conn) == nw.getUuid(conn)) {
                dom0vif = vif;
                s_logger.debug("A VIF for dom0 has already been found - No need to create one");
            }
        }
        if (dom0vif == null) {
            s_logger.debug("Create a vif on dom0 for " + networkDesc);
            VIF.Record vifr = new VIF.Record();
            vifr.VM = dom0;
            vifr.device = getLowestAvailableVIFDeviceNum(conn, dom0);
            if (vifr.device == null) {
                s_logger.debug("Failed to create " + networkDesc + ", no vif available");
                return;
            }
            Map<String, String> config = new HashMap<String, String>();
            config.put("nameLabel", vifNameLabel);
            vifr.otherConfig = config;
            vifr.MAC = "FE:FF:FF:FF:FF:FF";
            vifr.network = nw;

            vifr.lockingMode = Types.VifLockingMode.NETWORK_DEFAULT;
            dom0vif = VIF.create(conn, vifr);
        }
        // At this stage we surely have a VIF
        dom0vif.plug(conn);
        dom0vif.unplug(conn);
        synchronized(_tmpDom0Vif) {
            _tmpDom0Vif.add(dom0vif);
        }

    }
View Full Code Here

Examples of com.xensource.xenapi.VIF

            // convert mbs to kilobyte per second
            vifr.qosAlgorithmParams.put("kbps", Integer.toString(nic.getNetworkRateMbps() * 128));
        }

        vifr.lockingMode = Types.VifLockingMode.NETWORK_DEFAULT;
        VIF vif = VIF.create(conn, vifr);
        if (s_logger.isDebugEnabled()) {
            vifr = vif.getRecord(conn);
            s_logger.debug("Created a vif " + vifr.uuid + " on " + nic.getDeviceId());
        }
       
        return vif;
    }
View Full Code Here

Examples of com.xensource.xenapi.VIF

            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 (!add && correctVif == null) {
               return; // it is a disassociateIp and it has already happened
            }

            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));
            }

            if (correctVif == null) {
                throw new InternalErrorException("Failed to find DomR VIF to associate/disassociate IP with.");
            }

            String args = "ipassoc.sh " + privateIpAddress;

            if (add) {
                args += " -A ";
            } else {
                args += " -D ";
            }

            if (sourceNat) {
                args += " -s";
            }
            if (firstIP) {
                args += " -f";
            }

            String cidrSize = Long.toString(NetUtils.getCidrSize(vlanNetmask));
            args += " -l ";
            args += publicIpAddress + "/" + cidrSize;

            args += " -c ";
            args += "eth" + correctVif.getDevice(conn);

            args += " -g ";
            args += vlanGateway;

            if (addVif) {
                //To indicate this is new interface created
                args += " -n";
            }


            String result = callHostPlugin(conn, "vmops", "routerProxy", "args", args);
            if (result == null || result.isEmpty()) {
                throw new InternalErrorException("Xen plugin \"ipassoc\" failed.");
            }

            if (!add) {
                args += " -d";
                String zeroIpsRes = callHostPlugin(conn, "vmops", "routerProxy", "args", args);
                if (zeroIpsRes == null || zeroIpsRes.isEmpty()) {
                    //There are no ip address set on the interface. So unplug the interface
                    // If it is not unplugged then the interface is not resuable.
                    removeVif = true;
                }
            }



            if (removeVif) {
                network = correctVif.getNetwork(conn);

                // Mark this vif to be removed from network usage
                networkUsage(conn, privateIpAddress, "deleteVif", "eth" + correctVif.getDevice(conn));

                // Remove the VIF from DomR
                correctVif.unplug(conn);
                correctVif.destroy(conn);

                // Disable the VLAN network if necessary
                disableVlanNetwork(conn, network);
            }
View Full Code Here

Examples of com.xensource.xenapi.VIF

    protected void assignVPCPublicIpAddress(Connection conn, String vmName, String routerIp, IpAddressTO ip) throws Exception {

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

            VIF correctVif = getVifByMac(conn, router, ip.getVifMacAddress());
            if (correctVif == null) {
                if (ip.isAdd()) {
                    throw new InternalErrorException("Failed to find DomR VIF to associate IP with.");
                } else {
                    s_logger.debug("VIF to deassociate IP with does not exist, return success");
                    return;
                }
            }          

            String args = "vpc_ipassoc.sh " + routerIp;
            String snatArgs = "vpc_privateGateway.sh " + routerIp;

            if (ip.isAdd()) {
                args += " -A ";
                snatArgs += " -A ";
            } else {
                args += " -D ";
                snatArgs+= " -D ";
            }

            args += " -l ";
            args += ip.getPublicIp();

            args += " -c ";
            args += "eth" + correctVif.getDevice(conn);

            args += " -g ";
            args += ip.getVlanGateway();

            args += " -m ";
            args += Long.toString(NetUtils.getCidrSize(ip.getVlanNetmask()));


            args += " -n ";
            args += NetUtils.getSubNet(ip.getPublicIp(), ip.getVlanNetmask());

            String result = callHostPlugin(conn, "vmops", "routerProxy", "args", args);
            if (result == null || result.isEmpty()) {
                throw new InternalErrorException("Xen plugin \"vpc_ipassoc\" failed.");
            }

            if (ip.isSourceNat()) {
                snatArgs += " -l " + ip.getPublicIp();
                snatArgs += " -c " + "eth" + correctVif.getDevice(conn);

                result = callHostPlugin(conn, "vmops", "routerProxy", "args", snatArgs);
                if (result == null || result.isEmpty()) {
                    throw new InternalErrorException("Xen plugin \"vpc_privateGateway\" failed.");
                }
View Full Code Here

Examples of com.xensource.xenapi.VIF

            vmName = vm.getNameLabel(conn);
            List<Integer> usedDeviceNums = new ArrayList<Integer>();
            Set<VIF> vifs = vm.getVIFs(conn);
            Iterator<VIF> vifIter = vifs.iterator();
            while(vifIter.hasNext()){
                VIF vif = vifIter.next();
                try{
                    usedDeviceNums.add(Integer.valueOf(vif.getDevice(conn)));
                } catch (NumberFormatException e) {
                    String msg = "Obtained an invalid value for an allocated VIF device number for VM: " + vmName;
                    s_logger.debug(msg, e);
                    throw new CloudRuntimeException(msg);
                }
View Full Code Here

Examples of com.xensource.xenapi.VIF

            } else {
                linkLocal = networks.iterator().next();
            }

            /* Make sure there is a physical bridge on this network */
            VIF dom0vif = null;
            Pair<VM, VM.Record> vm = getControlDomain(conn);
            VM dom0 = vm.first();
            Set<VIF> vifs = dom0.getVIFs(conn);
            if (vifs.size() != 0) {
                for (VIF vif : vifs) {
                    Map<String, String> otherConfig = vif.getOtherConfig(conn);
                    if (otherConfig != null) {
                        String nameLabel = otherConfig.get("nameLabel");
                        if ((nameLabel != null) && nameLabel.equalsIgnoreCase("link_local_network_vif")) {
                            dom0vif = vif;
                        }
                    }
                }
            }

            /* create temp VIF0 */
            if (dom0vif == null) {
                s_logger.debug("Can't find a vif on dom0 for link local, creating a new one");
                VIF.Record vifr = new VIF.Record();
                vifr.VM = dom0;
                vifr.device = getLowestAvailableVIFDeviceNum(conn, dom0);
                if (vifr.device == null) {
                    s_logger.debug("Failed to create link local network, no vif available");
                    return;
                }
                Map<String, String> config = new HashMap<String, String>();
                config.put("nameLabel", "link_local_network_vif");
                vifr.otherConfig = config;
                vifr.MAC = "FE:FF:FF:FF:FF:FF";
                vifr.network = linkLocal;
                vifr.lockingMode = Types.VifLockingMode.NETWORK_DEFAULT;
                dom0vif = VIF.create(conn, vifr);
                dom0vif.plug(conn);
            } else {
                s_logger.debug("already have a vif on dom0 for link local network");
                if (!dom0vif.getCurrentlyAttached(conn)) {
                    dom0vif.plug(conn);
                }
            }

            String brName = linkLocal.getBridge(conn);
            callHostPlugin(conn, "vmops", "setLinkLocalIP", "brName", brName);
View Full Code Here

Examples of com.xensource.xenapi.VIF

                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);
                try {
                    if (network.getNameLabel(conn).startsWith("VLAN")) {
                        disableVlanNetwork(conn, network);
                    }
                }  catch (Exception e) {
View Full Code Here

Examples of com.xensource.xenapi.VIF

            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 = getLowestAvailableVIFDeviceNum(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();
            s_logger.warn(msg, e);
            return new PlugNicAnswer(cmd, false, msg);
View Full Code Here

Examples of com.xensource.xenapi.VIF

            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());
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.