Examples of VIF


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

Examples of com.xensource.xenapi.VIF

        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
        IpAddressTO pubIp = cmd.getIpAddress();
        try {
            VM router = getVM(conn, routerName);

            VIF correctVif = getCorrectVif(conn, router, pubIp);

            String args = "vpc_snat.sh " + routerIp;

            args += " -A ";
            args += " -l ";
            args += pubIp.getPublicIp();

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

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

Examples of com.xensource.xenapi.VIF

            if (privateGw != null) {
                s_logger.debug("Private gateway configuration is set");
            }
            NicTO nic = cmd.getNic();
            VIF vif = getVifByMac(conn, router, nic.getMac());

            if (privateGw != null) {
                s_logger.debug("Private gateway configuration is set");
                String args = "vpc_privategw_acl.sh " + routerIp;
                args += " -d " + "eth" + vif.getDevice(conn);
                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++) {
                        results[i] = "Failed";
                    }
                    return new SetNetworkACLAnswer(cmd, false, results);
                }
            } else {
                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);
View Full Code Here

Examples of com.xensource.xenapi.VIF

    @Test
    public void testSetNicDevIdIfCorrectVifIsNotNull() throws Exception {
        IpAddressTO ip = mock(IpAddressTO.class);
        when(ip.isAdd()).thenReturn(false);
        VIF correctVif = null;
        try {
            _resource.setNicDevIdIfCorrectVifIsNotNull(conn, ip, correctVif);
        } catch (NullPointerException e) {
            fail("this test is meant to show that null pointer is not thrown");
        }
View Full Code Here

Examples of com.xensource.xenapi.VIF

        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
        IpAddressTO pubIp = cmd.getIpAddress();
        try {
            VM router = getVM(conn, routerName);

            VIF correctVif = getCorrectVif(conn, router, pubIp);
           
            String args = "vpc_snat.sh " + routerIp;

            args += " -A ";
            args += " -l ";
            args += pubIp.getPublicIp();

            args += " -c ";
            args += "eth" + correctVif.getDevice(conn);
           
            String result = callHostPlugin(conn, "vmops", "routerProxy", "args", args);
            if (result == null || result.isEmpty()) {
                throw new InternalErrorException("Xen plugin \"vpc_snat\" failed.");
            }
View Full Code Here

Examples of com.xensource.xenapi.VIF

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

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

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

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

            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
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.