예제 #1
0
        protected override void ProcessRecord()
        {
            Func <DataVirtualHardDisk, bool> func = null;
            PersistentVM instance  = base.VM.GetInstance();
            int?         nullable1 = this.Lun;

            if (nullable1.HasValue)
            {
                Collection <DataVirtualHardDisk> dataVirtualHardDisks = instance.DataVirtualHardDisks;
                if (func == null)
                {
                    func = (DataVirtualHardDisk dd) => {
                        int lun      = dd.Lun;
                        int?nullable = this.Lun;
                        if (lun != nullable.GetValueOrDefault())
                        {
                            return(false);
                        }
                        else
                        {
                            return(nullable.HasValue);
                        }
                    }
                    ;
                }
                DataVirtualHardDisk dataVirtualHardDisk = dataVirtualHardDisks.Where <DataVirtualHardDisk>(func).SingleOrDefault <DataVirtualHardDisk>();
                base.WriteObject(dataVirtualHardDisk, true);
                return;
            }
            else
            {
                base.WriteObject(instance.DataVirtualHardDisks, true);
                return;
            }
        }
예제 #2
0
        private static bool CheckDataDisk(DataVirtualHardDisk disk, string expLabel, int expSize, int expLun, HostCaching hc)
        {
            Console.WriteLine("DataDisk - Name:{0}, Label:{1}, Size:{2}, LUN:{3}, HostCaching: {4}",
                              disk.DiskName, disk.DiskLabel, disk.LogicalDiskSizeInGB, disk.Lun, disk.HostCaching);

            try
            {
                Assert.AreEqual(expLabel, disk.DiskLabel);
                Assert.AreEqual(expSize, disk.LogicalDiskSizeInGB);
                Assert.AreEqual(expLun, disk.Lun);
                if (disk.HostCaching == null && hc == HostCaching.None || disk.HostCaching == hc.ToString())
                {
                    Console.WriteLine("DataDisk found: {0}", disk.DiskLabel);
                }
                else
                {
                    Assert.Fail("HostCaching is not matched!");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                if (e is AssertFailedException)
                {
                    return(false);
                }
                else
                {
                    throw;
                }
            }
            return(true);
        }
예제 #3
0
        protected override void ProcessRecord()
        {
            Func <DataVirtualHardDisk, bool> func = null;

            try
            {
                base.ProcessRecord();
                Collection <DataVirtualHardDisk> dataDisks            = this.GetDataDisks();
                Collection <DataVirtualHardDisk> dataVirtualHardDisks = dataDisks;
                if (func == null)
                {
                    func = (DataVirtualHardDisk disk) => disk.Lun == this.LUN;
                }
                DataVirtualHardDisk dataVirtualHardDisk = dataVirtualHardDisks.Where <DataVirtualHardDisk>(func).SingleOrDefault <DataVirtualHardDisk>();
                if (dataVirtualHardDisk == null)
                {
                    object[] lUN = new object[1];
                    lUN[0] = this.LUN;
                    base.ThrowTerminatingError(new ErrorRecord(new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "A data disk is not currently assigned to LUN #{0} in the configuration of this VM.", lUN)), string.Empty, ErrorCategory.InvalidData, null));
                }
                dataDisks.Remove(dataVirtualHardDisk);
                base.WriteObject(base.VM, true);
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                base.WriteError(new ErrorRecord(exception, string.Empty, ErrorCategory.CloseError, null));
            }
        }
 public static void AddDataDisk(this IServiceManagement proxy,
                                string subscriptionId,
                                string serviceName,
                                string deploymentName,
                                string roleName,
                                DataVirtualHardDisk dataDisk)
 {
     proxy.EndAddDataDisk(proxy.BeginAddDataDisk(
                              subscriptionId,
                              serviceName,
                              deploymentName,
                              roleName,
                              dataDisk,
                              null,
                              null));
 }
 public static void AddDataDisk(this IServiceManagement proxy,
     string subscriptionId,
     string serviceName,
     string deploymentName,
     string roleName,
     DataVirtualHardDisk dataDisk)
 {
     proxy.EndAddDataDisk(proxy.BeginAddDataDisk(
         subscriptionId,
         serviceName,
         deploymentName,
         roleName,
         dataDisk,
         null,
         null));
 }
 public static void UpdateDataDisk(this IServiceManagement proxy,
                                   string subscriptionId,
                                   string serviceName,
                                   string deploymentName,
                                   string roleName,
                                   int lun,
                                   DataVirtualHardDisk dataDisk)
 {
     proxy.EndUpdateDataDisk(
         proxy.BeginUpdateDataDisk(subscriptionId,
                                   serviceName,
                                   deploymentName,
                                   roleName,
                                   lun.ToString(),
                                   dataDisk,
                                   null,
                                   null));
 }
        internal void ExecuteCommand()
        {
            var dataDisks = GetDataDisks();
            var dataDisk  = dataDisks.SingleOrDefault(disk => disk.Lun == LUN);

            if (dataDisk != null)
            {
                ThrowTerminatingError(
                    new ErrorRecord(
                        new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, Resources.DataDiskAlreadySpecifiedForVM, this.LUN)),
                        string.Empty,
                        ErrorCategory.InvalidData,
                        null));
            }

            dataDisk = new DataVirtualHardDisk {
                HostCaching = HostCaching, Lun = LUN
            };

            switch (ParameterSetName)
            {
            case "CreateNew":
                dataDisk.DiskLabel           = DiskLabel;
                dataDisk.LogicalDiskSizeInGB = DiskSizeInGB;
                dataDisk.MediaLink           = string.IsNullOrEmpty(MediaLocation) ? null : new Uri(MediaLocation);
                break;

            case "Import":
                dataDisk.DiskName = DiskName;
                break;

            case "ImportFrom":
                dataDisk.DiskName        = DiskName;
                dataDisk.SourceMediaLink = string.IsNullOrEmpty(MediaLocation) ? null : new Uri(MediaLocation);
                break;
            }

            dataDisks.Add(dataDisk);

            WriteObject(VM, true);
        }
