コード例 #1
0
ファイル: BallooningPage.cs プロジェクト: xueqingz/xenadmin
 public MemSettings(bool has_ballooning, vm_power_state power_state,
                    long static_min, long static_max, long dynamic_min, long dynamic_max)
 {
     this.has_ballooning = has_ballooning;
     this.power_state    = power_state;
     this.static_min     = static_min;
     this.static_max     = static_max;
     this.dynamic_min    = dynamic_min;
     this.dynamic_max    = dynamic_max;
 }
コード例 #2
0
        private List <VM> GetEvacuatedVMs(String key, vm_power_state expectedPowerState)
        {
            List <VM> vms = GetVMs(key);

            foreach (VM vm in vms.ToArray())
            {
                if (vm.power_state != expectedPowerState)
                {
                    vms.Remove(vm);
                }
            }

            return(vms);
        }
コード例 #3
0
 public static string ToString(vm_power_state x)
 {
     switch (x)
     {
         case vm_power_state.Halted:
             return "Halted";
         case vm_power_state.Paused:
             return "Paused";
         case vm_power_state.Running:
             return "Running";
         case vm_power_state.Suspended:
             return "Suspended";
         default:
             return "unknown";
     }
 }
コード例 #4
0
        public static string ToString(vm_power_state x)
        {
            switch (x)
            {
            case vm_power_state.Halted:
                return("Halted");

            case vm_power_state.Paused:
                return("Paused");

            case vm_power_state.Running:
                return("Running");

            case vm_power_state.Suspended:
                return("Suspended");
            }
            return("unknown");
        }
コード例 #5
0
        /// <summary>
        /// Return the FriendlyName of a vm_power_state
        /// </summary>
        public static string ToFriendlyName(this vm_power_state powerState)
        {
            switch (powerState)
            {
            case vm_power_state.Halted:
                return(FriendlyNames.Label_VM_power_state_Halted);

            case vm_power_state.Paused:
                return(FriendlyNames.Label_VM_power_state_Paused);

            case vm_power_state.Running:
                return(FriendlyNames.Label_VM_power_state_Running);

            case vm_power_state.Suspended:
                return(FriendlyNames.Label_VM_power_state_Suspended);

            default:
                return(FriendlyNames.Label_VM_power_state_unknown);
            }
        }
コード例 #6
0
ファイル: vm_power_state.cs プロジェクト: ywwseu/xenadmin
        public static string StringOf(this vm_power_state x)
        {
            switch (x)
            {
            case vm_power_state.Halted:
                return("Halted");

            case vm_power_state.Paused:
                return("Paused");

            case vm_power_state.Running:
                return("Running");

            case vm_power_state.Suspended:
                return("Suspended");

            default:
                return("unknown");
            }
        }
コード例 #7
0
        public VirtualMachineState getState()
        {
            vm_power_state ps = VM.get_power_state(session, vmRef);

            switch (ps)
            {
            case vm_power_state.Halted:
                return(VirtualMachineState.POWERED_OFF);

            case vm_power_state.Running:
                return(VirtualMachineState.POWERED_ON);

            case vm_power_state.Paused:
            case vm_power_state.Suspended:
                return(VirtualMachineState.SUSPENDED);

            case vm_power_state.unknown:
            default:
                return(VirtualMachineState.UNKNOWN);
            }
        }
コード例 #8
0
ファイル: BallooningPage.cs プロジェクト: robhoes/xenadmin
 public MemSettings(bool has_ballooning, vm_power_state power_state,
     long static_min, long static_max, long dynamic_min, long dynamic_max)
 {
     this.has_ballooning = has_ballooning;
     this.power_state = power_state;
     this.static_min = static_min;
     this.static_max = static_max;
     this.dynamic_min = dynamic_min;
     this.dynamic_max = dynamic_max;
 }
コード例 #9
0
ファイル: vm_power_state.cs プロジェクト: ywwseu/xenadmin
 public static string ToString(vm_power_state x)
 {
     return(x.StringOf());
 }
