private HostVirtualNicSpec createVNicSpecification() {
    HostVirtualNicSpec vNicSpec = new HostVirtualNicSpec();
    HostIpConfig ipConfig = new HostIpConfig();
    ipConfig.dhcp=false;
    ipAddr = cb.get_option("ipaddress");
    ipConfig.ipAddress=ipAddr;
    ipConfig.subnetMask="255.255.255.0";      
    vNicSpec.ip=ipConfig;
    return vNicSpec;
 }
Example #2
0
        private HostVirtualNicSpec createVNicSpecification()
        {
            HostVirtualNicSpec vNicSpec = new HostVirtualNicSpec();
            HostIpConfig       ipConfig = new HostIpConfig();

            ipConfig.dhcp       = false;
            ipAddr              = cb.get_option("ipaddress");
            ipConfig.ipAddress  = ipAddr;
            ipConfig.subnetMask = "255.255.255.0";
            vNicSpec.ip         = ipConfig;
            return(vNicSpec);
        }
Example #3
0
        public void AddVirtualNic(VMware.Vim.HostConfigManager configMgr, string portGroupName, string IPaddress, string subNetmask)
        {
            VMware.Vim.ManagedObjectReference nwSystem = configMgr.NetworkSystem;

            HostVirtualNicSpec vNicSpec = new HostVirtualNicSpec();
            HostIpConfig       ipConfig = new HostIpConfig();

            ipConfig.dhcp       = false;
            ipConfig.ipAddress  = IPaddress;
            ipConfig.subnetMask = subNetmask;
            vNicSpec.ip         = ipConfig;

            vimService.AddVirtualNic(nwSystem != null ? new VimApi_55.ManagedObjectReference()
            {
                type  = nwSystem.Type,
                Value = nwSystem.Value
            } : null, portGroupName, vNicSpec);
        }
Example #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;
            }
        }