Esempio n. 1
0
        public override async Task <PortGroupAllocation> AddPortGroup(string sw, VmNet eth)
        {
            try
            {
                HostPortGroupSpec spec = new HostPortGroupSpec();
                spec.vswitchName     = sw;
                spec.vlanId          = eth.Vlan;
                spec.name            = eth.Net;
                spec.policy          = new HostNetworkPolicy();
                spec.policy.security = new HostNetworkSecurityPolicy();
                spec.policy.security.allowPromiscuous          = true;
                spec.policy.security.allowPromiscuousSpecified = true;
                if (eth.Net.Untagged().EndsWith(_client.NetworkAllowAllSuffix))
                {
                    spec.policy.security.forgedTransmits          = true;
                    spec.policy.security.forgedTransmitsSpecified = true;
                    spec.policy.security.macChanges          = true;
                    spec.policy.security.macChangesSpecified = true;
                }

                await _client.vim.AddPortGroupAsync(_client.net, spec);
            } catch {}

            return(new PortGroupAllocation
            {
                Net = eth.Net,
                Key = eth.Net,
                VlanId = eth.Vlan,
                Switch = sw
            });
        }
Esempio n. 2
0
        public void CreatePortGroup(VMware.Vim.HostConfigManager configMgr, string portGroupName, string vSwitchName)
        {
            VMware.Vim.ManagedObjectReference nMob = configMgr.NetworkSystem;

            HostPortGroupSpec portgrp = new HostPortGroupSpec();

            portgrp.name        = portGroupName;
            portgrp.vswitchName = vSwitchName;
            portgrp.policy      = new HostNetworkPolicy();

            vimService.AddPortGroup(nMob != null ? new VimApi_55.ManagedObjectReference()
            {
                type  = nMob.Type,
                Value = nMob.Value
            } : null, portgrp);
        }
Esempio n. 3
0
        public override async Task <PortGroupAllocation> AddPortGroup(string sw, VmNet eth)
        {
            try
            {
                HostPortGroupSpec spec = new HostPortGroupSpec();
                spec.vswitchName     = sw;
                spec.vlanId          = eth.Vlan;
                spec.name            = eth.Net;
                spec.policy          = new HostNetworkPolicy();
                spec.policy.security = new HostNetworkSecurityPolicy();
                spec.policy.security.allowPromiscuous          = true;
                spec.policy.security.allowPromiscuousSpecified = true;

                await _client.vim.AddPortGroupAsync(_client.net, spec);
            } catch {}

            return(new PortGroupAllocation
            {
                Net = eth.Net,
                Key = "HostPortGroup|" + eth.Net,
                VlanId = eth.Vlan,
                Switch = sw
            });
        }
