Example #1
0
 public void RemovePortGroup(VMware.Vim.HostConfigManager configMgr, string portGroupName)
 {
     VMware.Vim.ManagedObjectReference nMob = configMgr.NetworkSystem;
     //HostNetworkInfo nwSystem = (HostNetworkInfo)this.GetDynamicProperty(nMob, "networkInfo");
     vimService.RemovePortGroup(nMob != null ? new VimApi_55.ManagedObjectReference()
     {
         type  = nMob.Type,
         Value = nMob.Value
     } : null, portGroupName);
 }
Example #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);
        }
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 Object GetDynamicProperty(VMware.Vim.ManagedObjectReference mor, String propertyName)
        {
            VimApi_55.ObjectContent[] objContent = GetObjectProperties(null, mor,
                                                                       new String[] { propertyName });

            Object propertyValue = null;

            if (objContent != null)
            {
                VimApi_55.DynamicProperty[] dynamicProperty = objContent[0].propSet;
                if (dynamicProperty != null)
                {
                    Object dynamicPropertyVal  = dynamicProperty[0].val;
                    String dynamicPropertyName = dynamicPropertyVal.GetType().FullName;
                    propertyValue = dynamicPropertyVal;
                }
            }
            return(propertyValue);
        }
Example #5
0
        private VimApi_55.ObjectContent[] GetObjectProperties(
            VMware.Vim.ManagedObjectReference collector,
            VMware.Vim.ManagedObjectReference mobj, string[] properties
            )
        {
            if (mobj == null)
            {
                return(null);
            }

            VimApi_55.ManagedObjectReference usecoll = collector != null ? new VimApi_55.ManagedObjectReference()
            {
                type  = collector.Type,
                Value = collector.Value
            } : null;
            if (usecoll == null)
            {
                usecoll = new VimApi_55.ManagedObjectReference()
                {
                    type  = this.vConnection.PropertyCollector.Type,
                    Value = this.vConnection.PropertyCollector.Value
                };
            }

            VimApi_55.PropertyFilterSpec spec = new VimApi_55.PropertyFilterSpec();
            spec.propSet                 = new VimApi_55.PropertySpec[] { new VimApi_55.PropertySpec() };
            spec.propSet[0].all          = properties == null || properties.Length == 0;
            spec.propSet[0].allSpecified = spec.propSet[0].all;
            spec.propSet[0].type         = mobj.Type;
            spec.propSet[0].pathSet      = properties;

            spec.objectSet        = new VimApi_55.ObjectSpec[] { new VimApi_55.ObjectSpec() };
            spec.objectSet[0].obj = mobj != null ? new VimApi_55.ManagedObjectReference()
            {
                type  = mobj.Type,
                Value = mobj.Value
            } : null;
            spec.objectSet[0].skip = false;
            return(RetrievePropertiesEx(usecoll, new VimApi_55.PropertyFilterSpec[] { spec }));
        }
Example #6
0
 private void importListFromVCenterToolStripMenuItem_Click(object sender, EventArgs e)
 {
     var vcenterConnectForm = new VCenterConnectForm(defaultVcenterServer);
     var result = vcenterConnectForm.ShowDialog(this);
     if (result == DialogResult.Yes)
     {
         VCenterClient = vcenterConnectForm.VCenterClient;
         VCenterServer = vcenterConnectForm.VCenterServer;
         VCenterUserName = vcenterConnectForm.VCenterUserName;
         VCenterUserPassword = vcenterConnectForm.VCenterUserPassword;
         var moRef = new VMware.Vim.ManagedObjectReference();
         moRef.Type = "Datacenter";
         moRef.Value = vcenterConnectForm.DCMoRef;
         NameValueCollection filter = null;
         if (vcenterConnectForm.PowerState.ToLower() != "any")
         {
             filter = new NameValueCollection();
             filter.Add("Runtime.PowerState", vcenterConnectForm.PowerState);
         }
         var worker = new BackgroundWorker();
         worker.DoWork += new DoWorkEventHandler(new Action<object, DoWorkEventArgs>((o, args) =>
         {
             addToActionLog("Started: Loading server list from VCenter");
             IList<VMware.Vim.EntityViewBase> vmList =
                 VCenterClient.FindEntityViews(typeof(VMware.Vim.VirtualMachine), moRef, filter, null);
             lock (gridLock)
             {
                 gridModifier++;
             }
             foreach (VMware.Vim.VirtualMachine vm in vmList)
             {
                 addVMNodeToGrid(vm.Name, ActionRunner.dateStampResult().Invoke(vm.Runtime.PowerState.ToString()));
             }
             lock (gridLock)
             {
                 gridModifier--;
             }
             addToActionLog("Complete: Loading server list from VCenter");
         }));
         worker.RunWorkerAsync();
     }
     else if (result == DialogResult.OK && vcenterConnectForm.Connected)
     {
         VCenterClient = vcenterConnectForm.VCenterClient;
         VCenterServer = vcenterConnectForm.VCenterServer;
         VCenterUserName = vcenterConnectForm.VCenterUserName;
         VCenterUserPassword = vcenterConnectForm.VCenterUserPassword;
         addToActionLog("Completed: Connected to VCenter.  VM actions should now work.");
     }
     vcenterConnectForm.Close();
 }