예제 #8
0
        internal void ExecuteCommand()
        {
            var dataDisks = GetDataDisks();
            var dataDisk  = dataDisks.SingleOrDefault(disk => disk.Lun == LUN);

            if (dataDisk != null)
            {
                ThrowTerminatingError(
                    new ErrorRecord(
                        new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "A data disk has already been assigned to LUN #{0} for this VM. Specify a different LUN or use Set-DataDisk to change the configuration settings of the existing disk.", this.LUN)),
                        string.Empty,
                        ErrorCategory.InvalidData,
                        null));
            }

            dataDisk = new DataVirtualHardDisk {
                HostCaching = HostCaching, Lun = LUN
            };

            switch (ParameterSetName)
            {
            case "CreateNew":
                dataDisk.DiskLabel           = DiskLabel;
                dataDisk.LogicalDiskSizeInGB = DiskSizeInGB;
                dataDisk.MediaLink           = string.IsNullOrEmpty(MediaLocation) ? null : new Uri(MediaLocation);
                break;

            case "Import":
                dataDisk.DiskName = DiskName;
                break;

            case "ImportFrom":
                dataDisk.DiskName        = DiskName;
                dataDisk.SourceMediaLink = string.IsNullOrEmpty(MediaLocation) ? null : new Uri(MediaLocation);
                break;
            }

            dataDisks.Add(dataDisk);

            WriteObject(VM, true);
        }
예제 #9
0
        private static bool CheckDataDisk(DataVirtualHardDisk disk, string expLabel, int expSize, int expLun, HostCaching hc)
        {
            Console.WriteLine("DataDisk - Name:{0}, Label:{1}, Size:{2}, LUN:{3}, HostCaching: {4}",
                disk.DiskName, disk.DiskLabel, disk.LogicalDiskSizeInGB, disk.Lun, disk.HostCaching);

            try
            {
                Assert.AreEqual(expLabel, disk.DiskLabel);
                Assert.AreEqual(expSize, disk.LogicalDiskSizeInGB);
                Assert.AreEqual(expLun, disk.Lun);
                if (disk.HostCaching == null && hc == HostCaching.None || disk.HostCaching == hc.ToString())
                {
                    Console.WriteLine("DataDisk found: {0}", disk.DiskLabel);
                }
                else
                {
                    Assert.Fail("HostCaching is not matched!");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                if (e is AssertFailedException)
                {
                    return false;
                }
                else
                {
                    throw;
                }
            }
            return true;
        }
예제 #10
0
        internal void ExecuteCommand()
        {
            var dataDisks = GetDataDisks();
            var dataDisk = dataDisks.SingleOrDefault(disk => disk.Lun == LUN);

            if (dataDisk != null)
            {
                ThrowTerminatingError(
                    new ErrorRecord(
                            new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, Resources.DataDiskAlreadySpecifiedForVM, this.LUN)),
                            string.Empty,
                            ErrorCategory.InvalidData,
                            null));
            }

            dataDisk = new DataVirtualHardDisk { HostCaching = HostCaching, Lun = LUN };

            switch (ParameterSetName)
            {
                case "CreateNew":
                    dataDisk.DiskLabel = DiskLabel;
                    dataDisk.LogicalDiskSizeInGB = DiskSizeInGB;
                    dataDisk.MediaLink = string.IsNullOrEmpty(MediaLocation) ? null : new Uri(MediaLocation);
                    break;
                case "Import":
                    dataDisk.DiskName = DiskName;
                    break;
                case "ImportFrom":
                    dataDisk.DiskName = DiskName;
                    dataDisk.SourceMediaLink = string.IsNullOrEmpty(MediaLocation) ? null : new Uri(MediaLocation);
                    break;
            }

            dataDisks.Add(dataDisk);

            WriteObject(VM, true);
        }
