示例#1
0
        /// <summary>
        /// Initializes a new instance of the DataBoxManagementClient class
        /// </summary>
        /// <returns></returns>
        static DataBoxManagementClient InitializeDataBoxClient()
        {
            const string frontDoorUrl = "https://login.microsoftonline.com";
            const string tokenUrl     = "https://management.azure.com";

            // Fetch the configuration parameters.
            tenantId          = CloudConfigurationManager.GetSetting("TenantId");
            subscriptionId    = CloudConfigurationManager.GetSetting("SubscriptionId");
            aadApplicationId  = CloudConfigurationManager.GetSetting("AADApplicationId");
            aadApplicationKey = CloudConfigurationManager.GetSetting("AADApplicationKey");

            // Validates AAD ApplicationId and returns token
            var credentials = ApplicationTokenProvider.LoginSilentAsync(
                tenantId,
                aadApplicationId,
                aadApplicationKey,
                new ActiveDirectoryServiceSettings()
            {
                AuthenticationEndpoint = new Uri(frontDoorUrl),
                TokenAudience          = new Uri(tokenUrl),
                ValidateAuthority      = true,
            }).GetAwaiter().GetResult();

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

            // Set SubscriptionId
            dataBoxManagementClient.SubscriptionId = subscriptionId;

            return(dataBoxManagementClient);
        }
示例#2
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.");
            }
        }
示例#3
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);
            }
        }
示例#4
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);
        }
示例#5
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();
                }
            }
        }
示例#6
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.");
            }
        }
示例#7
0
        /// <summary>
        /// This method validates the customer shipping address and provide alternate addresses
        /// if any.
        /// </summary>
        private static void ValidateShippingAddress()
        {
            AddressType addressType     = AddressType.None;
            string      companyName     = "<company-name>";
            string      streetAddress1  = "<street-address-1>";
            string      streetAddress2  = "<street-address-2>";
            string      streetAddress3  = "<street-address-3>";
            string      postalCode      = "<postal-code>";
            string      city            = "<city>";
            string      stateOrProvince = "<state-or-province>";
            CountryCode countryCode     = CountryCode.US;

            ShippingAddress shippingAddress = new ShippingAddress()
            {
                AddressType     = addressType,
                CompanyName     = companyName,
                StreetAddress1  = streetAddress1,
                StreetAddress2  = streetAddress2,
                StreetAddress3  = streetAddress3,
                City            = city,
                StateOrProvince = stateOrProvince,
                PostalCode      = postalCode,
                Country         = countryCode.ToString(),
            };

            // Set location of the resource
            string location = "<location>";

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

            dataBoxManagementClient.Location = location;

            ValidateAddress         validateAddress         = new ValidateAddress(shippingAddress, DeviceType.Pod);
            AddressValidationOutput addressValidationOutput = ServiceOperationsExtensions.ValidateAddressMethod(dataBoxManagementClient.Service, validateAddress);

            // Verify shipping address validation status
            CheckShippingAddressValidationResult(addressValidationOutput);
        }
示例#8
0
        /// <summary>
        /// Lists all the jobs available under the subscription.
        /// </summary>
        private static void ListJobs()
        {
            //Initializes a new instance of the DataBoxManagementClient class
            DataBoxManagementClient dataBoxManagementClient = InitializeDataBoxClient();

            IPage <JobResource> jobPageList = null;
            List <JobResource>  jobList     = new List <JobResource>();

            do
            {
                // Lists all the jobs available under the subscription.
                if (jobPageList == null)
                {
                    jobPageList = JobsOperationsExtensions.List(dataBoxManagementClient.Jobs);
                }
                else
                {
                    jobPageList = JobsOperationsExtensions.ListNext(dataBoxManagementClient.Jobs, jobPageList.NextPageLink);
                }

                jobList.AddRange(jobPageList.ToList());
            } while (!(string.IsNullOrEmpty(jobPageList.NextPageLink)));
        }
示例#9
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.");
            }
        }
示例#10
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);
            }
        }
