Ejemplo n.º 1
0
 /// <summary>
 /// Wait until task is finish.
 /// </summary>
 /// <param name="result"></param>
 /// <param name="vm"></param>
 /// <param name="timeout"></param>
 public static void WaitForTaskToFinish(this Result result, VMInfo vm, long timeout)
 {
     if (result != null && !result.ResponseInError && timeout > 0)
     {
         vm.Client.WaitForTaskToFinish(vm.Node, result.Response.data, 1000, timeout);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Sends a view model data to one or more clients.
 /// </summary>
 /// <param name="vmInfo">View model info.</param>
 /// <param name="args">Arguments containing information on clients to send to.</param>
 private void Send(VMInfo vmInfo, GroupSend args)
 {
     ResponseVMFilter.Invoke(vmInfo.Id, vmInfo.Instance, args.Data, filteredData =>
     {
         _vmResponse(MULTICAST + nameof(GroupSend), vmInfo.Id, JsonConvert.SerializeObject(args));
     });
 }
Ejemplo n.º 3
0
        public static VMInfo GetCachedVirtualMachineForPC(int itemId)
        {
            if (itemId == 0)
            {
                return(new VMInfo());
            }

            string key = "CachedVirtualMachine" + itemId;

            if (HttpContext.Current.Items[key] != null)
            {
                return((VMInfo)HttpContext.Current.Items[key]);
            }

            // load virtual machine
            VMInfo vm = ES.Services.VPSPC.GetVirtualMachineItem(itemId);

            // place to cache
            if (vm != null)
            {
                HttpContext.Current.Items[key] = vm;
            }

            vm.HostName = vm.HostName ?? String.Empty;

            return(vm);
        }
Ejemplo n.º 4
0
        private void VMDataFileHandling()
        {
            string filePath = Path.Combine(runningPath, "data.txt");

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            //Load ALL VMS
            LoadVMS();
            //Load ALL Running VMS
            LoadRunningVMS();
            //Load VM Info, Group

            foreach (KeyValuePair <string, string> item in dctVms)
            {
                VMInfo info = new VMInfo();
                info.Guid = item.Key;
                info.Name = item.Value;
                GetVMInfo(ref info);
                lstVMInfo.Add(info);
                string vmData = String.Format("{0}|{1}|{2} \r\n", info.Guid, info.Name, info.Group);

                File.AppendAllText(filePath, vmData);
            }
        }
Ejemplo n.º 5
0
        private VMInfo GetVMInfo(ref VMInfo info)
        {
            COMLIB cb  = new COMLIB();
            string str = cb.RunCmd2(Path.Combine(vbEXEPath, vbExe), String.Format("showvminfo {0}", info.Guid));

            if (String.IsNullOrEmpty(str))
            {
                MessageBox.Show("Error");
                return(null);
            }

            string[] strResults = str.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            for (int i = 3; i < strResults.Length; i++)
            {
                if (strResults[i].Contains("Groups"))
                {
                    string[] strvms = strResults[i].Split(':');
                    if (strvms.Length > 0)
                    {
                        string tmpGroups = strvms[1].Replace(" ", String.Empty);
                        tmpGroups  = tmpGroups.Replace("/", String.Empty);
                        info.Group = tmpGroups;
                        if (!lstGroup.Contains(tmpGroups))
                        {
                            lstGroup.Add(tmpGroups);
                        }
                        continue;
                    }
                }
            }

            return(info);
        }
Ejemplo n.º 6
0
        protected void btnCreate_Click(object sender, EventArgs e)
        {
            try
            {
                VMInfo selectedVM = VirtualMachinesForPCHelper.GetCachedVirtualMachineForPC(Convert.ToInt32(listOperatingSystems.SelectedValue.Trim()));

                ResultObject res = ES.Services.VPSPC.CreateVMFromVM(PanelSecurity.PackageId
                                                                    , selectedVM, txtVmName.Text.Trim());

                if (res.IsSuccess)
                {
                    // return to the list
                    Response.Redirect(EditUrl("SpaceID", PanelSecurity.PackageId.ToString(), ""));
                    return;
                }
                else
                {
                    // show error
                    messageBox.ShowMessage(res, "VPS_ERROR_CREATE", "VPS");
                }
            }
            catch (Exception ex)
            {
                messageBox.ShowErrorMessage("VPS_ERROR_CREATE", ex);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Determines if this machine is running inside of a known VM.
        /// </summary>
        /// <returns><c>true</c> if running in a VM; otherwise, <c>false</c>.</returns>
        public static bool IsVM()
        {
            var query = QueryAll(query: WIN32_COMPUTER_SYSTEM);
            var any   = query.Any(entry => VM_Information.Any(vm => vm.IsMatch(entry)));

            cached_vm = VM_Information.FirstOrDefault(vm => query.Any(vm.IsMatch));
            return(any);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Sends a view model data to one or more clients.
 /// </summary>
 /// <param name="vmInfo">View model info.</param>
 /// <param name="args">Arguments containing information on clients to send to.</param>
 private void Send(VMInfo vmInfo, GroupSend args)
 {
     ResponseVMFilter.Invoke(vmInfo, args, filteredData =>
     {
         VMResponse(MULTICAST + nameof(GroupSend), vmInfo.Id, JsonSerializer.Serialize(args));
         return(Task.CompletedTask);
     });
 }
Ejemplo n.º 9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            VMInfo vm = VirtualMachinesForPCHelper.GetCachedVirtualMachineForPC(PanelRequest.ItemID);

            if (vm != null && !String.IsNullOrWhiteSpace(vm.Name))
            {
                litServerName.Text = vm.Name;
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Info vms.
 /// </summary>
 /// <param name="vms"></param>
 /// <param name="outputType"></param>
 /// <returns></returns>
 public static string Info(this IReadOnlyList <VMInfo> vms, TableOutputType outputType)
 {
     return(vms.Count > 0 ?
            TableHelper.Create(VMInfo.GetTitlesInfo(),
                               vms.Select(a => a.GetRowInfo()),
                               outputType,
                               false) :
            "");
 }
Ejemplo n.º 11
0
        public static async Task RunOrchestrator(
            [OrchestrationTrigger] IDurableOrchestrationContext context)
        {
            VMInfo   input = context.GetInput <VMInfo>();
            EntityId id    = new EntityId("VM", input.VMId);

            await context.CallEntityAsync(id, input.Action, input.Hour);

            return;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Handles a request for a view model from a browser client.
        /// </summary>
        /// <param name="connectionId">Identifies the client connection.</param>
        /// <param name="vmId">Identifies the view model.</param>
        /// <param name="vmArg">Optional view model's initialization argument.</param>
        /// <returns>Group name, if the request is for a multicast view model associated with one.</returns>
        public async virtual Task <string> OnRequestVMAsync(string connectionId, string vmId, object vmArg = null)
        {
            BaseVM vmInstance = null;

            if (_activeVMs.ContainsKey(vmId))
            {
                vmInstance = _activeVMs[vmId].Instance;
            }
            else
            {
                // Create a new view model instance whose class name is matching the given VMId.
                vmInstance = CreateVM(vmId, vmArg);
                await vmInstance.OnCreatedAsync();
            }

            await RequestVMFilter.Invoke(vmId, vmInstance, vmArg, async data =>
            {
                var vmData = vmInstance.Serialize();

                // Send the view model data back to the browser client.
                await ResponseVMFilter.Invoke(vmId, vmInstance, vmData, filteredData => _vmResponse(connectionId, vmId, (string)filteredData));

                // Reset the changed property states.
                vmInstance.AcceptChangedProperties();

                // Add the view model instance to the controller.
                if (!_activeVMs.ContainsKey(vmId))
                {
                    var vmInfo = new VMInfo(id: vmId, instance: vmInstance, connectionId: connectionId);
                    vmInstance.RequestPushUpdates += VmInstance_RequestPushUpdates;
                    if (vmInstance is MulticastVM)
                    {
                        var multicastVM  = vmInstance as MulticastVM;
                        vmInfo.GroupName = multicastVM.GroupName;
                        multicastVM.RequestMulticastPushUpdates += VMInstance_RequestMulticastPushUpdates;
                        multicastVM.RequestSend += VMInstance_RequestSend;
                    }
                    _activeVMs.TryAdd(vmId, vmInfo);
                }
                else
                {
                    _activeVMs[vmId].ConnectionId = connectionId;
                }

                // If this request causes other view models to change, push those new values back to the client.
                foreach (var vmInfo in _activeVMs.Values)
                {
                    PushUpdates(vmInfo);
                }
            });

            return(_activeVMs[vmId].GroupName);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Push property changed updates on a view model back to the client.
        /// </summary>
        /// <param name="vmInfo">View model.</param>
        /// <param name="vmData">Serialized data to be pushed. If null, it's coming from the view model.</param>
        protected virtual void PushUpdates(VMInfo vmInfo, string vmData)
        {
            if (string.IsNullOrEmpty(vmData))
            {
                return;
            }

            ResponseVMFilter.Invoke(vmInfo.Id, vmInfo.Instance, vmData, filteredData =>
            {
                _vmResponse(vmInfo.ConnectionId, vmInfo.Id, (string)filteredData);
            });
        }
Ejemplo n.º 14
0
        public void RevertToSnapshot(string snapshotName, VMInfo vmInfo)
        {
            string vmPathName = GetVmPathName(vmInfo.storage, vmInfo.name);

            using (VMWareVirtualMachine vm = _host.Open(vmPathName))
            {
                using (VMWareSnapshot snapshot = vm.Snapshots.GetNamedSnapshot(snapshotName))
                {
                    snapshot.RevertToSnapshot();
                }
            }
        }
Ejemplo n.º 15
0
        private void BindConfiguration()
        {
            VMInfo vm = null;

            try
            {
                // load machine
                try
                {
                    vm = ES.Services.VPSPC.GetVirtualMachineItem(PanelRequest.ItemID);
                }
                catch (Exception ex)
                {
                    vm = null;
                }

                if (vm == null)
                {
                    messageBox.ShowErrorMessage("VPS_LOAD_VM_META_ITEM");
                    return;
                }

                // bind item
                litOperatingSystem.Text = vm.TemplateName;

                litCpu.Text       = String.Format(GetLocalizedString("CpuCores.Text"), vm.CPUCount);
                litRam.Text       = String.Format(GetLocalizedString("Ram.Text"), vm.Memory);
                litHdd.Text       = String.Format(GetLocalizedString("Hdd.Text"), vm.HddSize);
                litSnapshots.Text = vm.SnapshotsNumber.ToString();

                optionDvdInstalled.Value = vm.DvdDriver;
                optionBootFromCD.Value   = vm.BootFromCD;
                optionNumLock.Value      = vm.NumLockEnabled;

                optionStartShutdown.Value = vm.StartTurnOffAllowed;
                optionPauseResume.Value   = vm.PauseResumeAllowed;
                optionReset.Value         = vm.ResetAllowed;
                optionReboot.Value        = vm.RebootAllowed;
                optionReinstall.Value     = vm.ReinstallAllowed;

                optionExternalNetwork.Value = vm.ExternalNetworkEnabled;
                optionPrivateNetwork.Value  = vm.PrivateNetworkEnabled;

                // toggle buttons
                bool manageAllowed = VirtualMachinesForPCHelper.IsVirtualMachineManagementAllowed(PanelSecurity.PackageId);
                btnEdit.Visible = manageAllowed;
            }
            catch (Exception ex)
            {
                messageBox.ShowErrorMessage("VPS_LOAD_VM_META_ITEM", ex);
            }
        }
Ejemplo n.º 16
0
        public void CopyFileToHost(string filePath, string guestPath, VMInfo vmInfo)
        {
            string vmPathName = vmInfo.storage + " " + vmInfo.name + "/" + vmInfo.name + ".vmx";

            using (VMWareVirtualMachine vm = _host.Open(vmPathName))
            {
                vm.WaitForToolsInGuest();
                vm.LoginInGuest(vmInfo.account, vmInfo.pwd);

                vm.CopyFileFromGuestToHost(guestPath + @"\" + Path.GetFileName(filePath), filePath);
                vm.LogoutFromGuest();
            }
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="phase"></param>
 /// <param name="vm"></param>
 /// <param name="label"></param>
 /// <param name="keep"></param>
 /// <param name="snapName"></param>
 /// <param name="state"></param>
 public PhaseEventArgs(string phase,
                       VMInfo vm,
                       string label,
                       int keep,
                       string snapName,
                       bool state)
 {
     Phase    = phase;
     VM       = vm;
     Label    = label;
     SnapName = snapName;
     State    = state;
 }
 public void ConfigureCreatedVMNetworkAdapters(VMInfo vmInfo)
 {
     try
     {
         Log.WriteStart("'{0}' ConfigureCreatedVMNetworkAdapters", ProviderSettings.ProviderName);
         VirtualizationForPC.ConfigureCreatedVMNetworkAdapters(vmInfo);
         Log.WriteEnd("'{0}' ConfigureCreatedVMNetworkAdapters", ProviderSettings.ProviderName);
     }
     catch (Exception ex)
     {
         Log.WriteError(String.Format("'{0}' ConfigureCreatedVMNetworkAdapters", ProviderSettings.ProviderName), ex);
         throw;
     }
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Push property changed updates on a view model back to the client.
        /// </summary>
        /// <param name="vmInfo">View model.</param>
        /// <param name="vmData">Serialized data to be pushed. If null, it's coming from the view model.</param>
        protected virtual void PushUpdates(VMInfo vmInfo, string vmData)
        {
            if (string.IsNullOrEmpty(vmData))
            {
                return;
            }

            ResponseVMFilter.Invoke(vmInfo, vmData, filteredData =>
            {
                var vmDataToSend = filteredData is GroupSend ? (filteredData as GroupSend).Data : (string)filteredData;
                VMResponse(vmInfo.ConnectionId, vmInfo.Id, vmDataToSend);
                return(Task.CompletedTask);
            });
        }
 public VMInfo MoveVM(VMInfo vmForMove)
 {
     try
     {
         Log.WriteStart("'{0}' MoveVM", ProviderSettings.ProviderName);
         VMInfo ret = VirtualizationForPC.MoveVM(vmForMove);
         Log.WriteEnd("'{0}' MoveVM", ProviderSettings.ProviderName);
         return(ret);
     }
     catch (Exception ex)
     {
         Log.WriteError(String.Format("'{0}' MoveVM", ProviderSettings.ProviderName), ex);
         throw;
     }
 }
 public VMInfo GetVirtualMachine(string vmId)
 {
     try
     {
         Log.WriteStart("'{0}' GetVirtualMachine", ProviderSettings.ProviderName);
         VMInfo result = VirtualizationForPC.GetVirtualMachine(vmId);
         Log.WriteEnd("'{0}' GetVirtualMachine", ProviderSettings.ProviderName);
         return(result);
     }
     catch (Exception ex)
     {
         Log.WriteError(String.Format("'{0}' GetVirtualMachine", ProviderSettings.ProviderName), ex);
         throw;
     }
 }
Ejemplo n.º 22
0
        bool CheckAlocBlock(Block block, out Dictionary <Local, VMInfo> vmDictonary)
        {
            vmDictonary = new Dictionary <Local, VMInfo>();
            var outLocals = new List <VMInfo>();
            var instr     = block.Instructions;

            for (int i = 3; i < instr.Count; i++)
            {
                if (!Utilis.IsLoc(instr[i]))
                {
                    continue;
                }
                var local = instr[i].Instruction.GetLocal(blocks.Locals);
                if (!Utilis.IsPtrElementType(local.Type, ElementType.U1))
                {
                    continue;
                }
                if (!instr[i].IsStloc())
                {
                    continue;
                }
                if (vmDictonary.ContainsKey(local))
                {
                    outLocals.Remove(vmDictonary[local]);
                    continue;
                }
                if (instr[i - 1].OpCode != OpCodes.Localloc)
                {
                    continue;
                }
                if (instr[i - 2].OpCode != OpCodes.Conv_U)
                {
                    continue;
                }
                if (!instr[i - 3].IsLdcI4())
                {
                    continue;
                }
                var size   = instr[i - 3].GetLdcI4Value();
                var vmInfo = new VMInfo()
                {
                    Size = size, Local = local, Instruction = instr[i], Info = NewEmptyElementTypeArray(size)
                };
                vmDictonary[local] = vmInfo;
                outLocals.Add(vmInfo);
            }
            return(outLocals.Count != 0);
        }
Ejemplo n.º 23
0
        public void CopyFileToGuest(string filePath, string guestPath, VMInfo vmInfo)
        {
            string vmPathName = vmInfo.storage + " " + vmInfo.name + "/" + vmInfo.name + ".vmx";

            using (VMWareVirtualMachine vm = _host.Open(vmPathName))
            {
                vm.WaitForToolsInGuest();
                vm.LoginInGuest(vmInfo.account, vmInfo.pwd);
                string fileName = Path.GetFileName(filePath);

                if (fileName == "file_toucher.pl" || fileName == "smv.pl")
                    vm.RunProgramInGuest(@"C:\windows\system32\attrib.exe", "-r " + guestPath + @"\" + Path.GetFileName(filePath));

                vm.CopyFileFromHostToGuest(filePath, guestPath + @"\" + Path.GetFileName(filePath));
                vm.LogoutFromGuest();
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Disposes a view model.
        /// </summary>
        /// <param name="vmInfo">View model info.</param>
        protected void DisposeViewModel(VMInfo vmInfo)
        {
            vmInfo.Instance.RequestPushUpdates -= VmInstance_RequestPushUpdates;

            if (vmInfo.Instance is IMulticast)
            {
                var multicastVM = vmInfo.Instance as IMulticast;
                multicastVM.RequestMulticastPushUpdates -= VMInstance_RequestMulticastPushUpdates;

                // If the multicast view model has a group, call the hub to disassociate the connection Id with that group.
                if (!string.IsNullOrEmpty(multicastVM.GroupName))
                {
                    RemoveConnectionFromGroup(vmInfo.ConnectionId, vmInfo.Id, multicastVM.GroupName);
                }
            }
            vmInfo.Instance.Dispose();
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Disposes a view model.
        /// </summary>
        /// <param name="vmInfo">View model info.</param>
        protected void DisposeViewModel(VMInfo vmInfo)
        {
            vmInfo.Instance.RequestPushUpdates -= VmInstance_RequestPushUpdates;

            if (typeof(MulticastVM).GetTypeInfo().IsAssignableFrom(vmInfo.Instance.GetType()))
            {
                var multicastVM = vmInfo.Instance as MulticastVM;
                multicastVM.RequestMulticastPushUpdates -= VMInstance_RequestMulticastPushUpdates;
                multicastVM.RequestSend -= VMInstance_RequestSend;

                // If the multicast view model has a group, call the hub to disassociate the connection Id with that group.
                if (!string.IsNullOrEmpty(vmInfo.GroupName))
                {
                    RemoveConnectionFromGroup(vmInfo.ConnectionId, vmInfo.Id, vmInfo.GroupName);
                }
            }
            vmInfo.Instance.Dispose();
        }
Ejemplo n.º 26
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="phase"></param>
 /// <param name="vm"></param>
 /// <param name="label"></param>
 /// <param name="keep"></param>
 /// <param name="snapName"></param>
 /// <param name="vmState"></param>
 /// <param name="duration"></param>
 /// <param name="status"></param>
 public PhaseEventArgs(HookPhase phase,
                       VMInfo vm,
                       string label,
                       int keep,
                       string snapName,
                       bool vmState,
                       double duration,
                       bool status)
 {
     Phase    = phase;
     VM       = vm;
     Label    = label;
     Keep     = keep;
     SnapName = snapName;
     VMState  = vmState;
     Duration = duration;
     Status   = status;
 }
Ejemplo n.º 27
0
        private bool LoadVMSFromFile(bool refresh)
        {
            bool isDone = true;

            try
            {
                string filePath = Path.Combine(runningPath, "data.txt");
                if (refresh)
                {
                    VMDataFileHandling();
                }
                else
                {
                    if (!File.Exists(filePath))
                    {
                        VMDataFileHandling();
                        isDone = true;
                    }
                    else
                    {
                        string[] vmData = File.ReadAllLines(filePath);
                        foreach (string s in vmData)
                        {
                            string[] tmp  = s.Split('|');
                            VMInfo   info = new VMInfo();
                            info.Guid  = tmp[0];
                            info.Name  = tmp[1];
                            info.Group = tmp[2];
                            lstVMInfo.Add(info);
                        }
                        isDone = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                isDone = false;
            }


            return(isDone);
        }
Ejemplo n.º 28
0
        public static string GetDomainName(this VMInfo vm)
        {
            var computerName = vm.ComputerName;
            //
            var result = String.Empty;

            //
            if (String.IsNullOrEmpty(computerName) == false)
            {
                //
                var indexOf = computerName.IndexOf(".");
                //
                if (indexOf > -1)
                {
                    result = computerName.Substring(indexOf + 1);
                }
            }
            //
            return(result);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Push property changed updates on a view model back to the client.
        /// </summary>
        /// <param name="vmInfo">View model.</param>
        protected virtual void PushUpdates(VMInfo vmInfo)
        {
            var vmInstance = vmInfo.Instance;

            if (vmInstance is MulticastVM)
            {
                vmInstance.PushUpdates();
            }
            else
            {
                lock (vmInstance)
                {
                    var changedProperties = vmInstance.AcceptChangedProperties();
                    if (changedProperties != null && changedProperties.Count > 0)
                    {
                        PushUpdates(vmInfo, vmInstance.Serialize(changedProperties));
                    }
                }
            }
        }
        public VMInfo CreateVMFromVM(string sourceName, VMInfo vmTemplate, Guid taskGuid)
        {
            VMInfo result = vmTemplate;

            try
            {
                Log.WriteStart("'{0}' CreateVMFromVM", ProviderSettings.ProviderName);
                result = VirtualizationForPC.CreateVMFromVM(sourceName, vmTemplate, taskGuid);
                Log.WriteEnd("'{0}' CreateVMFromVM", ProviderSettings.ProviderName);
                return(result);
            }
            catch (System.TimeoutException ex)
            {
                return(result);
            }
            catch (Exception ex)
            {
                Log.WriteError(String.Format("'{0}' CreateVMFromVM", ProviderSettings.ProviderName), ex);
                throw;
            }
        }
Ejemplo n.º 31
0
        protected void Page_Load(object sender, EventArgs e)
        {
            resolution.Text = Request["Resolution"];

            // load server info
            VMInfo vm = ES.Services.VPSPC.GetCachedVirtualMachine(PanelRequest.ItemID);

            litServerName.Text = vm.Name + " - ";
            username.Text      = "Administrator";
            // TODO: Review VMInfo class fields and underlying data for correctness
            password.Text = vm.AdminPassword;

            // load external network parameters
            NetworkAdapterDetails nic = ES.Services.VPSPC.GetExternalNetworkAdapterDetails(PanelRequest.ItemID);

            if (nic.IPAddresses.Length > 0)
            {
                NetworkAdapterIPAddress ip = nic.IPAddresses[0];
                serverName.Text = !String.IsNullOrEmpty(ip.NATAddress) ? ip.NATAddress : ip.IPAddress;
            }
        }
Ejemplo n.º 32
0
        private void BindTask(VMInfo vm)
        {
            task = ES.Services.Tasks.GetTaskWithLogRecords(vm.CurrentTaskId, DateTime.MinValue);
            if (task == null)
            {
                return;
            }

            // bind task details
            litTaskName.Text = String.Format("{0} &quot;{1}&quot;",
                                             GetAuditLogTaskName(task.Source, task.TaskName),
                                             task.ItemName);

            // time
            litStarted.Text = task.StartDate.ToString("T");
            TimeSpan d = (TimeSpan)(DateTime.Now - task.StartDate);

            litElapsed.Text = new TimeSpan(d.Hours, d.Minutes, d.Seconds).ToString();

            // bind records
            repRecords.DataSource = task.GetLogs();
            repRecords.DataBind();
        }
        private void BindFormDetails()
        {
            // load VM item
            VMInfo vm = VirtualMachinesForPCHelper.GetCachedVirtualMachineForPC(PanelRequest.ItemID);

            if (!String.IsNullOrEmpty(vm.CurrentTaskId))
            {
                messageBox.ShowWarningMessage("VPS_PROVISIONING_PROCESS");
                btnDelete.Enabled = false;
                return;
            }

            AdminOptionsPanel.Visible = (PanelSecurity.EffectiveUser.Role == WebsitePanel.EnterpriseServer.UserRole.Administrator);

            //// load export settings
            //if (PanelSecurity.EffectiveUser.Role == WebsitePanel.EnterpriseServer.UserRole.Administrator)
            //{
            //    txtExportPath.Text = ES.Services.VPSPC.GetDefaultExportPath(PanelRequest.ItemID);
            //}
            //else
            //{
            //    AdminOptionsPanel.Visible = false;
            //}
        }
 /// <remarks/>
 public System.IAsyncResult BeginUpdateVirtualMachine(VMInfo vm, System.AsyncCallback callback, object asyncState) {
     return this.BeginInvoke("UpdateVirtualMachine", new object[] {
                 vm}, callback, asyncState);
 }
 /// <remarks/>
 public void CreateVMFromVMAsync(string sourceName, VMInfo vmTemplate, System.Guid taskGuid) {
     this.CreateVMFromVMAsync(sourceName, vmTemplate, taskGuid, null);
 }
 /// <remarks/>
 public void MoveVMAsync(VMInfo vmForMove) {
     this.MoveVMAsync(vmForMove, null);
 }
 /// <remarks/>
 public void MoveVMAsync(VMInfo vmForMove, object userState) {
     if ((this.MoveVMOperationCompleted == null)) {
         this.MoveVMOperationCompleted = new System.Threading.SendOrPostCallback(this.OnMoveVMOperationCompleted);
     }
     this.InvokeAsync("MoveVM", new object[] {
                 vmForMove}, this.MoveVMOperationCompleted, userState);
 }
 public void ConfigureCreatedVMNetworkAdapters(VMInfo vmInfo) {
     this.Invoke("ConfigureCreatedVMNetworkAdapters", new object[] {
                 vmInfo});
 }
 public VMInfo MoveVM(VMInfo vmForMove) {
     object[] results = this.Invoke("MoveVM", new object[] {
                 vmForMove});
     return ((VMInfo)(results[0]));
 }
 public VMInfo UpdateVirtualMachine(VMInfo vm) {
     object[] results = this.Invoke("UpdateVirtualMachine", new object[] {
                 vm});
     return ((VMInfo)(results[0]));
 }
 /// <remarks/>
 public void ConfigureCreatedVMNetworkAdaptersAsync(VMInfo vmInfo, object userState) {
     if ((this.ConfigureCreatedVMNetworkAdaptersOperationCompleted == null)) {
         this.ConfigureCreatedVMNetworkAdaptersOperationCompleted = new System.Threading.SendOrPostCallback(this.OnConfigureCreatedVMNetworkAdaptersOperationCompleted);
     }
     this.InvokeAsync("ConfigureCreatedVMNetworkAdapters", new object[] {
                 vmInfo}, this.ConfigureCreatedVMNetworkAdaptersOperationCompleted, userState);
 }
Ejemplo n.º 42
0
        public VMWareVirtualMachine.Process RunProgram(string guestPath, VMInfo vmInfo)
        {
            string vmPathName = vmInfo.storage + " " + vmInfo.name + "/" + vmInfo.name + ".vmx";

            using (VMWareVirtualMachine vm = _host.Open(vmPathName))
            {
                vm.WaitForToolsInGuest();
                vm.LoginInGuest(vmInfo.account, vmInfo.pwd);

                VMWareVirtualMachine.Process proc = vm.RunProgramInGuest(guestPath, "", 10);
                vm.LogoutFromGuest();
                return proc;
            }
        }
 public VMInfo CreateVMFromVM(string sourceName, VMInfo vmTemplate, System.Guid taskGuid) {
     object[] results = this.Invoke("CreateVMFromVM", new object[] {
                 sourceName,
                 vmTemplate,
                 taskGuid});
     return ((VMInfo)(results[0]));
 }
 /// <remarks/>
 public System.IAsyncResult BeginCreateVMFromVM(string sourceName, VMInfo vmTemplate, System.Guid taskGuid, System.AsyncCallback callback, object asyncState) {
     return this.BeginInvoke("CreateVMFromVM", new object[] {
                 sourceName,
                 vmTemplate,
                 taskGuid}, callback, asyncState);
 }
 /// <remarks/>
 public void ConfigureCreatedVMNetworkAdaptersAsync(VMInfo vmInfo) {
     this.ConfigureCreatedVMNetworkAdaptersAsync(vmInfo, null);
 }
 /// <remarks/>
 public System.IAsyncResult BeginMoveVM(VMInfo vmForMove, System.AsyncCallback callback, object asyncState) {
     return this.BeginInvoke("MoveVM", new object[] {
                 vmForMove}, callback, asyncState);
 }
 /// <remarks/>
 public void UpdateVirtualMachineAsync(VMInfo vm, object userState) {
     if ((this.UpdateVirtualMachineOperationCompleted == null)) {
         this.UpdateVirtualMachineOperationCompleted = new System.Threading.SendOrPostCallback(this.OnUpdateVirtualMachineOperationCompleted);
     }
     this.InvokeAsync("UpdateVirtualMachine", new object[] {
                 vm}, this.UpdateVirtualMachineOperationCompleted, userState);
 }
 /// <remarks/>
 public void CreateVirtualMachineAsync(VMInfo vm) {
     this.CreateVirtualMachineAsync(vm, null);
 }
        private void ComposeVMData()
        {
            m_VMs = new List<VMInfo>();
            var VMs = new List<XenAPI.VM>(Connection.Cache.VMs);
            VMs.Sort();
            foreach (XenAPI.VM vm in VMs)
            {
                string OSinfo = vm.GetOSName();
                string srInfo = "";
                string MacInfo = "";
                string running_on = Messages.HYPHEN;

                if (Cancelling)
                    throw new CancelledException();

                if (!vm.is_a_real_vm)
                {
                    PercentComplete = Convert.ToInt32((++itemIndex) * baseIndex / itemCount);
                    continue;
                }

                ComparableList<ComparableAddress> addresses = new ComparableList<ComparableAddress>();
                if (vm.guest_metrics != null && !string.IsNullOrEmpty(vm.guest_metrics.opaque_ref) && !(vm.guest_metrics.opaque_ref.ToLower().Contains("null")))
                {
                    VM_guest_metrics metrics = vm.Connection.Resolve(vm.guest_metrics);

                    List<VIF> vifs = vm.Connection.ResolveAll(vm.VIFs);
                    foreach (VIF vif in vifs)
                    {
                        MacInfo += vif.MAC + " ";
                        foreach (var network in metrics.networks.Where(n => n.Key.StartsWith(String.Format("{0}/ip", vif.device))))
                        {
                            ComparableAddress ipAddress;
                            if (!ComparableAddress.TryParse(network.Value, false, true, out ipAddress))
                                continue;

                            addresses.Add(ipAddress);
                        }
                    }
                }
                if (MacInfo.Length == 0)
                    MacInfo = Messages.HYPHEN;

                foreach (XenRef<VBD> vbdRef in vm.VBDs)
                {
                    var vbd = vm.Connection.Resolve(vbdRef);
                    if (vbd != null && !vbd.IsCDROM && !vbd.IsFloppyDrive && vbd.bootable)
                    {
                        VDI vdi = vm.Connection.Resolve(vbd.VDI);
                        srInfo += vdi.name_label + ":" + vdi.SizeText + ";";
                    }
                }
                if (srInfo.Length == 0)
                    srInfo = Messages.HYPHEN;

                if (vm.resident_on != null && !string.IsNullOrEmpty(vm.resident_on.opaque_ref) && !(vm.resident_on.opaque_ref.ToLower().Contains("null")))
                {
                    running_on = vm.Connection.Resolve(vm.resident_on).Name;
                }

                string default_template_name = Messages.HYPHEN;
                if(vm.other_config.ContainsKey("base_template_name"))
                    default_template_name = vm.other_config["base_template_name"];

                VMInfo buf = new VMInfo(vm.Name, vm.uuid, PropertyAccessorHelper.vmCpuUsageStringByMetric(vm, MetricUpdater),
                    PropertyAccessorHelper.vmMemoryUsagePercentageStringByMetric(vm, MetricUpdater), srInfo, Convert.ToString(vm.VIFs.Count),
                    Convert.ToString(addresses), MacInfo, OSinfo, Convert.ToString(vm.power_state),
                    Convert.ToString(vm.RunningTime), running_on, default_template_name, vm.Description);

                m_VMs.Add(buf);

                PercentComplete = Convert.ToInt32((++itemIndex) * baseIndex / itemCount);
            }
        }
Ejemplo n.º 50
0
        public void TakeSnapshot(string snapshotName, VMInfo vmInfo)
        {
            string vmPathName = GetVmPathName(vmInfo.storage, vmInfo.name);

            using (VMWareVirtualMachine vm = _host.Open(vmPathName))
            {
                const int VIX_SNAPSHOT_INCLUDE_MEMORY = 0x0002;

                using (VMWareSnapshot snapshot =
                    vm.Snapshots.CreateSnapshot(snapshotName, "", VIX_SNAPSHOT_INCLUDE_MEMORY, 300))
                {
                }
            }
        }
 /// <remarks/>
 public void CreateVMFromVMAsync(string sourceName, VMInfo vmTemplate, System.Guid taskGuid, object userState) {
     if ((this.CreateVMFromVMOperationCompleted == null)) {
         this.CreateVMFromVMOperationCompleted = new System.Threading.SendOrPostCallback(this.OnCreateVMFromVMOperationCompleted);
     }
     this.InvokeAsync("CreateVMFromVM", new object[] {
                 sourceName,
                 vmTemplate,
                 taskGuid}, this.CreateVMFromVMOperationCompleted, userState);
 }
 /// <remarks/>
 public void UpdateVirtualMachineAsync(VMInfo vm) {
     this.UpdateVirtualMachineAsync(vm, null);
 }
 /// <remarks/>
 public System.IAsyncResult BeginConfigureCreatedVMNetworkAdapters(VMInfo vmInfo, System.AsyncCallback callback, object asyncState) {
     return this.BeginInvoke("ConfigureCreatedVMNetworkAdapters", new object[] {
                 vmInfo}, callback, asyncState);
 }