예제 #11
0
		protected override void ProcessRecord()
		{
			Uri uri;
			Uri uri1;
			Func<DataVirtualHardDisk, bool> func = null;
			try
			{
				this.ValidateParameters();
				base.ProcessRecord();
				Collection<DataVirtualHardDisk> dataDisks = this.GetDataDisks();
				Collection<DataVirtualHardDisk> dataVirtualHardDisks = dataDisks;
				if (func == null)
				{
					func = (DataVirtualHardDisk disk) => disk.Lun == this.LUN;
				}
				DataVirtualHardDisk diskLabel = dataVirtualHardDisks.Where<DataVirtualHardDisk>(func).SingleOrDefault<DataVirtualHardDisk>();
				if (diskLabel != null)
				{
					object[] lUN = new object[1];
					lUN[0] = this.LUN;
					base.ThrowTerminatingError(new ErrorRecord(new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "A data disk has already been assigned to LUN #{0} for this VM. Specify a different LUN or use Set-DataDisk to change the configuration settings of the existing disk.", lUN)), string.Empty, ErrorCategory.InvalidData, null));
				}
				DataVirtualHardDisk dataVirtualHardDisk = new DataVirtualHardDisk();
				dataVirtualHardDisk.HostCaching = this.HostCaching;
				dataVirtualHardDisk.Lun = this.LUN;
				diskLabel = dataVirtualHardDisk;
				string parameterSetName = base.ParameterSetName;
				string str = parameterSetName;
				if (parameterSetName != null)
				{
					if (str == "CreateNew")
					{
						diskLabel.DiskLabel = this.DiskLabel;
						diskLabel.LogicalDiskSizeInGB = this.DiskSizeInGB;
						DataVirtualHardDisk dataVirtualHardDisk1 = diskLabel;
						if (string.IsNullOrEmpty(this.MediaLocation))
						{
							uri = null;
						}
						else
						{
							uri = new Uri(this.MediaLocation);
						}
						dataVirtualHardDisk1.MediaLink = uri;
					}
					else
					{
						if (str == "Import")
						{
							diskLabel.DiskName = this.DiskName;
						}
						else
						{
							if (str == "ImportFrom")
							{
								diskLabel.DiskName = this.DiskName;
								DataVirtualHardDisk dataVirtualHardDisk2 = diskLabel;
								if (string.IsNullOrEmpty(this.MediaLocation))
								{
									uri1 = null;
								}
								else
								{
									uri1 = new Uri(this.MediaLocation);
								}
								dataVirtualHardDisk2.SourceMediaLink = uri1;
							}
						}
					}
				}
				dataDisks.Add(diskLabel);
				base.WriteObject(base.VM, true);
			}
			catch (Exception exception1)
			{
				Exception exception = exception1;
				base.WriteError(new ErrorRecord(exception, string.Empty, ErrorCategory.CloseError, null));
			}
		}
 public IAsyncResult BeginUpdateDataDisk(string subscriptionID, string serviceName, string deploymentName, string roleName, string lun, DataVirtualHardDisk dataDisk, AsyncCallback callback, object state)
 {
     throw new NotImplementedException();
 }
