예제 #1
0
        public override async Task <PortGroupAllocation> AddPortGroup(string sw, VmNet eth)
        {
            var mor = new ManagedObjectReference();

            try
            {
                bool allowAll = eth.Net.Untagged().EndsWith(_client.NetworkAllowAllSuffix);

                var spec = new DVPortgroupConfigSpec()
                {
                    name       = eth.Net,
                    autoExpand = true,
                    type       = "earlyBinding",

                    defaultPortConfig = new VMwareDVSPortSetting
                    {
                        vlan = new VmwareDistributedVirtualSwitchVlanIdSpec
                        {
                            vlanId = eth.Vlan
                        },
                        securityPolicy = new DVSSecurityPolicy()
                        {
                            allowPromiscuous = new BoolPolicy()
                            {
                                value          = true,
                                valueSpecified = true
                            },
                            forgedTransmits = new BoolPolicy()
                            {
                                value          = allowAll,
                                valueSpecified = allowAll
                            },
                            macChanges = new BoolPolicy()
                            {
                                value          = allowAll,
                                valueSpecified = allowAll
                            }
                        }
                    }
                };

                var task = await _client.vim.CreateDVPortgroup_TaskAsync(_client.dvs, spec);

                var info = await WaitForVimTask(task);

                mor = info.result as ManagedObjectReference;
            }
            catch { }
            return(new PortGroupAllocation
            {
                Net = eth.Net,
                Key = mor.AsString(),
                VlanId = eth.Vlan,
                Switch = _client.UplinkSwitch
            });
        }
예제 #2
0
        /// <summary>
        /// Associates a given NetworkResourcePool to the given DVSPortGroup on the given DVS switch
        /// </summary>
        /// <param name="dvSwitchName"></param>
        /// <param name="nrpName"></param>
        /// <param name="dvPortGroupName"></param>
        private void ReconfigureDVSPG(string dvSwitchName, string nrpName,
                                      string dvPortGroupName)
        {
            DVSNetworkResourcePool[] nrpList = null;
            ManagedObjectReference   dvsMor  = cb._svcUtil.getEntityByName("VmwareDistributedVirtualSwitch", dvSwitchName);

            if (dvsMor != null)
            {
                string[]        type       = new string[] { "networkResourcePool" };
                ObjectContent[] objContent = cb.getServiceUtil().GetObjectProperties(null, dvsMor, type);
                if (objContent != null)
                {
                    nrpList = (DVSNetworkResourcePool[])objContent[0].propSet[0].val;
                }

                string nrpKey = null;
                if (nrpList != null)
                {
                    foreach (DVSNetworkResourcePool dvsNrp in nrpList)
                    {
                        if (dvsNrp.name.Equals(nrpName))
                        {
                            nrpKey = dvsNrp.key;
                            break;
                        }
                    }

                    if (nrpKey == null)
                    {
                        throw new Exception("NetworkResource Pool " + nrpName + " Not Found");
                    }
                }
                else
                {
                    throw new Exception("No NetworkResourcePool found for DVS Switch " + dvSwitchName);
                }
                ManagedObjectReference dvspgMor = cb._svcUtil.getEntityByName("DistributedVirtualPortgroup",
                                                                              dvPortGroupName);

                if (dvspgMor != null)
                {
                    DVPortgroupConfigInfo configInfo        = (DVPortgroupConfigInfo)cb.getServiceUtil().GetDynamicProperty(dvspgMor, "config");
                    DVPortgroupConfigSpec dvPortGConfigSpec = new DVPortgroupConfigSpec();
                    dvPortGConfigSpec.configVersion = configInfo.configVersion;
                    DVPortSetting portSetting            = new DVPortSetting();
                    StringPolicy  networkResourcePoolKey = new StringPolicy();
                    networkResourcePoolKey.value        = nrpKey;
                    networkResourcePoolKey.inherited    = false;
                    portSetting.networkResourcePoolKey  = networkResourcePoolKey;
                    dvPortGConfigSpec.name              = dvPortGroupName;
                    dvPortGConfigSpec.defaultPortConfig = portSetting;
                    ManagedObjectReference taskmor = cb._connection._service.ReconfigureDVPortgroup_Task(dvspgMor, dvPortGConfigSpec);
                    if (taskmor != null)
                    {
                        String status = cb.getServiceUtil().WaitForTask(
                            taskmor);
                        if (status.Equals("sucess"))
                        {
                            Console.WriteLine("Sucessfully Associated Port Group::" + dvPortGroupName + " with the Network Resource Pool::"
                                              + nrpName + " on the DVS::" + dvSwitchName);
                        }
                        else
                        {
                            Console.WriteLine("Failure while reconfiguring the port group");
                            throw new Exception(status);
                        }
                    }
                }
                else
                {
                    throw new Exception("DVS port group " + dvPortGroupName + " Not Found");
                }
            }
            else
            {
                throw new Exception("DVS Switch " + dvSwitchName + " Not Found");
            }
        }
