Beispiel #1
0
        /// <summary>
        /// Create the Managed Object References for the sample
        /// </summary>
        /// <param name="name">name of sample</param>
        public void CreateServiceRef(string name, string[] args)
        {
            var svcCon = cb.getConnection();

            _service    = svcCon.Service;
            _propCol    = svcCon.PropCol;
            _rootFolder = svcCon.Root;
        }
Beispiel #2
0
        public void displayNewProperties()
        {
            _service = ecb.getConnection().Service;
            _sic     = ecb.getConnection().ServiceContent;
            String vmName = ecb.get_option("vmname");
            ManagedObjectReference vmmor = ecb.getServiceUtil().GetDecendentMoRef(null,
                                                                                  "VirtualMachine", vmName);

            if (vmmor != null)
            {
                ArrayList supportedVersions = VersionUtil.getSupportedVersions(ecb.get_option("url"));

                Object[] vmProps    = getProperties(vmmor, new String[] { "name" });
                String   serverName = (String)vmProps[0];
                Console.WriteLine("Virtual Machine Name " + serverName);

                vmProps = getProperties(vmmor, new String[] { "config.uuid" });
                String uuid = (String)vmProps[0];
                Console.WriteLine("Config UUID " + uuid);

                vmProps = getProperties(vmmor, new String[] { "config.guestId" });
                String guestId = (String)vmProps[0];
                Console.WriteLine("Guest Id " + guestId);

                if (VersionUtil.isApiVersionSupported(supportedVersions, "2.5"))
                {
                    vmProps = getProperties(vmmor, new String[] { "name" });

                    Boolean bootOptionsSupported = (Boolean)getObjectProperty(vmmor, "capability.bootOptionsSupported");
                    Console.WriteLine("Boot Options Supported " + bootOptionsSupported);

                    Boolean diskSharesSupported = (Boolean)getObjectProperty(vmmor, "capability.diskSharesSupported");
                    Console.WriteLine("Disk Shares Supported " + diskSharesSupported);

                    Boolean flag = VersionUtil.isApiVersionSupported(supportedVersions, "4.0");
                    Console.WriteLine("Is API Supported  " + flag);
                    if (flag)
                    {
                        Console.WriteLine("\nProperties added in vSphere API 4.0\n");
                        Boolean changeTrackingSupported = (Boolean)getObjectProperty(vmmor, "capability.changeTrackingSupported");
                        Console.WriteLine("Change Tracking Supported " + changeTrackingSupported);

                        Boolean recordReplaySupported = (Boolean)getObjectProperty(vmmor, "capability.recordReplaySupported");
                        Console.WriteLine("Record Replay Supported " + recordReplaySupported);

                        VirtualMachineFaultToleranceState faultToleranceState
                            = (VirtualMachineFaultToleranceState)getObjectProperty(vmmor, "runtime.faultToleranceState");
                        Console.WriteLine("Fault Tolerance State " + faultToleranceState);
                    }
                }
            }
            else
            {
                Console.WriteLine("Virtal Machine Not Found");
            }
        }
        public void displayNewProperties() {
            _service = ecb.getConnection().Service;
            _sic = ecb.getConnection().ServiceContent;
            String vmName = ecb.get_option("vmname");
            ManagedObjectReference vmmor = ecb.getServiceUtil().GetDecendentMoRef(null,
                                             "VirtualMachine", vmName);

            if (vmmor != null)
            {
                ArrayList supportedVersions = VersionUtil.getSupportedVersions(ecb.get_option("url"));

                Object[] vmProps = getProperties(vmmor, new String[] { "name" });
                String serverName = (String)vmProps[0];
                Console.WriteLine("Virtual Machine Name " + serverName);

                vmProps = getProperties(vmmor, new String[] { "config.uuid" });
                String uuid = (String)vmProps[0];
                Console.WriteLine("Config UUID " + uuid);

                vmProps = getProperties(vmmor, new String[] { "config.guestId" });
                String guestId = (String)vmProps[0];
                Console.WriteLine("Guest Id " + guestId);

                if (VersionUtil.isApiVersionSupported(supportedVersions, "2.5"))
                {
                    vmProps = getProperties(vmmor, new String[] { "name" });
                    
                    Boolean bootOptionsSupported = (Boolean)getObjectProperty(vmmor, "capability.bootOptionsSupported");
                    Console.WriteLine("Boot Options Supported " + bootOptionsSupported);

                    Boolean diskSharesSupported = (Boolean)getObjectProperty(vmmor, "capability.diskSharesSupported");
                    Console.WriteLine("Disk Shares Supported " + diskSharesSupported);

                    Boolean flag = VersionUtil.isApiVersionSupported(supportedVersions, "4.0");
                    Console.WriteLine("Is API Supported  " + flag);
                    if (flag)
                    {
                        Console.WriteLine("\nProperties added in vSphere API 4.0\n");
                        Boolean changeTrackingSupported = (Boolean)getObjectProperty(vmmor, "capability.changeTrackingSupported");
                        Console.WriteLine("Change Tracking Supported " + changeTrackingSupported);

                        Boolean recordReplaySupported = (Boolean)getObjectProperty(vmmor, "capability.recordReplaySupported");
                        Console.WriteLine("Record Replay Supported " + recordReplaySupported);

                        VirtualMachineFaultToleranceState faultToleranceState
                           = (VirtualMachineFaultToleranceState)getObjectProperty(vmmor, "runtime.faultToleranceState");
                        Console.WriteLine("Fault Tolerance State " + faultToleranceState);
                    }
                }
            }
            else
            {
                Console.WriteLine("Virtal Machine Not Found");
            }
        }
Beispiel #4
0
        public void PowerDownHost(String[] args)
        {
            _service = cb.getConnection().Service;
            _sic     = cb.getConnection().ServiceContent;
            String hostname             = cb.get_option("hostname");
            ManagedObjectReference hmor =
                cb.getServiceUtil().GetDecendentMoRef(null, "HostSystem", hostname);

            if (hmor != null)
            {
                if (cb.get_option("operation").Equals("reboot"))
                {
                    ManagedObjectReference taskmor
                        = _service.RebootHost_Task(hmor, true);
                    String result = cb.getServiceUtil().WaitForTask(taskmor);
                    if (result.Equals("sucess"))
                    {
                        Console.WriteLine("Operation reboot host"
                                          + " completed sucessfully");
                    }
                }
                else if (cb.get_option("operation").Equals("shutdown"))
                {
                    ManagedObjectReference taskmor
                        = _service.ShutdownHost_Task(hmor, true);
                    String result = cb.getServiceUtil().WaitForTask(taskmor);
                    if (result.Equals("sucess"))
                    {
                        Console.WriteLine("Operation shutdown host"
                                          + " completed sucessfully");
                    }
                }
                else if (cb.get_option("operation").Equals("powerdowntostandby"))
                {
                    ManagedObjectReference taskmor = _service.
                                                     PowerDownHostToStandBy_Task(hmor, 120, false, true);
                    String result = cb.getServiceUtil().WaitForTask(taskmor);
                    if (result.Equals("sucess"))
                    {
                        Console.WriteLine("Operation powerDownHostToStandBy"
                                          + " completed sucessfully");
                    }
                }
            }
            else
            {
                Console.WriteLine("Host " + cb.get_option("hostname") + " not found");
            }
        }
 public void PowerDownHost(String[] args)
 {
     _service = cb.getConnection().Service;
     _sic = cb.getConnection().ServiceContent;
     String hostname = cb.get_option("hostname");
     ManagedObjectReference hmor =
           cb.getServiceUtil().GetDecendentMoRef(null, "HostSystem", hostname);
     if (hmor != null)
     {
         if (cb.get_option("operation").Equals("reboot"))
         {
             ManagedObjectReference taskmor
                = _service.RebootHost_Task(hmor, true);
             String result = cb.getServiceUtil().WaitForTask(taskmor);
             if (result.Equals("sucess"))
             {
                 Console.WriteLine("Operation reboot host"
                                    + " completed sucessfully");
             }
         }
         else if (cb.get_option("operation").Equals("shutdown"))
         {
             ManagedObjectReference taskmor
                = _service.ShutdownHost_Task(hmor, true);
             String result = cb.getServiceUtil().WaitForTask(taskmor);
             if (result.Equals("sucess"))
             {
                 Console.WriteLine("Operation shutdown host"
                                    + " completed sucessfully");
             }
         }
         else if (cb.get_option("operation").Equals("powerdowntostandby"))
         {
                 ManagedObjectReference taskmor = _service.
                     PowerDownHostToStandBy_Task(hmor, 120, false, true);
                 String result = cb.getServiceUtil().WaitForTask(taskmor);
                 if (result.Equals("sucess"))
                 {
                     Console.WriteLine("Operation powerDownHostToStandBy"
                              + " completed sucessfully");
                 }
         }
     }
     else
     {
         Console.WriteLine("Host " + cb.get_option("hostname") + " not found");
     }
 }
       public static void powerDownHost(VimApi.ManagedObjectReference hmor, String[] args, ArrayList apiVersions, Cookie cookie)
       {
      ExtendedAppUtil ecb = null;                  
      ecb = ExtendedAppUtil.initialize("PowerDownHostToStandBy"
                                       , HostPowerOps.constructOptions()
                                       ,args);
      ecb.connect(cookie);

      _service = ecb.getServiceConnectionV25().Service;
      _sic = ecb.getServiceConnectionV25().ServiceContent;          
      // Convert the vim managed object to vim25 managed object
      ManagedObjectReference hmor1  = 
         VersionUtil.convertManagedObjectReference(hmor);
                
      ManagedObjectReference taskmor =  _service.PowerDownHostToStandBy_Task(hmor1,120,false,true);
      String result = ecb.getServiceUtilV25().WaitForTask(taskmor);
      if(result.Equals("sucess")) {
         Console.WriteLine("Operation powerDownHostToStandBy"
                            +" completed sucessfully");
      }
   }
 /// <summary>
 /// Create the Managed Object References for the sample
 /// </summary>
 /// <param name="name">name of sample</param>
 public void CreateServiceRef(string name, string[] args) {
     var svcCon = cb.getConnection();
     _service = svcCon.Service;
     _propCol = svcCon.PropCol;
     _rootFolder = svcCon.Root;
 }
Beispiel #8
0
        public void queryMemoryOverhead()
        {
            _service = ecb.getConnection().Service;
            _sic     = ecb.getConnection().ServiceContent;

            ArrayList supportedVersions = VersionUtil.getSupportedVersions(ecb.get_option("url"));
            String    hostname          = ecb.get_option("hostname");
            ManagedObjectReference hmor =
                ecb.getServiceUtil().GetDecendentMoRef(null, "HostSystem", hostname);

            if (hmor != null)
            {
                if (VersionUtil.isApiVersionSupported(supportedVersions, "2.5"))
                {
                    VirtualMachineConfigInfo vmConfigInfo =
                        new VirtualMachineConfigInfo();
                    vmConfigInfo.changeVersion = "1";
                    DateTime dt = ecb.getConnection().Service.CurrentTime(ecb.getConnection().ServiceRef);
                    vmConfigInfo.modified = dt;

                    VirtualMachineDefaultPowerOpInfo defaultInfo
                        = new VirtualMachineDefaultPowerOpInfo();
                    vmConfigInfo.defaultPowerOps = defaultInfo;

                    VirtualMachineFileInfo fileInfo
                        = new VirtualMachineFileInfo();
                    vmConfigInfo.files = fileInfo;

                    VirtualMachineFlagInfo flagInfo
                        = new VirtualMachineFlagInfo();
                    vmConfigInfo.flags = flagInfo;

                    vmConfigInfo.guestFullName = "Full Name";
                    vmConfigInfo.guestId       = "Id";

                    VirtualHardware vhardware
                        = new VirtualHardware();
                    vhardware.memoryMB    = int.Parse(ecb.get_option("memorysize"));
                    vhardware.numCPU      = int.Parse(ecb.get_option("cpucount"));
                    vmConfigInfo.hardware = vhardware;

                    // Not Required For Computing The Overhead
                    vmConfigInfo.name               = "OnlyFoeInfo";
                    vmConfigInfo.uuid               = "12345678-abcd-1234-cdef-123456789abc";
                    vmConfigInfo.version            = "First";
                    vmConfigInfo.template           = false;
                    vmConfigInfo.alternateGuestName = "Alternate";

                    long overhead
                        = ecb._connection._service.QueryMemoryOverheadEx(
                              hmor, vmConfigInfo);
                    Console.WriteLine("Using queryMemoryOverheadEx API using vmReconfigInfo");
                    Console.WriteLine("Memory overhead necessary to "
                                      + "poweron a virtual machine with memory "
                                      + ecb.get_option("memorysize")
                                      + " MB and cpu count "
                                      + ecb.get_option("cpucount")
                                      + " -: " + overhead + " bytes");
                }
                else
                {
                    long overhead
                        = ecb._connection._service.QueryMemoryOverhead(hmor,
                                                                       long.Parse(ecb.get_option("memorysize")), 0, false,
                                                                       int.Parse(ecb.get_option("cpucount"))
                                                                       );
                    Console.WriteLine("Using queryMemoryOverhead API "
                                      + "using CPU count and Memory Size");
                    Console.WriteLine("Memory overhead necessary to "
                                      + "poweron a virtual machine with memory "
                                      + ecb.get_option("memorysize")
                                      + " MB and cpu count "
                                      + ecb.get_option("cpucount")
                                      + " -: " + overhead + " bytes");
                }
            }
            else
            {
                Console.WriteLine("Host " + ecb.get_option("hostname") + " not found");
            }
        }
       public void queryMemoryOverhead()
       {
           _service = ecb.getConnection().Service;
           _sic = ecb.getConnection().ServiceContent;

           ArrayList supportedVersions = VersionUtil.getSupportedVersions(ecb.get_option("url"));
           String hostname = ecb.get_option("hostname");
           ManagedObjectReference hmor =
              ecb.getServiceUtil().GetDecendentMoRef(null, "HostSystem", hostname);

           if (hmor != null)
           {
               if (VersionUtil.isApiVersionSupported(supportedVersions, "2.5"))
               {
                   VirtualMachineConfigInfo vmConfigInfo =
                           new VirtualMachineConfigInfo();
                   vmConfigInfo.changeVersion = "1";
                   DateTime dt = ecb.getConnection().Service.CurrentTime(ecb.getConnection().ServiceRef);
                   vmConfigInfo.modified = dt;
                
                   VirtualMachineDefaultPowerOpInfo defaultInfo 
                      = new VirtualMachineDefaultPowerOpInfo();
                   vmConfigInfo.defaultPowerOps=defaultInfo;
           
                   VirtualMachineFileInfo fileInfo 
                      = new VirtualMachineFileInfo();
                   vmConfigInfo.files=fileInfo;
            
                   VirtualMachineFlagInfo flagInfo 
                      = new VirtualMachineFlagInfo();
                   vmConfigInfo.flags=flagInfo;
            
                   vmConfigInfo.guestFullName="Full Name";
                   vmConfigInfo.guestId="Id";
            
                   VirtualHardware vhardware 
                      = new VirtualHardware();
                   vhardware.memoryMB=int.Parse(ecb.get_option("memorysize"));
                   vhardware.numCPU=int.Parse(ecb.get_option("cpucount"));
                   vmConfigInfo.hardware=vhardware;
            
                   // Not Required For Computing The Overhead
                   vmConfigInfo.name="OnlyFoeInfo";
                   vmConfigInfo.uuid="12345678-abcd-1234-cdef-123456789abc";
                   vmConfigInfo.version="First";
                   vmConfigInfo.template=false;
                   vmConfigInfo.alternateGuestName="Alternate";
            
                   long overhead 
                      = ecb._connection._service.QueryMemoryOverheadEx(
                                             hmor,vmConfigInfo);      
                   Console.WriteLine("Using queryMemoryOverheadEx API using vmReconfigInfo");
                   Console.WriteLine("Memory overhead necessary to "
                                     + "poweron a virtual machine with memory " 
                                     + ecb.get_option("memorysize") 
                                     + " MB and cpu count " 
                                     + ecb.get_option("cpucount") 
                                     + " -: " + overhead + " bytes");
               }
               else
               {
                   long overhead
                      = ecb._connection._service.QueryMemoryOverhead(hmor,
                           long.Parse(ecb.get_option("memorysize")), 0, false,
                           int.Parse(ecb.get_option("cpucount"))
                        );
                   Console.WriteLine("Using queryMemoryOverhead API "
                                     + "using CPU count and Memory Size");
                   Console.WriteLine("Memory overhead necessary to "
                                      + "poweron a virtual machine with memory "
                                      + ecb.get_option("memorysize")
                                      + " MB and cpu count "
                                      + ecb.get_option("cpucount")
                                      + " -: " + overhead + " bytes");
               }
           }
           else
           {
               Console.WriteLine("Host " + ecb.get_option("hostname") + " not found");
           }
       }