예제 #13
0
        protected override void ProcessRecord()
        {
            Uri uri;
            Uri uri1;
            Func <DataVirtualHardDisk, bool> func = null;

            try
            {
                this.ValidateParameters();
                base.ProcessRecord();
                Collection <DataVirtualHardDisk> dataDisks            = this.GetDataDisks();
                Collection <DataVirtualHardDisk> dataVirtualHardDisks = dataDisks;
                if (func == null)
                {
                    func = (DataVirtualHardDisk disk) => disk.Lun == this.LUN;
                }
                DataVirtualHardDisk diskLabel = dataVirtualHardDisks.Where <DataVirtualHardDisk>(func).SingleOrDefault <DataVirtualHardDisk>();
                if (diskLabel != null)
                {
                    object[] lUN = new object[1];
                    lUN[0] = this.LUN;
                    base.ThrowTerminatingError(new ErrorRecord(new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "A data disk has already been assigned to LUN #{0} for this VM. Specify a different LUN or use Set-DataDisk to change the configuration settings of the existing disk.", lUN)), string.Empty, ErrorCategory.InvalidData, null));
                }
                DataVirtualHardDisk dataVirtualHardDisk = new DataVirtualHardDisk();
                dataVirtualHardDisk.HostCaching = this.HostCaching;
                dataVirtualHardDisk.Lun         = this.LUN;
                diskLabel = dataVirtualHardDisk;
                string parameterSetName = base.ParameterSetName;
                string str = parameterSetName;
                if (parameterSetName != null)
                {
                    if (str == "CreateNew")
                    {
                        diskLabel.DiskLabel           = this.DiskLabel;
                        diskLabel.LogicalDiskSizeInGB = this.DiskSizeInGB;
                        DataVirtualHardDisk dataVirtualHardDisk1 = diskLabel;
                        if (string.IsNullOrEmpty(this.MediaLocation))
                        {
                            uri = null;
                        }
                        else
                        {
                            uri = new Uri(this.MediaLocation);
                        }
                        dataVirtualHardDisk1.MediaLink = uri;
                    }
                    else
                    {
                        if (str == "Import")
                        {
                            diskLabel.DiskName = this.DiskName;
                        }
                        else
                        {
                            if (str == "ImportFrom")
                            {
                                diskLabel.DiskName = this.DiskName;
                                DataVirtualHardDisk dataVirtualHardDisk2 = diskLabel;
                                if (string.IsNullOrEmpty(this.MediaLocation))
                                {
                                    uri1 = null;
                                }
                                else
                                {
                                    uri1 = new Uri(this.MediaLocation);
                                }
                                dataVirtualHardDisk2.SourceMediaLink = uri1;
                            }
                        }
                    }
                }
                dataDisks.Add(diskLabel);
                base.WriteObject(base.VM, true);
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                base.WriteError(new ErrorRecord(exception, string.Empty, ErrorCategory.CloseError, null));
            }
        }
예제 #14
0
        internal void ExecuteCommand()
        {
            var dataDisks = GetDataDisks();
            var dataDisk = dataDisks.SingleOrDefault(disk => disk.Lun == LUN);

            if (dataDisk != null)
            {
                ThrowTerminatingError(
                    new ErrorRecord(
                            new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "A data disk has already been assigned to LUN #{0} for this VM. Specify a different LUN or use Set-DataDisk to change the configuration settings of the existing disk.", this.LUN)),
                            string.Empty,
                            ErrorCategory.InvalidData,
                            null));
            }

            dataDisk = new DataVirtualHardDisk { HostCaching = HostCaching, Lun = LUN };

            switch (ParameterSetName)
            {
                case "CreateNew":
                    dataDisk.DiskLabel = DiskLabel;
                    dataDisk.LogicalDiskSizeInGB = DiskSizeInGB;
                    dataDisk.MediaLink = string.IsNullOrEmpty(MediaLocation) ? null : new Uri(MediaLocation);
                    break;
                case "Import":
                    dataDisk.DiskName = DiskName;
                    break;
                case "ImportFrom":
                    dataDisk.DiskName = DiskName;
                    dataDisk.SourceMediaLink = string.IsNullOrEmpty(MediaLocation) ? null : new Uri(MediaLocation);
                    break;
            }

            dataDisks.Add(dataDisk);

            WriteObject(VM, true);
        }
 public static void UpdateDataDisk(this IServiceManagement proxy,
     string subscriptionId,
     string serviceName,
     string deploymentName,
     string roleName,
     int lun,
     DataVirtualHardDisk dataDisk)
 {
     proxy.EndUpdateDataDisk(
         proxy.BeginUpdateDataDisk(subscriptionId,
         serviceName,
         deploymentName,
         roleName,
         lun.ToString(),
         dataDisk,
         null,
         null));
 }