コード例 #10
0
        public void ImpXvaFile()
        {
            log.InfoFormat("开始导入WinCenter xva文件:{0}", ConnectManager.FilePath);
            string vmRef = GetVmRef(applyFile());

            if (string.IsNullOrEmpty(vmRef))
            {
                return;
            }
            log.InfoFormat("WinCenter xva文件导入完成");

            try {
                log.InfoFormat("导入后的WinCenter VM:[{0}]", vmRef);
                List <XenRef <VIF> > vifRefs = VM.get_VIFs(ConnectManager.session, vmRef);
                foreach (XenRef <VIF> vifRef in vifRefs)
                {
                    log.InfoFormat("删除原有的VIF:[{0}]", vifRef.opaque_ref);
                    VIF.destroy(ConnectManager.session, vifRef);
                }
                HTTPHelper.progressInfo     = "删除原有VIF";
                HTTPHelper.progressPercent += 1;

                bool isTemplate = VM.get_is_a_template(ConnectManager.session, vmRef);
                if (isTemplate)
                {
                    log.InfoFormat("导入的xva是模板,删除VM:[{0}]", vmRef);
                    VM.destroy(ConnectManager.session, vmRef);
                    return;
                }

                VIF newVif = ConnectManager.VIF;
                newVif.VM = new XenRef <VM>(vmRef);
                XenRef <VIF> newVifRef = VIF.create(ConnectManager.session, newVif);
                log.InfoFormat("重新创建VIF:[{0}]", newVifRef.opaque_ref);
                string mac = VIF.get_MAC(ConnectManager.session, newVifRef);
                log.InfoFormat("新的MAC地址为:[{0}]", mac);
                string newVifUuid = VIF.get_uuid(ConnectManager.session, newVifRef);
                log.InfoFormat("新的VIF UUID为:[{0}]", newVifUuid);

                HTTPHelper.progressInfo     = "创建新的VIF";
                HTTPHelper.progressPercent += 1;

                DefaultVMName(ConnectManager.VMName);
                log.InfoFormat("检查WinCenter VM的名称,VM名称为:{0}", ConnectManager.VMName);
                VM.set_name_label(ConnectManager.session, vmRef, ConnectManager.VMName);
                HTTPHelper.progressInfo     = "检查VM名称";
                HTTPHelper.progressPercent += 1;

                /**
                 * BUG:AE方式设置IP之后,由于ISO没有弹出,在控制台修改IP重启以后,AE会重新设置ISO配置中的IP
                 * 故不再使用AE这种方式,而是改成在VM启动后使用xenstore-write方式动态修改IP
                 */
                //初始化AE
                //initVmByAe(vmRef, mac);

                XenRef <Host> hostRef = Host.get_by_uuid(ConnectManager.session, ConnectManager.TargetHost.uuid);
                log.InfoFormat("设置WinCenter VM的所属主机:[{0}]", ConnectManager.TargetHostName);
                HTTPHelper.progressInfo = "设置主机";
                VM.set_affinity(ConnectManager.session, vmRef, hostRef);
                HTTPHelper.progressPercent += 1;

                setAutoPoweron(vmRef);
                HTTPHelper.progressInfo = "启动VM";
                VM.start(ConnectManager.session, vmRef, false, false);
                Thread.Sleep(2 * 60 * 1000);                 //休眠2分钟,等待虚拟机启动完成
                HTTPHelper.progressPercent += 2;
                log.InfoFormat("启动WinCenter VM:[{0}]成功", vmRef);

                //去掉AE方式设置IP,VM启动后使用xenstore-write方式动态设置IP
                HTTPHelper.progressInfo = "设置网络信息";
                setActiveVifIp(newVifUuid);
                HTTPHelper.progressPercent = 100;
                log.InfoFormat("设置IP信息成功");
            }
            catch (Exception ex) {
                log.ErrorFormat("安装失败: {0}", ex.Message);
                log.ErrorFormat("开始删除WinCenter VM:[{0}]", vmRef);
                try {
                    vm_power_state power_state = VM.get_power_state(ConnectManager.session, vmRef);
                    if (!vm_power_state.Halted.ToString().Equals(power_state.ToString()))
                    {
                        VM.shutdown(ConnectManager.session, vmRef);
                    }
                }
                catch (Exception ex1) {
                    log.ErrorFormat("WinCenter VM关机失败:{0}", ex1.Message);
                }

                try {
                    VM.destroy(ConnectManager.session, vmRef);
                }
                catch (Exception ex1) {
                    log.ErrorFormat("删除WinCenter VM失败:{0}", ex1.Message);
                    throw ex1;
                }
                throw;
            }
        }