public override void ExecuteCmdlet() { if (this.ParameterSetName.Equals(GetByResourceIdParameterSet)) { this.ResourceGroupName = ResourceIdHandler.GetResourceGroupName(ResourceId); this.Name = ResourceIdHandler.GetResourceName(ResourceId); } if (this.ParameterSetName.Equals(GetByInputObjectParameterSet)) { this.ResourceGroupName = InputObject.ResourceGroup; this.Name = InputObject.JobResource.Name; } // Initiate to delete job if (ShouldProcess(this.Name, string.Format(Resource.DeletingDataboxJob + this.Name + Resource.InResourceGroup + this.ResourceGroupName))) { JobsOperationsExtensions.Delete( DataBoxManagementClient.Jobs, ResourceGroupName, Name); if (PassThru) { WriteObject(true); } } }
/// <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."); } }
/// <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); } }
/// <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); }
/// <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(); } } }
/// <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."); } }
/// <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))); }
/// <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."); } }
/// <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); } }
/// <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))); }
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); }
/// <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); } }
public override void ExecuteCmdlet() { if (DataBoxType == "DataBoxDisk" && ExpectedDataSizeInTeraBytes.Equals(0)) { throw new PSArgumentNullException("ExpectedDataSizeInTeraBytes"); } ShippingAddress shippingAddress = new ShippingAddress() { AddressType = this.AddressType, CompanyName = this.CompanyName, StreetAddress1 = this.StreetAddress1, StreetAddress2 = this.StreetAddress2, StreetAddress3 = this.StreetAddress3, City = this.City, StateOrProvince = this.StateOrProvinceCode, Country = this.CountryCode, PostalCode = this.PostalCode }; ContactDetails contactDetails = new ContactDetails() { Phone = this.PhoneNumber, EmailList = EmailId, ContactName = this.ContactName }; List <DestinationAccountDetails> destinationAccountDetails = new List <DestinationAccountDetails>(); foreach (var storageAccount in StorageAccountResourceId) { destinationAccountDetails.Add( new DestinationAccountDetails(storageAccount)); } DataBoxDiskJobDetails diskDetails; DataBoxJobDetails databoxDetails; DataBoxHeavyJobDetails heavyDetails; JobResource newJobResource = new JobResource(); Sku sku = new Sku(); switch (DataBoxType) { case "DataBoxDisk": diskDetails = new DataBoxDiskJobDetails(contactDetails, shippingAddress, destinationAccountDetails, expectedDataSizeInTeraBytes: ExpectedDataSizeInTeraBytes); sku.Name = SkuName.DataBoxDisk; newJobResource = new JobResource(Location, sku, details: diskDetails); break; case "DataBox": databoxDetails = new DataBoxJobDetails(contactDetails, shippingAddress, destinationAccountDetails); sku.Name = SkuName.DataBox; newJobResource = new JobResource(Location, sku, details: databoxDetails); break; case "DataBoxHeavy": heavyDetails = new DataBoxHeavyJobDetails(contactDetails, shippingAddress, destinationAccountDetails); sku.Name = SkuName.DataBoxHeavy; newJobResource = new JobResource(Location, sku, details: heavyDetails); break; default: break; } AddressValidationOutput addressValidationResult = ServiceOperationsExtensions.ValidateAddressMethod( DataBoxManagementClient.Service, Location, shippingAddress, newJobResource.Sku.Name); if (addressValidationResult.ValidationStatus != AddressValidationStatus.Valid) { WriteVerbose(Resource.AddressValidationStatus + addressValidationResult.ValidationStatus + "\n"); //print alternate address if (addressValidationResult.ValidationStatus == AddressValidationStatus.Ambiguous) { WriteVerbose(Resource.SupportAddresses + "\n\n"); foreach (ShippingAddress address in addressValidationResult.AlternateAddresses) { WriteVerbose(Resource.AddressType + address.AddressType + "\n"); if (!(string.IsNullOrEmpty(address.CompanyName))) { WriteVerbose(Resource.CompanyName + address.CompanyName); } if (!(string.IsNullOrEmpty(address.StreetAddress1))) { WriteVerbose(Resource.StreetAddress1 + address.StreetAddress1); } if (!(string.IsNullOrEmpty(address.StreetAddress2))) { WriteVerbose(Resource.StreetAddress2 + address.StreetAddress2); } if (!(string.IsNullOrEmpty(address.StreetAddress3))) { WriteVerbose(Resource.StreetAddress3 + address.StreetAddress3); } if (!(string.IsNullOrEmpty(address.City))) { WriteVerbose(Resource.City + address.City); } if (!(string.IsNullOrEmpty(address.StateOrProvince))) { WriteVerbose(Resource.StateOrProvince + address.StateOrProvince); } if (!(string.IsNullOrEmpty(address.Country))) { WriteVerbose(Resource.Country + address.Country); } if (!(string.IsNullOrEmpty(address.PostalCode))) { WriteVerbose(Resource.PostalCode + address.PostalCode); } if (!(string.IsNullOrEmpty(address.ZipExtendedCode))) { WriteVerbose(Resource.ZipExtendedCode + address.ZipExtendedCode); } WriteVerbose("\n\n"); } throw new PSNotSupportedException(Resource.AmbiguousAddressMessage); } throw new PSNotSupportedException(Resource.InvalidAddressMessage); } if (ShouldProcess(this.Name, string.Format(Resource.CreatingDataboxJob + this.Name + Resource.InResourceGroup + this.ResourceGroupName))) { JobResource finalJobResource = JobsOperationsExtensions.Create( DataBoxManagementClient.Jobs, ResourceGroupName, Name, newJobResource); WriteObject(new PSDataBoxJob(finalJobResource)); } }
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); } }