示例#11
0
        /// <summary>
        /// Lists all the jobs available under the given resource group.
        /// </summary>
        private static void ListJobsByResourceGroup()
        {
            //Initializes a new instance of the DataBoxManagementClient class
            DataBoxManagementClient dataBoxManagementClient = InitializeDataBoxClient();

            IPage <JobResource> jobPageList = null;
            List <JobResource>  jobList     = new List <JobResource>();
            string resourceGroupName        = "<resource-group-name>";

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

                jobList.AddRange(jobPageList.ToList());
            } while (!(string.IsNullOrEmpty(jobPageList.NextPageLink)));
        }
示例#12
0
        /// <summary>
        /// Creates a new job with the specified parameters.
        /// </summary>
        private static void CreateJob()
        {
            AddressType addressType     = AddressType.None;
            string      streetAddress1  = "<street-address-1>";
            string      streetAddress2  = "<street-address-2>";
            string      streetAddress3  = "<street-address-3>";
            string      postalCode      = "<postal-code>";
            string      city            = "<city>";
            string      stateOrProvince = "<state-or-province>";
            CountryCode countryCode     = CountryCode.US;

            ShippingAddress shippingAddress = new ShippingAddress()
            {
                StreetAddress1  = streetAddress1,
                StreetAddress2  = streetAddress2,
                StreetAddress3  = streetAddress3,
                AddressType     = addressType,
                Country         = countryCode.ToString(),
                PostalCode      = postalCode,
                City            = city,
                StateOrProvince = stateOrProvince,
            };

            string emailIds = "<email-ids>";
            // Input a semicolon (;) separated string of email ids, eg. "[email protected];[email protected]"
            string phoneNumber = "<phone-number>";
            string contactName = "<contact-name>";

            List <string> emailIdList = new List <string>();

            emailIdList = emailIds.Split(new char[';'], StringSplitOptions.RemoveEmptyEntries).ToList();

            ContactDetails contactDetails = new ContactDetails()
            {
                Phone       = phoneNumber,
                EmailList   = emailIdList,
                ContactName = contactName
            };

            string      storageAccProviderType      = "Microsoft.Storage"; // Input the storage account provider type; Valid types: Microsoft.Storage / Microsoft.ClassicStorage
            string      storageAccResourceGroupName = "<storage-account-resource-group-name>";
            string      storageAccName = "<storage-account-name>";
            AccountType accountType    = "<account-type>"; // Choose account type from Storage AccountType list. eg. AccountType.GeneralPurposeStorage

            List <DestinationAccountDetails> destinationAccountDetails = new List <DestinationAccountDetails>();

            destinationAccountDetails.Add(
                new DestinationAccountDetails(
                    string.Concat("/subscriptions/", subscriptionId, "/resourceGroups/", storageAccResourceGroupName,
                                  "/providers/", storageAccProviderType, "/storageAccounts/", storageAccName.ToLower()), accountType));


            // Note.
            // For multiple destination storage accounts, follow above steps to add more than one account.
            // The storage accounts should be in the same Azure DataBox order's subscription and location (region).

            PodJobDetails jobDetails = new PodJobDetails(contactDetails, shippingAddress);

            string resourceGroupName = "<resource-group-name>";
            string location          = "<location>";
            string jobName           = "<job-or-order-name>";

            JobResource newJobResource = new JobResource(location, destinationAccountDetails, jobDetails);

            newJobResource.DeviceType = DeviceType.Pod;

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

            dataBoxManagementClient.Location = location;

            // Validate shipping address
            AddressValidationOutput addressValidateResult =
                ServiceOperationsExtensions.ValidateAddressMethod(
                    dataBoxManagementClient.Service,
                    new ValidateAddress(
                        shippingAddress,
                        newJobResource.DeviceType));

            // Verify shipping address validation status
            CheckShippingAddressValidationResult(addressValidateResult);

            // Creates a new job.
            if (addressValidateResult.ValidationStatus == AddressValidationStatus.Valid)
            {
                JobResource jobResource = JobsOperationsExtensions.Create(
                    dataBoxManagementClient.Jobs,
                    resourceGroupName,
                    jobName, newJobResource);
            }
        }