Esempio n. 1
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");
            }
        }
Esempio n. 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");
            }
        }