예제 #3
0
        /// <summary>
        /// Associates a given NetworkResourcePool to the given DVSPortGroup on the given DVS switch
        /// </summary>
        /// <param name="dvSwitchName"></param>
        /// <param name="nrpName"></param>
        /// <param name="dvPortGroupName"></param>
        private void ReconfigureDVSPG(string dvSwitchName, string nrpName,
                                             string dvPortGroupName)
        {
            DVSNetworkResourcePool[] nrpList = null;
            ManagedObjectReference dvsMor = cb._svcUtil.getEntityByName("VmwareDistributedVirtualSwitch", dvSwitchName);
            if (dvsMor != null)
            {
                string[] type = new string[] { "networkResourcePool" };
                ObjectContent[] objContent = cb.getServiceUtil().GetObjectProperties(null, dvsMor, type);
                if (objContent != null)
                {
                    nrpList = (DVSNetworkResourcePool[])objContent[0].propSet[0].val;
                }

                string nrpKey = null;
                if (nrpList != null)
                {
                    foreach (DVSNetworkResourcePool dvsNrp in nrpList)
                    {
                        if (dvsNrp.name.Equals(nrpName))
                        {
                            nrpKey = dvsNrp.key;
                            break;
                        }
                    }

                    if (nrpKey == null)
                    {
                        throw new Exception("NetworkResource Pool " + nrpName + " Not Found");
                    }
                }
                else
                {
                    throw new Exception("No NetworkResourcePool found for DVS Switch " + dvSwitchName);
                }
                ManagedObjectReference dvspgMor = cb._svcUtil.getEntityByName("DistributedVirtualPortgroup",
                                                    dvPortGroupName);

                if (dvspgMor != null)
                {

                    DVPortgroupConfigInfo configInfo = (DVPortgroupConfigInfo)cb.getServiceUtil().GetDynamicProperty(dvspgMor, "config");
                    DVPortgroupConfigSpec dvPortGConfigSpec = new DVPortgroupConfigSpec();
                    dvPortGConfigSpec.configVersion = configInfo.configVersion;
                    DVPortSetting portSetting = new DVPortSetting();
                    StringPolicy networkResourcePoolKey = new StringPolicy();
                    networkResourcePoolKey.value = nrpKey;
                    networkResourcePoolKey.inherited = false;
                    portSetting.networkResourcePoolKey = networkResourcePoolKey;
                    dvPortGConfigSpec.name = dvPortGroupName;
                    dvPortGConfigSpec.defaultPortConfig = portSetting;
                    ManagedObjectReference taskmor = cb._connection._service.ReconfigureDVPortgroup_Task(dvspgMor, dvPortGConfigSpec);
                    if (taskmor != null)
                    {
                        String status = cb.getServiceUtil().WaitForTask(
                              taskmor);
                        if (status.Equals("sucess"))
                        {
                            Console.WriteLine("Sucessfully Associated Port Group::" + dvPortGroupName + " with the Network Resource Pool::"
                                + nrpName + " on the DVS::" + dvSwitchName);
                        }
                        else
                        {
                            Console.WriteLine("Failure while reconfiguring the port group");
                            throw new Exception(status);
                        }
                    }
                }
                else
                {
                    throw new Exception("DVS port group " + dvPortGroupName + " Not Found");
                }
            }
            else
            {
                throw new Exception("DVS Switch " + dvSwitchName + " Not Found");
            }
        }
