Esempio n. 1
0
        /// <summary>
        /// This method gets shipping label sas uri for the specified job.
        /// </summary>
        private static void GetShippingLableUri()
        {
            string resourceGroupName = "<resource-group-name>";
            string jobName           = "<job-name>";

            // Initializes a new instance of the DataBoxManagementClient class.
            DataBoxManagementClient dataBoxManagementClient = InitializeDataBoxClient();

            // Gets information about the specified job.
            JobResource jobResource = JobsOperationsExtensions.Get(
                dataBoxManagementClient.Jobs,
                resourceGroupName,
                jobName);

            if (jobResource.Status == StageName.Delivered)
            {
                // Initiate cancel job
                ShippingLabelDetails shippingLabelDetails = JobsOperationsExtensions.DownloadShippingLabelUri(
                    dataBoxManagementClient.Jobs,
                    resourceGroupName,
                    jobName);

                Console.WriteLine("Shipping address sas url: \n{0}", shippingLabelDetails.ShippingLabelSasUri);
            }
            else
            {
                Console.WriteLine("Shipment address will be available only when the job is in delivered stage.");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// This method cancels the specified job.
        /// </summary>
        private static void CancelJob()
        {
            string resourceGroupName = "<resource-group-name>";
            string jobName           = "<job-name>";
            string reason            = "<reason>";

            // Initializes a new instance of the DataBoxManagementClient class.
            DataBoxManagementClient dataBoxManagementClient = InitializeDataBoxClient();

            // Gets information about the specified job.
            JobResource jobResource = JobsOperationsExtensions.Get(
                dataBoxManagementClient.Jobs,
                resourceGroupName,
                jobName);

            if (jobResource.IsCancellable != null &&
                (bool)jobResource.IsCancellable)
            {
                CancellationReason cancellationReason = new CancellationReason(reason);

                // Initiate cancel job
                JobsOperationsExtensions.Cancel(
                    dataBoxManagementClient.Jobs,
                    resourceGroupName,
                    jobName,
                    cancellationReason);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Gets information about the specified job.
        /// </summary>
        private static void GetJob()
        {
            string resourceGroupName = "<resource-group-name>";
            string jobName           = "<job-name>";
            string expand            = "details";

            //Initializes a new instance of the DataBoxManagementClient class
            DataBoxManagementClient dataBoxManagementClient = InitializeDataBoxClient();

            // Gets information about the specified job.
            JobResource jobResource = JobsOperationsExtensions.Get(dataBoxManagementClient.Jobs, resourceGroupName, jobName, expand);
        }
Esempio n. 4
0
        /// <summary>
        /// This method gets the unencrypted secrets related to the job.
        /// </summary>
        private static void GetSecrets()
        {
            string resourceGroupName = "<resource-group-name>";
            string jobName           = "<job-name>";

            // Initializes a new instance of the DataBoxManagementClient class
            DataBoxManagementClient dataBoxManagementClient = InitializeDataBoxClient();

            // Gets information about the specified job.
            JobResource jobResource = JobsOperationsExtensions.Get(
                dataBoxManagementClient.Jobs,
                resourceGroupName,
                jobName);

            if (jobResource.Status != null &&
                (int)jobResource.Status >= (int)StageName.Delivered &&
                (int)jobResource.Status <= (int)StageName.DataCopy)
            {
                // Fetches the list of unencrypted secrets
                UnencryptedSecrets secrets = ListSecretsOperationsExtensions.ListByJobs(
                    dataBoxManagementClient.ListSecrets,
                    resourceGroupName,
                    jobName);

                PodJobSecrets podSecret = (PodJobSecrets)secrets.JobSecrets;

                if (podSecret.PodSecrets != null)
                {
                    Console.WriteLine("Azure Databox device credentails");
                    foreach (PodSecret accountCredentials in podSecret.PodSecrets)
                    {
                        Console.WriteLine(" Device serial number: {0}", accountCredentials.DeviceSerialNumber);
                        Console.WriteLine(" Device password: {0}", accountCredentials.DevicePassword);

                        foreach (AccountCredentialDetails accountCredentialDetails in
                                 accountCredentials.AccountCredentialDetails)
                        {
                            Console.WriteLine("  Account name: {0}", accountCredentialDetails.AccountName);
                            foreach (ShareCredentialDetails shareCredentialDetails in
                                     accountCredentialDetails.ShareCredentialDetails)
                            {
                                Console.WriteLine("   Share name: {0}", shareCredentialDetails.ShareName);
                                Console.WriteLine("   User name: {0}", shareCredentialDetails.UserName);
                                Console.WriteLine("   Password: {0}{1}", shareCredentialDetails.Password, Environment.NewLine);
                            }
                        }
                        Console.WriteLine();
                    }
                    Console.ReadLine();
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// This method provides list of copy logs uri.
        /// </summary>
        private static void GetCopyLogsUri()
        {
            string resourceGroupName = "<resource-group-name>";
            string jobName           = "<job-name>";

            // Initializes a new instance of the DataBoxManagementClient class
            DataBoxManagementClient dataBoxManagementClient = InitializeDataBoxClient();

            // Gets information about the specified job.
            JobResource jobResource = JobsOperationsExtensions.Get(
                dataBoxManagementClient.Jobs,
                resourceGroupName,
                jobName);

            if (jobResource.Status == StageName.DataCopy ||
                jobResource.Status == StageName.Completed ||
                jobResource.Status == StageName.CompletedWithErrors)
            {
                // Fetches the Copy log details
                GetCopyLogsUriOutput getCopyLogsUriOutput =
                    JobsOperationsExtensions.GetCopyLogsUri(
                        dataBoxManagementClient.Jobs,
                        resourceGroupName,
                        jobName);

                if (getCopyLogsUriOutput.CopyLogDetails != null)
                {
                    Console.WriteLine("Copy log details");
                    foreach (AccountCopyLogDetails copyLogitem in getCopyLogsUriOutput.CopyLogDetails)
                    {
                        Console.WriteLine(string.Concat("  Account name: ", copyLogitem.AccountName, Environment.NewLine,
                                                        "  Copy log link: ", copyLogitem.CopyLogLink, Environment.NewLine, Environment.NewLine));
                    }
                }
            }
            else
            {
                Console.WriteLine("Copy logs will be available only when the job is in either data copy or completed status.");
            }
        }
Esempio n. 6
0
        /// <summary>
        /// This method initiates a shipment pickup.
        /// </summary>
        private static void BookShipmentPickup()
        {
            string resourceGroupName = "<resoruce-group-name>";
            string jobName           = "<job-name>";

            DateTime dtStartTime      = new DateTime();
            DateTime dtEndTime        = new DateTime();
            string   shipmentLocation = "<shipment-location>";

            ShipmentPickUpRequest shipmentPickUpRequest = new ShipmentPickUpRequest(dtStartTime, dtEndTime, shipmentLocation);

            // Initializes a new instance of the DataBoxManagementClient class
            DataBoxManagementClient dataBoxManagementClient = InitializeDataBoxClient();

            // Gets information about the specified job.
            JobResource jobResource = JobsOperationsExtensions.Get(
                dataBoxManagementClient.Jobs,
                resourceGroupName,
                jobName);

            if (jobResource.Status == StageName.Delivered)
            {
                // Initiate Book shipment pick up
                ShipmentPickUpResponse shipmentPickUpResponse = JobsOperationsExtensions.BookShipmentPickUp(
                    dataBoxManagementClient.Jobs,
                    resourceGroupName,
                    jobName,
                    shipmentPickUpRequest);

                Console.WriteLine("Confirmation number: {0}", shipmentPickUpResponse.ConfirmationNumber);
            }
            else
            {
                Console.WriteLine("Shipment pickup will be initiated only when the job is in delivered stage.");
            }
        }
Esempio n. 7
0
        /// <summary>
        /// This method deletes the specified job.
        /// </summary>
        private static void DeleteJob()
        {
            string resourceGroupName = "<resource-group-name>";
            string jobName           = "<job-name>";

            // Initializes a new instance of the DataBoxManagementClient class.
            DataBoxManagementClient dataBoxManagementClient = InitializeDataBoxClient();

            // Gets information about the specified job.
            JobResource jobResource = JobsOperationsExtensions.Get(
                dataBoxManagementClient.Jobs,
                resourceGroupName,
                jobName);

            if (jobResource.Status == StageName.Cancelled ||
                jobResource.Status == StageName.Completed ||
                jobResource.Status == StageName.CompletedWithErrors)
            {
                // Initiate delete job
                JobsOperationsExtensions.Delete(dataBoxManagementClient.Jobs,
                                                resourceGroupName,
                                                jobName);
            }
        }
        public override void ExecuteCmdlet()
        {
            if (this.IsParameterBound(c => this.ResourceId))
            {
                var resourceIdentifier = new DataBoxEdgeResourceIdentifier(this.ResourceId);
                this.ResourceGroupName = this.ResourceGroupName;
                this.DeviceName        = this.DeviceName;
                this.Name = this.Name;
            }

            if (this.IsParameterBound(c => this.DeviceObject))
            {
                this.ResourceGroupName = this.DeviceObject.ResourceGroupName;
                this.DeviceName        = this.DeviceObject.Name;
            }

            var results = new List <PSResourceModel>();

            if (!string.IsNullOrEmpty(this.Name) &&
                !string.IsNullOrEmpty(this.DeviceName) &&
                !string.IsNullOrEmpty(this.ResourceGroupName))
            {
                results.Add(
                    new PSResourceModel(
                        JobsOperationsExtensions.Get(
                            this.DataBoxEdgeManagementClient.Jobs,
                            this.DeviceName,
                            this.Name,
                            this.ResourceGroupName
                            )
                        )
                    );
            }

            WriteObject(results, true);
        }
        public override void ExecuteCmdlet()
        {
            if (this.ParameterSetName.Equals("GetByResourceIdParameterSet"))
            {
                this.ResourceGroupName = ResourceIdHandler.GetResourceGroupName(ResourceId);
                this.Name = ResourceIdHandler.GetResourceName(ResourceId);
            }

            if (!string.IsNullOrEmpty(this.Name))
            {
                List <PSDataBoxJob> result = new List <PSDataBoxJob>();
                result.Add(new PSDataBoxJob(JobsOperationsExtensions.Get(
                                                this.DataBoxManagementClient.Jobs,
                                                this.ResourceGroupName,
                                                this.Name,
                                                "details")));
                WriteObject(result, true);
            }
            else if (!string.IsNullOrEmpty(this.ResourceGroupName))
            {
                IPage <JobResource> jobPageList = null;
                List <JobResource>  result      = new List <JobResource>();
                List <PSDataBoxJob> finalResult = new List <PSDataBoxJob>();

                do
                {
                    // Lists all the jobs available under resource group.
                    if (jobPageList == null)
                    {
                        jobPageList = JobsOperationsExtensions.ListByResourceGroup(
                            this.DataBoxManagementClient.Jobs,
                            this.ResourceGroupName);
                    }
                    else
                    {
                        jobPageList = JobsOperationsExtensions.ListByResourceGroupNext(
                            this.DataBoxManagementClient.Jobs,
                            jobPageList.NextPageLink);
                    }

                    if (Completed || Cancelled || Aborted || CompletedWithError)
                    {
                        foreach (var job in jobPageList)
                        {
                            if ((Completed && job.Status == StageName.Completed) ||
                                (Cancelled && job.Status == StageName.Cancelled) ||
                                (Aborted && job.Status == StageName.Aborted) ||
                                (CompletedWithError && job.Status == StageName.CompletedWithErrors))
                            {
                                result.Add(job);
                            }
                        }
                    }
                    else
                    {
                        result.AddRange(jobPageList.ToList());
                    }
                } while (!(string.IsNullOrEmpty(jobPageList.NextPageLink)));

                foreach (var job in result)
                {
                    finalResult.Add(new PSDataBoxJob(job));
                }
                WriteObject(finalResult, true);
            }
            else
            {
                IPage <JobResource> jobPageList = null;
                List <JobResource>  result      = new List <JobResource>();
                List <PSDataBoxJob> finalResult = new List <PSDataBoxJob>();

                do
                {
                    // Lists all the jobs available under the subscription.
                    if (jobPageList == null)
                    {
                        jobPageList = JobsOperationsExtensions.List(
                            this.DataBoxManagementClient.Jobs);
                    }
                    else
                    {
                        jobPageList = JobsOperationsExtensions.ListNext(
                            this.DataBoxManagementClient.Jobs,
                            jobPageList.NextPageLink);
                    }
                    if (Completed || Cancelled || Aborted || CompletedWithError)
                    {
                        foreach (var job in jobPageList)
                        {
                            if ((Completed && job.Status == StageName.Completed) ||
                                (Cancelled && job.Status == StageName.Cancelled) ||
                                (Aborted && job.Status == StageName.Aborted) ||
                                (CompletedWithError && job.Status == StageName.CompletedWithErrors))
                            {
                                result.Add(job);
                            }
                        }
                    }
                    else
                    {
                        result.AddRange(jobPageList.ToList());
                    }
                } while (!(string.IsNullOrEmpty(jobPageList.NextPageLink)));

                foreach (var job in result)
                {
                    finalResult.Add(new PSDataBoxJob(job));
                }
                WriteObject(finalResult, true);
            }
        }