public void AddDiskProcess()
        {
            AddAzureDiskCommand.AddAzureDiskCommand variable = null;
            string diskName;

            using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
            {
                try
                {
                    AddAzureDiskCommand.AddAzureDiskCommand variable1 = variable;
                    Disk disk = new Disk();
                    disk.Name      = this.DiskName;
                    disk.MediaLink = new Uri(this.MediaLocation);
                    disk.OS        = this.OS;
                    Disk disk1 = disk;
                    if (string.IsNullOrEmpty(this.Label))
                    {
                        diskName = this.DiskName;
                    }
                    else
                    {
                        diskName = this.Label;
                    }
                    disk1.Label    = diskName;
                    variable1.disk = disk;
                    CmdletExtensions.WriteVerboseOutputForObject(this, LambdaVar22);
                    Disk        disk2       = base.RetryCall <Disk>((string s) => base.Channel.CreateDisk(s, LambdaVar22));
                    DiskContext diskContext = new DiskContext();
                    diskContext.DiskName        = disk2.Name;
                    diskContext.Label           = disk2.Label;
                    diskContext.IsCorrupted     = disk2.IsCorrupted;
                    diskContext.AffinityGroup   = disk2.AffinityGroup;
                    diskContext.OS              = disk2.OS;
                    diskContext.Location        = disk2.Location;
                    diskContext.MediaLink       = disk2.MediaLink;
                    diskContext.DiskSizeInGB    = disk2.LogicalDiskSizeInGB;
                    diskContext.SourceImageName = disk2.SourceImageName;
                    diskContext.AttachedTo      = AddAzureDiskCommand.CreateRoleReference(disk2.AttachedTo);
                    DiskContext diskContext1 = diskContext;
                    Operation   operation    = base.WaitForOperation(base.CommandRuntime.ToString());
                    diskContext1.set_OperationDescription(base.CommandRuntime.ToString());
                    diskContext1.set_OperationId(operation.OperationTrackingId);
                    diskContext1.set_OperationStatus(operation.Status);
                    base.WriteObject(diskContext1, true);
                }
                catch (CommunicationException communicationException1)
                {
                    CommunicationException communicationException = communicationException1;
                    this.WriteErrorDetails(communicationException);
                }
            }
        }
Example #2
0
        public void AzureDiskTest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
            vhdName = "os0.vhd";
            string mediaLocation = String.Format("{0}{1}/{2}", blobUrlRoot, vhdContainerName, vhdName);

            try
            {
                vmPowershellCmdlets.AddAzureDisk(vhdName, mediaLocation, vhdName, null);

                bool found = false;
                foreach (DiskContext disk in vmPowershellCmdlets.GetAzureDisk(vhdName))
                {
                    Console.WriteLine("Disk: Name - {0}, Label - {1}, Size - {2},", disk.DiskName, disk.Label, disk.DiskSizeInGB);
                    if (disk.DiskName == vhdName && disk.Label == vhdName)
                    {
                        found = true;
                        Console.WriteLine("{0} is found", disk.DiskName);
                    }
                }
                Assert.IsTrue(found, "Error: Disk is not added");

                string newLabel = "NewLabel";
                vmPowershellCmdlets.UpdateAzureDisk(vhdName, newLabel);

                DiskContext disk2 = vmPowershellCmdlets.GetAzureDisk(vhdName)[0];

                Console.WriteLine("Disk: Name - {0}, Label - {1}, Size - {2},", disk2.DiskName, disk2.Label, disk2.DiskSizeInGB);
                Assert.AreEqual(newLabel, disk2.Label);
                Console.WriteLine("Disk Label is successfully updated");

                vmPowershellCmdlets.RemoveAzureDisk(vhdName, false);
                Assert.IsTrue(Utilities.CheckRemove(vmPowershellCmdlets.GetAzureDisk, vhdName), "The disk was not removed");
                pass = true;
            }
            catch (Exception e)
            {
                pass = false;

                if (e.ToString().Contains("ResourceNotFound"))
                {
                    Console.WriteLine("Please upload {0} file to \\vhdtest\\ blob directory before running this test", vhdName);
                }

                Assert.Fail("Exception occurs: {0}", e.ToString());
            }
        }
        public void UpdateDiskProcess()
        {
            string empty = string.Empty;

            using (OperationContextScope operationContextScope = new OperationContextScope((IContextChannel)base.Channel))
            {
                try
                {
                    Disk disk = new Disk();
                    disk.Name  = this.DiskName;
                    disk.Label = this.Label;
                    Disk disk1 = disk;
                    CmdletExtensions.WriteVerboseOutputForObject(this, disk1);
                    Disk disk2 = base.RetryCall <Disk>((string s) => base.Channel.UpdateDisk(s, this.DiskName, disk1));
                    if (disk2 != null)
                    {
                        DiskContext diskContext = new DiskContext();
                        diskContext.set_OperationId(empty);
                        diskContext.DiskName        = disk1.Name;
                        diskContext.Label           = disk1.Label;
                        diskContext.IsCorrupted     = disk1.IsCorrupted;
                        diskContext.AffinityGroup   = disk1.AffinityGroup;
                        diskContext.OS              = disk1.OS;
                        diskContext.Location        = disk1.Location;
                        diskContext.MediaLink       = disk1.MediaLink;
                        diskContext.DiskSizeInGB    = disk1.LogicalDiskSizeInGB;
                        diskContext.SourceImageName = disk1.SourceImageName;
                        diskContext.AttachedTo      = UpdateAzureDiskCommand.CreateRoleReference(disk1.AttachedTo);
                        DiskContext diskContext1 = diskContext;
                        Operation   operation    = base.WaitForOperation(base.CommandRuntime.ToString());
                        diskContext1.set_OperationDescription(base.CommandRuntime.ToString());
                        diskContext1.set_OperationId(operation.OperationTrackingId);
                        diskContext1.set_OperationStatus(operation.Status);
                        base.WriteObject(diskContext1, true);
                    }
                }
                catch (CommunicationException communicationException1)
                {
                    CommunicationException communicationException = communicationException1;
                    this.WriteErrorDetails(communicationException);
                }
            }
        }
 protected override void ProcessRecord()
 {
     try
     {
         base.ProcessRecord();
         Operation          operation   = null;
         IEnumerable <Disk> diskProcess = this.GetDiskProcess(out operation);
         if (diskProcess != null)
         {
             List <DiskContext> diskContexts = new List <DiskContext>();
             foreach (Disk disk in diskProcess)
             {
                 DiskContext diskContext = new DiskContext();
                 diskContext.set_OperationId(operation.OperationTrackingId);
                 diskContext.set_OperationDescription(base.CommandRuntime.ToString());
                 diskContext.set_OperationStatus(operation.Status);
                 diskContext.DiskName        = disk.Name;
                 diskContext.Label           = disk.Label;
                 diskContext.IsCorrupted     = disk.IsCorrupted;
                 diskContext.AffinityGroup   = disk.AffinityGroup;
                 diskContext.OS              = disk.OS;
                 diskContext.Location        = disk.Location;
                 diskContext.MediaLink       = disk.MediaLink;
                 diskContext.DiskSizeInGB    = disk.LogicalDiskSizeInGB;
                 diskContext.SourceImageName = disk.SourceImageName;
                 diskContext.AttachedTo      = GetAzureDiskCommand.CreateRoleReference(disk.AttachedTo);
                 diskContexts.Add(diskContext);
             }
             base.WriteObject(diskContexts, true);
         }
     }
     catch (Exception exception1)
     {
         Exception exception = exception1;
         base.WriteError(new ErrorRecord(exception, string.Empty, ErrorCategory.CloseError, null));
     }
 }
Example #5
0
 public DrivesController(DiskContext context)
 {
     _context = context;
 }
        public void AzureDiskTest()
        {
            StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);

            vhdName = Utilities.GetUniqueShortName("os0vhd");
            CopyCommonVhd(vhdContainerName, "os0.vhd", vhdName);

            string mediaLocation = String.Format("{0}{1}/{2}", blobUrlRoot, vhdContainerName, vhdName);

            try
            {
                vmPowershellCmdlets.AddAzureDisk(vhdName, mediaLocation, vhdName, null);

                bool found = false;
                foreach (DiskContext disk in vmPowershellCmdlets.GetAzureDisk(vhdName))
                {
                    Console.WriteLine("Disk: Name - {0}, Label - {1}, Size - {2},", disk.DiskName, disk.Label, disk.DiskSizeInGB);
                    if (disk.DiskName == vhdName && disk.Label == vhdName)
                    {
                        found = true;
                        Console.WriteLine("{0} is found", disk.DiskName);
                    }
                }
                Assert.IsTrue(found, "Error: Disk is not added");

                // Update only label
                string newLabel = "NewLabel";
                vmPowershellCmdlets.UpdateAzureDisk(vhdName, newLabel);

                DiskContext virtualDisk = vmPowershellCmdlets.GetAzureDisk(vhdName)[0];

                Console.WriteLine("Disk: Name - {0}, Label - {1}, Size - {2},", virtualDisk.DiskName, virtualDisk.Label, virtualDisk.DiskSizeInGB);
                Assert.AreEqual(newLabel, virtualDisk.Label);
                Console.WriteLine("Disk Label is successfully updated");

                // Update only size
                int newSize = 50;
                vmPowershellCmdlets.UpdateAzureDisk(vhdName, null, newSize);

                virtualDisk = vmPowershellCmdlets.GetAzureDisk(vhdName)[0];

                Console.WriteLine("Disk: Name - {0}, Label - {1}, Size - {2},", virtualDisk.DiskName, virtualDisk.Label, virtualDisk.DiskSizeInGB);
                Assert.AreEqual(newLabel, virtualDisk.Label);
                Assert.AreEqual(newSize, virtualDisk.DiskSizeInGB);
                Console.WriteLine("Disk size is successfully updated");

                // Update both label and size
                newLabel = "NewLabel2";
                newSize  = 100;
                vmPowershellCmdlets.UpdateAzureDisk(vhdName, newLabel, newSize);

                virtualDisk = vmPowershellCmdlets.GetAzureDisk(vhdName)[0];

                Console.WriteLine("Disk: Name - {0}, Label - {1}, Size - {2},", virtualDisk.DiskName, virtualDisk.Label, virtualDisk.DiskSizeInGB);
                Assert.AreEqual(newLabel, virtualDisk.Label);
                Assert.AreEqual(newSize, virtualDisk.DiskSizeInGB);
                Console.WriteLine("Both disk label and size are successfully updated");

                vmPowershellCmdlets.RemoveAzureDisk(vhdName, true);
                Assert.IsTrue(Utilities.CheckRemove(vmPowershellCmdlets.GetAzureDisk, vhdName), "The disk was not removed");
                pass = true;
            }
            catch (Exception e)
            {
                pass = false;

                if (e.ToString().Contains("ResourceNotFound"))
                {
                    Console.WriteLine("Please upload {0} file to \\vhdtest\\ blob directory before running this test", vhdName);
                }

                try
                {
                    vmPowershellCmdlets.RemoveAzureDisk(vhdName, true);
                }
                catch (Exception cleanupError)
                {
                    Console.WriteLine("Error during cleaning up the disk.. Continue..:{0}", cleanupError);
                }

                Assert.Fail("Exception occurs: {0}", e.ToString());
            }
        }
Example #7
0
        private static void InitializeMigrations(IApplicationBuilder app, bool seedDataBase = false)
        {
            using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope())
            {
                DiskContext dbContext = serviceScope.ServiceProvider.GetRequiredService <DiskContext>();

                //dbContext.Database.EnsureCreated();
                //dbContext.Database.Migrate();

                if (seedDataBase)
                {
                    if (!dbContext.PSDrives.Any())
                    {
                        dbContext.PSDrives.AddRange(
                            new PSDrive
                        {
                            Id       = 1,
                            HostName = System.Environment.MachineName,
                            Name     = @"C:\",
                            Root     = "C:\\",
                            Used     = 351574278144,
                            Free     = 647982886912
                        });
                    }
                    dbContext.SaveChanges();


                    //// TODO: Use dbContext if you want to do seeding etc.
                    //if (!dbContext.LogicalDisks.Any())
                    //{
                    //    dbContext.LogicalDisks.AddRange(
                    //        new LogicalDisk
                    //        {
                    //            Id = 1,
                    //            Name = "C:",
                    //            Description = "Local Fixed Disk",
                    //            SystemName = "XPS9360R",
                    //            FreeSpace = 779430076416,
                    //            Size = 999557165056,
                    //            Compressed = false,
                    //            DriveType = 3,
                    //            FileSystem = "NTFS",
                    //            MaximumComponentLength = 255,
                    //            MediaType = 12,
                    //            SupportsDiskQuotas = false,
                    //            SupportsFileBasedCompression = true,
                    //            VolumeName = string.Empty,
                    //            VolumeSerialNumber = "D6F5CA93"
                    //        },
                    //        new LogicalDisk
                    //        {
                    //            Id = 2,
                    //            Name = "C:",
                    //            Description = "Local Fixed Disk",
                    //            SystemName = "SRVFILES",
                    //            FreeSpace = 28058644480,
                    //            Size = 53317988352,
                    //            Compressed = false,
                    //            DriveType = 3,
                    //            FileSystem = "NTFS",
                    //            MaximumComponentLength = 255,
                    //            MediaType = 12,
                    //            SupportsDiskQuotas = true,
                    //            SupportsFileBasedCompression = true,
                    //            VolumeName = "",
                    //            VolumeSerialNumber = "BE083D09"
                    //        },
                    //        new LogicalDisk
                    //        {
                    //            Id = 3,
                    //            Name = "E:",
                    //            Description = "Local Fixed Disk",
                    //            SystemName = "SRVFILES",
                    //            FreeSpace = 3103418286080,
                    //            Size = 3298397454336,
                    //            Compressed = false,
                    //            DriveType = 3,
                    //            FileSystem = "NTFS",
                    //            MaximumComponentLength = 255,
                    //            MediaType = 12,
                    //            SupportsDiskQuotas = true,
                    //            SupportsFileBasedCompression = false,
                    //            VolumeName = "office",
                    //            VolumeSerialNumber = "5004D410"
                    //        },
                    //        new LogicalDisk
                    //        {
                    //            Id = 4,
                    //            Name = "F:",
                    //            Description = "Local Fixed Disk",
                    //            SystemName = "SRVSTOR",
                    //            FreeSpace = 24905971007488,
                    //            Size = 70368606748672,
                    //            Compressed = false,
                    //            DriveType = 3,
                    //            FileSystem = "NTFS",
                    //            MaximumComponentLength = 255,
                    //            MediaType = 12,
                    //            SupportsDiskQuotas = true,
                    //            SupportsFileBasedCompression = false,
                    //            VolumeName = "audio",
                    //            VolumeSerialNumber = "182DAEF9"
                    //        },
                    //        new LogicalDisk
                    //        {
                    //            Id = 5,
                    //            Name = "G:",
                    //            Description = "Local Fixed Disk",
                    //            SystemName = "SRVFILES",
                    //            FreeSpace = 4487142572032,
                    //            Size = 5497421758464,
                    //            Compressed = false,
                    //            DriveType = 3,
                    //            FileSystem = "NTFS",
                    //            MaximumComponentLength = 255,
                    //            MediaType = 12,
                    //            SupportsDiskQuotas = true,
                    //            SupportsFileBasedCompression = false,
                    //            VolumeName = "video",
                    //            VolumeSerialNumber = "6E5EDF16"
                    //        },
                    //        new LogicalDisk
                    //        {
                    //            Id = 6,
                    //            Name = "I:",
                    //            Description = "Local Fixed Disk",
                    //            SystemName = "SRVFILES",
                    //            FreeSpace = 752906055680,
                    //            Size = 1099375308800,
                    //            Compressed = false,
                    //            DriveType = 3,
                    //            FileSystem = "NTFS",
                    //            MaximumComponentLength = 255,
                    //            MediaType = 12,
                    //            SupportsDiskQuotas = true,
                    //            SupportsFileBasedCompression = true,
                    //            VolumeName = "dbBackups",
                    //            VolumeSerialNumber = "F0B5AD4B"
                    //        },
                    //        new LogicalDisk
                    //        {
                    //            Id = 7,
                    //            Name = "S:",
                    //            Description = "Local Fixed Disk",
                    //            SystemName = "SRVFILES",
                    //            FreeSpace = 5497065574400,
                    //            Size = 5497421819904,
                    //            Compressed = false,
                    //            DriveType = 3,
                    //            FileSystem = "NTFS",
                    //            MaximumComponentLength = 255,
                    //            MediaType = 12,
                    //            SupportsDiskQuotas = true,
                    //            SupportsFileBasedCompression = true,
                    //            VolumeName = "video",
                    //            VolumeSerialNumber = "40355928"
                    //        },
                    //        new LogicalDisk
                    //        {
                    //            Id = 8,
                    //            Name = "Y:",
                    //            Description = "Local Fixed Disk",
                    //            SystemName = "SRVFILES",
                    //            FreeSpace = 5154517942272,
                    //            Size = 5497421758464,
                    //            Compressed = false,
                    //            DriveType = 3,
                    //            FileSystem = "NTFS",
                    //            MaximumComponentLength = 255,
                    //            MediaType = 12,
                    //            SupportsDiskQuotas = true,
                    //            SupportsFileBasedCompression = false,
                    //            VolumeName = "graphics",
                    //            VolumeSerialNumber = "6F5EBF16"
                    //        }
                    //    );
                    //    dbContext.SaveChanges();

                    //}
                }
            }
        }
Example #8
0
 public LogicalDisksController(DiskContext context)
 {
     _context = context;
 }