예제 #4
0
        /// <summary>
        /// This method is used to create DVS or add port group according to user choice.
        /// </summary>
        private void DoCreate()
        {
            string dcname     = cb.get_option("dcname");
            string dvsname    = cb.get_option("dvsname");
            string dvsdesc    = cb.get_option("dvsdesc");
            string dvsversion = cb.get_option("dvsversion");
            int    numPorts   = 0;

            if (cb.get_option("numports") != null)
            {
                numPorts = int.Parse(cb.get_option("numports"));
            }
            string portGroupName = cb.get_option("portgroupname");

            try
            {
                if (GetItemType().Equals("createdvs"))
                {
                    ManagedObjectReference dcmor = cb._svcUtil.getEntityByName("Datacenter", dcname);
                    if (dcmor != null)
                    {
                        ManagedObjectReference networkmor               = cb.getServiceUtil().GetMoRefProp(dcmor, "networkFolder");
                        DVSCreateSpec          dvscreatespec            = new DVSCreateSpec();
                        DistributedVirtualSwitchProductSpec dvsProdSpec = GetDVSProductSpec(dvsversion);
                        dvscreatespec.productInfo = dvsProdSpec;
                        DistributedVirtualSwitchHostProductSpec[] dvsHostProdSpec =
                            cb.getConnection()._service.QueryDvsCompatibleHostSpec(cb.getConnection().
                                                                                   _sic.dvSwitchManager, dvsProdSpec);

                        DVSCapability dvsCapability = new DVSCapability();
                        dvsCapability.compatibleHostComponentProductInfo = dvsHostProdSpec;
                        dvscreatespec.capability = dvsCapability;
                        DVSConfigSpec configSpec = GetConfigSpec(dvsname, dvsdesc);
                        dvscreatespec.configSpec = configSpec;

                        ManagedObjectReference taskmor =
                            cb.getConnection()._service.CreateDVS_Task(networkmor, dvscreatespec);
                        if (taskmor != null)
                        {
                            String status = cb.getServiceUtil().WaitForTask(
                                taskmor);
                            if (status.Equals("sucess"))
                            {
                                Console.WriteLine("Sucessfully created::"
                                                  + dvsname);
                            }
                            else
                            {
                                Console.WriteLine("dvs switch" + dvsname
                                                  + " not created::");
                                throw new Exception(status);
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("Datacenter" + dcname + "not found");
                    }
                }
                else if (GetItemType().Equals("addportgroup"))
                {
                    ManagedObjectReference dvsMor = cb._svcUtil.getEntityByName("VmwareDistributedVirtualSwitch", dvsname);
                    if (dvsMor != null)
                    {
                        DVPortgroupConfigSpec portGroupConfigSpec = new DVPortgroupConfigSpec();
                        portGroupConfigSpec.name     = portGroupName;
                        portGroupConfigSpec.numPorts = numPorts;
                        portGroupConfigSpec.type     = "earlyBinding";
                        List <DVPortgroupConfigSpec> lst = new List <DVPortgroupConfigSpec>();
                        lst.Add(portGroupConfigSpec);
                        ManagedObjectReference taskmor =
                            cb.getConnection()._service.AddDVPortgroup_Task(dvsMor, lst.ToArray());
                        if (taskmor != null)
                        {
                            String status = cb.getServiceUtil().WaitForTask(
                                taskmor);
                            if (status.Equals("sucess"))
                            {
                                Console.WriteLine("Sucessfully added port group :"
                                                  + portGroupName);
                            }
                            else
                            {
                                Console.WriteLine("port group" + portGroupName
                                                  + " not added:");
                                throw new Exception(status);
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("DvsSwitch  " + dvsname + " not found");
                    }
                }
                else
                {
                    Console.WriteLine("Unknown Type. Allowed types are:");
                    Console.WriteLine(" createdvs");
                    Console.WriteLine(" addportgroup");
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
예제 #5
0
        /// <summary>
        /// This method is used to create DVS or add port group according to user choice.
        /// </summary>
        private void DoCreate()
        {
            string dcname = cb.get_option("dcname");
            string dvsname = cb.get_option("dvsname");
            string dvsdesc = cb.get_option("dvsdesc");
            string dvsversion = cb.get_option("dvsversion");
            int numPorts = 0;
            if (cb.get_option("numports") != null)
            {
                numPorts = int.Parse(cb.get_option("numports"));
            }
            string portGroupName = cb.get_option("portgroupname");
            try
            {
                if (GetItemType().Equals("createdvs"))
                {
                    ManagedObjectReference dcmor = cb._svcUtil.getEntityByName("Datacenter", dcname);
                    if (dcmor != null)
                    {
                        ManagedObjectReference networkmor = cb.getServiceUtil().GetMoRefProp(dcmor, "networkFolder");
                        DVSCreateSpec dvscreatespec = new DVSCreateSpec();
                        DistributedVirtualSwitchProductSpec dvsProdSpec = GetDVSProductSpec(dvsversion);
                        dvscreatespec.productInfo = dvsProdSpec;
                        DistributedVirtualSwitchHostProductSpec[] dvsHostProdSpec =
                            cb.getConnection()._service.QueryDvsCompatibleHostSpec(cb.getConnection().
                            _sic.dvSwitchManager, dvsProdSpec);

                        DVSCapability dvsCapability = new DVSCapability();
                        dvsCapability.compatibleHostComponentProductInfo = dvsHostProdSpec;
                        dvscreatespec.capability = dvsCapability;
                        DVSConfigSpec configSpec = GetConfigSpec(dvsname, dvsdesc);
                        dvscreatespec.configSpec = configSpec;

                        ManagedObjectReference taskmor =
                               cb.getConnection()._service.CreateDVS_Task(networkmor, dvscreatespec);
                        if (taskmor != null)
                        {
                            String status = cb.getServiceUtil().WaitForTask(
                                  taskmor);
                            if (status.Equals("sucess"))
                            {
                                Console.WriteLine("Sucessfully created::"
                                      + dvsname);
                            }
                            else
                            {
                                Console.WriteLine("dvs switch" + dvsname
                                   + " not created::");
                                throw new Exception(status);
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("Datacenter" + dcname + "not found");
                    }
                }
                else if (GetItemType().Equals("addportgroup"))
                {
                    ManagedObjectReference dvsMor = cb._svcUtil.getEntityByName("VmwareDistributedVirtualSwitch", dvsname);
                    if (dvsMor != null)
                    {
                        DVPortgroupConfigSpec portGroupConfigSpec = new DVPortgroupConfigSpec();
                        portGroupConfigSpec.name = portGroupName;
                        portGroupConfigSpec.numPorts = numPorts;
                        portGroupConfigSpec.type = "earlyBinding";
                        List<DVPortgroupConfigSpec> lst = new List<DVPortgroupConfigSpec>();
                        lst.Add(portGroupConfigSpec);
                        ManagedObjectReference taskmor =
                        cb.getConnection()._service.AddDVPortgroup_Task(dvsMor, lst.ToArray());
                        if (taskmor != null)
                        {
                            String status = cb.getServiceUtil().WaitForTask(
                                  taskmor);
                            if (status.Equals("sucess"))
                            {
                                Console.WriteLine("Sucessfully added port group :"
                                      + portGroupName);
                            }
                            else
                            {
                                Console.WriteLine("port group" + portGroupName
                                   + " not added:");
                                throw new Exception(status);
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("DvsSwitch  " + dvsname + " not found");
                    }
                }
                else
                {
                    Console.WriteLine("Unknown Type. Allowed types are:");
                    Console.WriteLine(" createdvs");
                    Console.WriteLine(" addportgroup");
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }