Ejemplo n.º 1
0
        public void migrateVM(String vmname, String pool, String tHost, String srcHost)
        {
            String state;
            VirtualMachinePowerState   st  = VirtualMachinePowerState.poweredOff;
            VirtualMachineMovePriority pri = VirtualMachineMovePriority.defaultPriority;

            if (cb.option_is_set("state"))
            {
                state = cb.get_option("state");
                if (cb.get_option("state").Equals("suspended"))
                {
                    st = VirtualMachinePowerState.suspended;
                }
                else if (cb.get_option("state").Equals("poweredOn"))
                {
                    st = VirtualMachinePowerState.poweredOn;
                }
                else if (cb.get_option("state").Equals("poweredOff"))
                {
                    st = VirtualMachinePowerState.poweredOff;
                }
            }
            pri = getPriority();

            try
            {
                ManagedObjectReference srcMOR  = getMOR(srcHost, "HostSystem", null);
                ManagedObjectReference vmMOR   = getMOR(vmname, "VirtualMachine", srcMOR);
                ManagedObjectReference poolMOR = getMOR(pool, "ResourcePool", null);
                ManagedObjectReference hMOR    = getMOR(tHost, "HostSystem", null);
                if (vmMOR == null || srcMOR == null || poolMOR == null || hMOR == null)
                {
                    return;
                }

                Console.WriteLine("Migrating the Virtual Machine " + vmname);
                ManagedObjectReference taskMOR
                    = cb._connection._service.MigrateVM_Task(vmMOR, poolMOR, hMOR, pri, st, true);
                String res = cb.getServiceUtil().WaitForTask(taskMOR);
                if (res.Equals("sucess"))
                {
                    Console.WriteLine("Migration of Virtual Machine " + vmname + " done successfully to " + tHost);
                }
                else
                {
                    Console.WriteLine("Error::  Migration failed");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
        public VirtualMachineState getState()
        {
            Object [] properties             = getProperties(vmmor, new String [] { "runtime.powerState" });
            VirtualMachinePowerState vmState = (VirtualMachinePowerState)properties[0];

            switch (vmState)
            {
            case VirtualMachinePowerState.poweredOff:
                return(VirtualMachineState.POWERED_OFF);

            case VirtualMachinePowerState.poweredOn:
                return(VirtualMachineState.POWERED_ON);

            case VirtualMachinePowerState.suspended:
                return(VirtualMachineState.SUSPENDED);

            default:
                return(VirtualMachineState.UNKNOWN);
            }
        }
Ejemplo n.º 3
0
 public void setPowerState(
         VirtualMachinePowerState powerState)
 {
     this.powerState = powerState;
 }
Ejemplo n.º 4
0
 public VirtualMachine(ManagedObjectReference _this,
         String name,
         ManagedObjectReference host,
         VirtualMachinePowerState powerState,
         ManagedEntityStatus overallStatus,
         VirtualMachineQuickStats quickStats)
 {
     this.setMoRef(_this);
     this.setName(name);
     this.setHost(host);
     this.setPowerState(powerState);
     this.setOverallStatus(overallStatus);
     this.setQuickStats(quickStats);
 }