Esempio n. 4
0
        private void doAddVirtualNic()
        {
            ManagedObjectReference dcmor;
            ManagedObjectReference hostfoldermor;
            ManagedObjectReference hostmor = null;

            datacenter = cb.get_option("datacenter");
            host       = cb.get_option("host");
            vswitchId  = cb.get_option("vswitchid");
            portGroup  = cb.get_option("portgroupname");
            ipAddr     = cb.get_option("ipaddress");

            try {
                if (((datacenter != null) && (host != null)) ||
                    ((datacenter != null) && (host == null)))
                {
                    dcmor
                        = cb.getServiceUtil().GetDecendentMoRef(null, "Datacenter", datacenter);
                    if (dcmor == null)
                    {
                        Console.WriteLine("Datacenter not found");
                        return;
                    }
                    hostfoldermor = vmUtils.getHostFolder(dcmor);
                    hostmor       = vmUtils.getHost(hostfoldermor, host);
                }
                else if ((datacenter == null) && (host != null))
                {
                    hostmor = vmUtils.getHost(null, host);
                }
                if (hostmor != null)
                {
                    Object cmobj
                        = cb.getServiceUtil().GetDynamicProperty(hostmor, "configManager");
                    HostConfigManager      configMgr = (HostConfigManager)cmobj;
                    ManagedObjectReference nwSystem  = configMgr.networkSystem;

                    HostPortGroupSpec portgrp = new HostPortGroupSpec();
                    portgrp.name = portGroup;

                    HostVirtualNicSpec vNicSpec = createVNicSpecification();
                    cb.getConnection()._service.AddVirtualNic(nwSystem, portGroup, vNicSpec);

                    Console.WriteLine(cb.getAppName() + " : Successful creating nic on portgroup : "
                                      + portGroup);
                }
                else
                {
                    Console.WriteLine("Host not found");
                }
            }

            catch (SoapException e) {
                if (e.Detail.FirstChild.LocalName.Equals("ResourceInUseFault"))
                {
                    Console.WriteLine(cb.getAppName() + " : Failed to add nic "
                                      + ipAddr);
                }
                else if (e.Detail.FirstChild.LocalName.Equals("InvalidArgumentFault"))
                {
                    Console.WriteLine(cb.getAppName() + " : Failed to add nic " + ipAddr);
                    Console.WriteLine("PortGroup vlanId or network policy or ipaddress may be invalid .\n");
                }
                else if (e.Detail.FirstChild.LocalName.Equals("NotFoundFault"))
                {
                    Console.WriteLine(cb.getAppName() + " : Failed to add nic " + ipAddr);
                    Console.WriteLine(" Switch or portgroup not found.\n");
                }
            }

            catch (NullReferenceException e) {
                Console.WriteLine(cb.getAppName() + " : Failed to add nic " + ipAddr);
                Console.WriteLine("Datacenter or Host may be invalid \n");
                throw e;
            }
            catch (Exception e) {
                Console.WriteLine(cb.getAppName() + " : Failed to add nic " + ipAddr);
                throw e;
            }
        }
        private void doAddVirtualSwitchPortGroup()
        {
            ManagedObjectReference dcmor;
            ManagedObjectReference hostfoldermor;
            ManagedObjectReference hostmor = null;

            datacenter    = cb.get_option("datacenter");
            host          = cb.get_option("host");
            portGroupName = cb.get_option("portgroupname");
            vswitchId     = cb.get_option("vswitchid");
            try {
                if (((datacenter != null) && (host != null)) ||
                    ((datacenter != null) && (host == null)))
                {
                    dcmor
                        = cb.getServiceUtil().GetDecendentMoRef(null, "Datacenter", datacenter);
                    if (dcmor == null)
                    {
                        Console.WriteLine("Datacenter not found");
                        return;
                    }
                    hostfoldermor = vmUtils.getHostFolder(dcmor);
                    hostmor       = vmUtils.getHost(hostfoldermor, host);
                }
                else if ((datacenter == null) && (host != null))
                {
                    hostmor = vmUtils.getHost(null, host);
                }
                if (hostmor != null)
                {
                    Object cmobj
                        = cb.getServiceUtil().GetDynamicProperty(hostmor, "configManager");
                    HostConfigManager      configMgr = (HostConfigManager)cmobj;
                    ManagedObjectReference nwSystem  = configMgr.networkSystem;

                    HostPortGroupSpec portgrp = new HostPortGroupSpec();
                    portgrp.name        = portGroupName;
                    portgrp.vswitchName = vswitchId;
                    portgrp.policy      = new HostNetworkPolicy();

                    cb.getConnection()._service.AddPortGroup(nwSystem, portgrp);

                    Console.WriteLine(cb.getAppName() + " : Successful creating : "
                                      + vswitchId + "/" + portGroupName);
                }
                else
                {
                    Console.WriteLine("Host not found");
                }
            }
            catch (SoapException e) {
                if (e.Detail.FirstChild.LocalName.Equals("AlreadyExistsFault"))
                {
                    Console.WriteLine(cb.getAppName() + " : Failed creating : "
                                      + vswitchId + "/" + portGroupName);
                    Console.WriteLine("Portgroup name already exists");
                }
                if (e.Detail.FirstChild.LocalName.Equals("InvalidArgumentFault"))
                {
                    Console.WriteLine(cb.getAppName() + " : Failed creating : "
                                      + vswitchId + "/" + portGroupName);
                    Console.WriteLine("PortGroup vlanId or network policy may be invalid.");
                }
                else if (e.Detail.FirstChild.LocalName.Equals("NotFoundFault"))
                {
                    Console.WriteLine(cb.getAppName() + " : Failed creating : "
                                      + vswitchId + "/" + portGroupName);
                    Console.WriteLine("Switch Not found.");
                }
            }

            catch (NullReferenceException e) {
                Console.WriteLine(cb.getAppName() + " : Failed creating : "
                                  + vswitchId + "/" + portGroupName);
                Console.WriteLine("Datacenter or Host may be invalid");
                throw e;
            }
            catch (Exception e) {
                Console.WriteLine(cb.getAppName() + " : Failed creating : "
                                  + vswitchId + "/" + portGroupName);
                throw e;
            }
        }
Esempio n. 6
0
 private void doAddVirtualNic()  {
    ManagedObjectReference dcmor ;
    ManagedObjectReference hostfoldermor ;
    ManagedObjectReference hostmor = null; 
    datacenter = cb.get_option("datacenter");
    host = cb.get_option("host");
    vswitchId = cb.get_option("vswitchid");
    portGroup = cb.get_option("portgroupname");
    ipAddr = cb.get_option("ipaddress");
   
    try {
        if(((datacenter !=null) && (host !=null)) 
             || ((datacenter !=null) && (host ==null))) {
          dcmor 
             = cb.getServiceUtil().GetDecendentMoRef(null, "Datacenter", datacenter);
          if(dcmor == null) {
             Console.WriteLine("Datacenter not found");
             return;
          }
          hostfoldermor = vmUtils.getHostFolder(dcmor);
          hostmor = vmUtils.getHost(hostfoldermor, host);
       }
       else if ((datacenter ==null) && (host !=null)) {
          hostmor = vmUtils.getHost(null, host); 
       }
       if(hostmor != null) {
          Object cmobj 
             = cb.getServiceUtil().GetDynamicProperty(hostmor, "configManager");
          HostConfigManager configMgr = (HostConfigManager)cmobj;
          ManagedObjectReference nwSystem = configMgr.networkSystem;
 
          HostPortGroupSpec portgrp = new HostPortGroupSpec();
          portgrp.name=portGroup;
 
          HostVirtualNicSpec vNicSpec = createVNicSpecification();
          cb.getConnection()._service.AddVirtualNic(nwSystem, portGroup, vNicSpec);
          
          Console.WriteLine(cb.getAppName() + " : Successful creating nic on portgroup : " 
                             + portGroup);
       }
       else {
          Console.WriteLine("Host not found");
       }      
    }
    
    catch (SoapException e) {
        if (e.Detail.FirstChild.LocalName.Equals("ResourceInUseFault"))
        {
            Console.WriteLine(cb.getAppName() + " : Failed to add nic "
                             + ipAddr);
        }
        else if (e.Detail.FirstChild.LocalName.Equals("InvalidArgumentFault"))
        {
            Console.WriteLine(cb.getAppName() + " : Failed to add nic " + ipAddr);
            Console.WriteLine("PortGroup vlanId or network policy or ipaddress may be invalid .\n");
        }
        else if (e.Detail.FirstChild.LocalName.Equals("NotFoundFault"))
        {
            Console.WriteLine(cb.getAppName() + " : Failed to add nic " + ipAddr);
            Console.WriteLine(" Switch or portgroup not found.\n");
        }
    }
     
    catch (NullReferenceException e) {
        Console.WriteLine(cb.getAppName() + " : Failed to add nic " + ipAddr);
       Console.WriteLine("Datacenter or Host may be invalid \n");
       throw e;
    }   
    catch (Exception e) {
        Console.WriteLine(cb.getAppName() + " : Failed to add nic " + ipAddr);
       throw e;
    } 
 }
 private void doAddVirtualSwitchPortGroup()  {
    ManagedObjectReference dcmor ;
    ManagedObjectReference hostfoldermor ;
    ManagedObjectReference hostmor = null; 
    datacenter = cb.get_option("datacenter");
    host = cb.get_option("host");
    portGroupName = cb.get_option("portgroupname");
    vswitchId = cb.get_option("vswitchid");
    try {
       if(((datacenter !=null) && (host !=null)) 
             ||((datacenter !=null) && (host ==null))) {
          dcmor 
             = cb.getServiceUtil().GetDecendentMoRef(null, "Datacenter", datacenter);
          if(dcmor == null) {
             Console.WriteLine("Datacenter not found");
             return;
          }
          hostfoldermor = vmUtils.getHostFolder(dcmor);
          hostmor = vmUtils.getHost(hostfoldermor, host);
       }
       else if ((datacenter ==null) && (host !=null)) {
          hostmor = vmUtils.getHost(null, host); 
       }
       if(hostmor != null) {
          Object cmobj 
             = cb.getServiceUtil().GetDynamicProperty(hostmor, "configManager");
          HostConfigManager configMgr = (HostConfigManager)cmobj;
          ManagedObjectReference nwSystem = configMgr.networkSystem;
 
          HostPortGroupSpec portgrp = new HostPortGroupSpec();
          portgrp.name=portGroupName;
          portgrp.vswitchName=vswitchId;
          portgrp.policy=new HostNetworkPolicy();
 
          cb.getConnection()._service.AddPortGroup(nwSystem, portgrp);
 
          Console.WriteLine(cb.getAppName() + " : Successful creating : " 
                           + vswitchId +"/"+ portGroupName);
       }
       else {
          Console.WriteLine("Host not found");
       }      
    }
   catch ( SoapException e) {
       if (e.Detail.FirstChild.LocalName.Equals("AlreadyExistsFault"))
       {
           Console.WriteLine(cb.getAppName() + " : Failed creating : "
                            + vswitchId + "/" + portGroupName);
           Console.WriteLine("Portgroup name already exists");
       }
       if (e.Detail.FirstChild.LocalName.Equals("InvalidArgumentFault"))
       {
           Console.WriteLine(cb.getAppName() + " : Failed creating : "
                        + vswitchId + "/" + portGroupName);
           Console.WriteLine("PortGroup vlanId or network policy may be invalid.");
       }
       else if (e.Detail.FirstChild.LocalName.Equals("NotFoundFault"))
       {
           Console.WriteLine(cb.getAppName() + " : Failed creating : "
                        + vswitchId + "/" + portGroupName);
           Console.WriteLine("Switch Not found.");
       }
    }
        
    catch (NullReferenceException e) {
       Console.WriteLine(cb.getAppName() + " : Failed creating : " 
                        + vswitchId +"/"+ portGroupName);
       Console.WriteLine("Datacenter or Host may be invalid");
       throw e;
    }   
    catch (Exception e) {
       Console.WriteLine(cb.getAppName() + " : Failed creating : " 
                        + vswitchId +"/"+ portGroupName);
       throw e;
    }
 }