public async Task <TerodoViewStatusType> DestroyAsync(TerodoViewComputeResourceVolumeType paramVolume) { Resource = $"{OrgResource}/computeresources/{instanceLocalCompureresourceObject.Id}/computeresourcevolumes/{paramVolume.Id}.json"; return(await DeleteOperationAsync <TerodoViewStatusType>()); }
public async Task ComputeCesourceCustomizationWMIAsync() { long _c_volume_actual_size = 0; long _c_volume_actual_free = 0; string _cdrom_drive_letter = ""; SelectQuery VolumeQuery = new SelectQuery("SELECT Size, FreeSpace FROM Win32_LogicalDisk WHERE DeviceID = 'C:'"); SelectQuery CdromQuery = new SelectQuery("SELECT Drive FROM Win32_CDROMDrive"); foreach (var item in (await GetManagementObjectSearcherAsync(CdromQuery)).Get()) { try { _cdrom_drive_letter = item["Drive"].ToString(); } catch (Exception) { } } foreach (var item in (await GetManagementObjectSearcherAsync(VolumeQuery)).Get()) { try { _c_volume_actual_size = Convert.ToInt64(item["Size"].ToString()); _c_volume_actual_free = Convert.ToInt64(item["FreeSpace"].ToString()); } catch (Exception) { throw new ArgumentException(String.Format("Error collecting C: volume space information for {0}", _local_computeresource_context.ComputeResource.Hostname)); } } TerodoViewComputeResourceVolumeType _c_volume_object = _local_computeresource_context.ComputeResource.Volumes.FirstOrDefault(x => x.Mountpoint == "C"); long _c_volume_to_add = 0; if (_c_volume_object != null) { _c_volume_to_add = (long)(_c_volume_object.Size * 1024 * 1024 * 1024) - _c_volume_actual_size; } else { throw new ArgumentException("Cannot find C: drive in volume list for partition mapping"); } List <String> _used_drive_letters = _local_computeresource_context.ComputeResource.Volumes.Select(x => x.Mountpoint.Substring(0, 1)).ToList(); List <String> _systemdriveletters = new List <String>(); _systemdriveletters.AddRange("DEFGHIJKLMNOPQRSTUVWXYZ".Select(d => d.ToString())); List <String> _availabledriveletters = _systemdriveletters.Except(_used_drive_letters).ToList <String>(); List <String> _diskpart_struct = new List <string>(); //convert number MB from bytes _c_volume_to_add = _c_volume_to_add / 1024 / 1024; if (_c_volume_to_add > 0) { _diskpart_struct.Add("select volume c"); _diskpart_struct.Add(String.Format("extend size={0} disk=0 noerr", _c_volume_to_add)); _diskpart_struct.Add(""); } //change cdrom drive letter if (_cdrom_drive_letter != "") { _diskpart_struct.Add(String.Format("select volume {0}", _cdrom_drive_letter.Substring(0, 1))); _diskpart_struct.Add(String.Format("assign letter={0} noerr", _availabledriveletters.Last())); _diskpart_struct.Add(""); } foreach (int _disk_index in _local_computeresource_context.ComputeResource.Volumes.Select(x => x.DiskIndex).Distinct()) { if (_disk_index != 0) { _diskpart_struct.Add(String.Format("select disk {0}", _disk_index)); _diskpart_struct.Add("clean"); _diskpart_struct.Add("ATTRIBUTES DISK CLEAR READONLY noerr"); _diskpart_struct.Add("ONLINE DISK noerr"); } int _vol_index = 0; if (_disk_index == 0) { _vol_index = 2; } else { _vol_index = 1; } foreach (TerodoViewComputeResourceVolumeType _volume in _local_computeresource_context.ComputeResource.Volumes.ToList().Where(x => x.DiskIndex == _disk_index && !x.Mountpoint.Contains("C")).OrderBy(x => x.Mountpoint)) { string _driveletter = _volume.Mountpoint.Substring(0, 1); _diskpart_struct.Add(String.Format("select disk {0}", _disk_index)); _diskpart_struct.Add(String.Format("create partition primary size={0} noerr", _volume.Size * 1024)); _diskpart_struct.Add("format fs=ntfs quick"); _diskpart_struct.Add(String.Format("assign letter={0} noerr", _driveletter)); _diskpart_struct.Add(""); _vol_index++; } } string[] diskpart_bat_content = new String[] { @"C:\Windows\System32\diskpart.exe /s C:\diskpart.txt > C:\diskpart.log" }; string _local_location = @"C:\"; string _remote_location = _local_location.Replace(':', '$'); string _diskpart_remote_commands = @"\\" + Path.Combine(await _local_computeresource_context.GetContactibleIPAsync(true), _remote_location, "diskpart.txt"); string _diskpart_remote_bat = @"\\" + Path.Combine(await _local_computeresource_context.GetContactibleIPAsync(true), _remote_location, "diskpart.bat"); await CopyStringArrayToRemoteFileAsync(_diskpart_struct.ToArray(), _diskpart_remote_commands); await CopyStringArrayToRemoteFileAsync(diskpart_bat_content, _diskpart_remote_bat); await RunCommandAsync(_local_location, @"C:\diskpart.bat"); //if (_local_computeresource_context.ComputeCesource.interfaces.Where(x => x.index != 0).Count() > 0) //{ // SetInterfaceAddressesWMI(); //} }
public async Task <TerodoViewComputeResourceVolumeType> UpdateAsync(TerodoViewComputeResourceVolumeType paramVolume) { Resource = $"{OrgResource}/computeresources/{instanceLocalCompureresourceObject.Id}/computeresourcevolumes/{paramVolume.Id}.json"; return(await PutOperationAsync <TerodoViewComputeResourceVolumeType>(ExceptionFactory.CheckObjectIsNull(paramVolume))); }