Aggiornare l'account di archiviazione
L'operazione asincrona Update Storage Account
aggiorna l'etichetta e la descrizione e abilita o disabilita lo stato della replica geografica per l'account di archiviazione specificato.
Richiesta
La richiesta di Update Storage Account
può essere specificata come indicato di seguito. Sostituire <subscription-id>
con l'ID sottoscrizione e <service-name>
con il nome dell'account di archiviazione.
Metodo | URI della richiesta |
---|---|
PUT | https://management.core.windows.net/<subscription-id>/services/storageservices/<service-name> |
È necessario verificare che la richiesta eseguita al servizio di gestione sia sicura. Per ulteriori dettagli, vedere l'autenticazione di richieste di gestione del servizio.
Parametri URI
Nessuna.
Intestazioni della richiesta
La tabella seguente descrive le intestazioni della richiesta.
Intestazione della richiesta | Descrizione |
---|---|
Content-Type |
Obbligatorio. Impostare questa intestazione su application/xml . |
x-ms-version |
Obbligatorio. Specifica la versione dell'operazione da usare per questa richiesta. Il valore di questa intestazione deve essere impostato su 2011-06-01 o versione successiva. Per usare la funzionalità di replica geografica, è richiesta almeno la versione "2012-03-01".Per usare la funzionalità Dominio personalizzato, è richiesta almeno la versione "2013-06-01". Per usare la funzionalità SecondaryReadEnabled, è richiesta almeno la versione "2013-11-01". Per usare il campo AccountType , è richiesta almeno la versione "2014-06-01". Si noti che GeoReplicationEnabled e SecondaryReadEnabled non sono più supportate nelle versioni successive. Le relative funzionalità sono incluse nel campo AccountType .Per ulteriori informazioni sulle intestazioni di controllo delle versioni, vedere il controllo delle versioni di Service Management. |
Corpo della richiesta
Il formato del corpo della richiesta è il seguente:
<?xml version="1.0" encoding="utf-8"?> <UpdateStorageServiceInput xmlns="https://schemas.microsoft.com/windowsazure"> <Description>description-of-storage-account</Description> <Label>base64-encoded-label</Label> <GeoReplicationEnabled>geo-replication-indicator</GeoReplicationEnabled> <ExtendedProperties> <ExtendedProperty> <Name>property-name</Name> <Value>property-value</Value> </ExtendedProperty> </ExtendedProperties> <CustomDomains> <CustomDomain> <Name>name-of-custom-domain</Name> <UseSubDomainName>cname-validation-indicator</UseSubDomainName> </CustomDomain> </CustomDomains> <SecondaryReadEnabled>secondary-read-indicator</SecondaryReadEnabled> <AccountType>type-of-storage-account</AccountType> </UpdateStorageServiceInput>
Nella tabella indicata di seguito vengono descritti gli elementi del corpo della richiesta.
Nome elemento | Descrizione |
Label | Facoltativa. Specifica un nome con codifica Base 64 per l'account di archiviazione. L'etichetta può contenere un massimo di 100 caratteri. L'etichetta può essere usata per identificare l'account di archiviazione per motivi di rilevamento. È necessario specificare un valore per Label o Description o per entrambi. |
Descrizione | Facoltativa. Descrizione dell'account di archiviazione. La descrizione può contenere un massimo di 1024 caratteri. È necessario specificare un valore per Label o Description o per entrambi. |
GeoReplicationEnabled | Facoltativa. Abilita o disabilita la replica geografica nell'archiviazione specificata. Se è impostato su true , i dati dell'account di archiviazione vengono replicati in più di una posizione geografica in modo da abilitare la resilienza in cado di perdita irreversibile di servizio. Se è impostato su false , la replica geografica è disabilitata. Se l'elemento non è incluso nel corpo della richiesta, il valore corrente non viene modificato. Important: Se è stata abilitata la replica geografica, è possibile scegliere di disabilitarla impostando questo elemento su false. Una volta disabilitata, i dati non vengono più replicati a un data center secondario e tutti i dati nella posizione secondaria saranno rimossi. Abilitare la replica geografica dopo che è stata disabilitata comporterà la fatturazione dell'account di archiviazione per la replica della copia corrente dei dati al data center secondario. Dopo la replica della copia dei dati al data center secondario, la replica geografica degli aggiornamenti verrà eseguita senza costi aggiuntivi.L'elemento GeoReplicationEnabled è disponibile solo se si usa la versione 01.03.12 o una versione successiva e viene sostituito dall'elemento AccountType con la versione 2014-06-01 o una versione successiva. |
ExtendedProperties | Specifica il nome e il valore di una proprietà estesa che è stata aggiunta all'account di archiviazione. |
CustomDomains | Specifica i domini personalizzati associati all'account di archiviazione. L'elemento CustomDomains è disponibile solo se si usa la versione 2013-06-01 o una versione successiva. |
SecondaryReadEnabled | Indica se è abilitata la lettura secondaria per l'account di archiviazione. I valori possibili sono: - true - false L'elemento SecondaryReadEnabled è disponibile solo se si usa la versione 2013-11-01 o una versione successiva e viene sostituito dall'elemento AccountType con la versione 2014-06-01 o una versione successiva. |
AccountType | Specifica se l'account supporta l'archiviazione con ridondanza locale, l'archiviazione con ridondanza geografica o l'archiviazione con ridondanza geografica e accesso in lettura. L'archiviazione con ridondanza della zona non è un'opzione disponibile quando si aggiorna un account di archiviazione. I valori possibili sono: - Standard_LRS - Standard_GRS - Standard_RAGRS L'elemento AccountType è disponibile solo se si usa la versione 2014-06-01 o una versione successiva e sostituisce gli elementi SecondaryReadEnabled e GeoReplicationEnabled. Note: I tipi di account Standard_ZRS e Premium_LRS non sono un'opzione praticabile, perché non possono essere cambiati in altri tipi di account. Inoltre, tutti gli altri tipi di account non possono essere cambiati nel tipo Standard_ZRS o Premium_LRS . |
ExtendedProperties
Specifica il nome e il valore di una proprietà estesa che è stata aggiunta all'account di archiviazione.
Nome elemento | Descrizione |
---|---|
Nome | Facoltativa. Rappresenta il nome di una proprietà estesa dell'account di archiviazione. Ogni proprietà estesa deve contenere un nome e un valore definiti. È possibile avere un massimo di 50 proprietà estese coppie nome/valore. La lunghezza massima dell'elemento Name è di 64 caratteri. Nel nome sono validi solo i caratteri alfanumerici e i caratteri di sottolineatura. Il nome deve iniziare con una lettera. Se si tenta di usare altri caratteri, di immettere un elemento Name che inizia con un carattere diverso da una lettera o di specificare un nome identico a quello di un'altra proprietà estesa appartenente allo stesso account di archiviazione, si verificherà un errore con codice di stato 400 (Richiesta non valida). Il Name elemento è disponibile solo utilizzando la versione 2012-03-01 o superiore. |
Valore | Facoltativa. Rappresenta il valore di una proprietà estesa dell'account di archiviazione. Ogni proprietà estesa deve contenere un nome e un valore definiti. È possibile avere un massimo di 50 coppie nome/valore per le proprietà estese e il valore di ciascuna proprietà contiene un massimo di 255 caratteri. Il Value elemento è disponibile solo utilizzando la versione 2012-03-01 o superiore. |
CustomDomains
Specifica i domini personalizzati associati all'account di archiviazione.
Nome elemento | Descrizione |
---|---|
CustomDomain | Specifica le informazioni relative a un dominio personalizzato associato all'account di archiviazione. |
Nome | Specifica il nome del dominio personalizzato. |
UseSubDomainName | Indica se la convalida di CNAME indiretta è abilitata. I valori possibili sono: - true - false |
Risposta
Nella risposta sono inclusi un codice di stato HTTP, un set di intestazioni per la risposta e il corpo di una risposta.
Codice di stato
Un'operazione completata correttamente restituisce 200 (OK). Per informazioni sui codici di stato, vedere stato di gestione del servizio e i codici di errore.
Intestazioni della risposta
Nella risposta per questa operazione sono incluse le intestazioni riportate di seguito; inoltre, possono essere incluse intestazioni HTTP standard aggiuntive. Tutte le intestazioni standard sono conformi alla specifica del protocollo HTTP/1.1.
Intestazione della risposta | Descrizione |
---|---|
x-ms-request-id |
Valore che identifica in modo univoco una richiesta eseguita nel servizio di gestione. Per un'operazione asincrona, è possibile chiamare Ottenere lo stato di operazione con il valore dell'intestazione per determinare se l'operazione è stata completata, ha avuto esito negativo o è ancora in corso. |
Corpo della risposta
Nessuna.
Osservazioni
Usare l'operazione Update Storage Account
per modificare la descrizione, l'etichetta o il valore dell'impostazione della replica geografica per un account di archiviazione. È possibile usare l'operazione Recupero delle proprietà dell'account di archiviazione per analizzare questi valori.
Esempio
L'esempio seguente consente di chiamare l'operazione Recupero delle proprietà dell'account di archiviazione per elencare i valori delle proprietà iniziali per l'account di archiviazione, aggiornare le proprietà Label
e Description
con una chiamata all'operazione Update Storage Account
, quindi visualizzare i risultati aggiornati con un'altra chiamata a Recupero delle proprietà dell'account di archiviazione. Modificare il valore della stringa Version
con la versione desiderata, il valore Thumbprint
sull'identificazione personale del certificato di gestione, il valore SubscriptionId
sull'identificatore di sottoscrizione e il valore ServiceName
nel valore sul nome dell'account di archiviazione per eseguire l'esempio.
namespace Microsoft.WindowsAzure.ServiceManagementRESTAPI.Samples { using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Security.Cryptography.X509Certificates; using System.Xml; using System.Xml.Linq; public class Program { // Set these constants with your values to run the sample. private const string Version = "2011-12-01"; private const string Thumbprint = "management-certificate-thumbprint"; private const string SubscriptionId = "subscription-identifier"; private const string ServiceName = "storage-account-name"; // This is the common namespace for all Service Management REST API XML data. private static XNamespace wa = "https://schemas.microsoft.com/windowsazure"; /// <summary> /// Gets or sets the certificate that matches the Thumbprint value. /// </summary> private static X509Certificate2 Certificate { get; set; } static void Main(string[] args) { try { Certificate = GetStoreCertificate(Thumbprint); // Get the initial property values for the storage account. // Convert the Label property to a readable value for display. XElement initialProperties = GetStorageAccountProperties(ServiceName); XElement labelElement = initialProperties.Descendants(wa + "Label").First(); labelElement.Value = labelElement.Value.FromBase64(); Console.WriteLine( "Storage Account Properties for {0}:{1}{2}", ServiceName, Environment.NewLine, initialProperties.ToString(SaveOptions.OmitDuplicateNamespaces)); // Update the label and description of the storage account. string label = String.Format("updated_{0}_label", ServiceName); string description = String.Format( "Updated description for {0}", ServiceName); UpdateStorageAccount(ServiceName, label, description, geoReplicationEnabled: false); // Get the updated property values for the storage account. // Convert the Label property to a readable value for display. XElement updatedProperties = GetStorageAccountProperties(ServiceName); labelElement = updatedProperties.Descendants(wa + "Label").First(); labelElement.Value = labelElement.Value.FromBase64(); Console.WriteLine( "Updated Storage Account Properties for {0}:{1}{2}", ServiceName, Environment.NewLine, updatedProperties.ToString(SaveOptions.OmitDuplicateNamespaces)); } catch (Exception ex) { Console.WriteLine("Exception caught in Main:"); Console.WriteLine(ex.Message); } Console.Write("Press any key to continue:"); Console.ReadKey(); } /// <summary> /// Calls the Get Storage Account Properties operation in the Service /// Management REST API for the specified subscription and storage account /// name and returns the StorageService XML element from the response. /// </summary> /// <param name="serviceName">The name of the storage account.</param> /// <returns>The StorageService XML element from the response.</returns> private static XElement GetStorageAccountProperties( string serviceName) { string uriFormat = "https://management.core.windows.net/{0}" + "/services/storageservices/{1}"; Uri uri = new Uri(String.Format(uriFormat, SubscriptionId, serviceName)); XDocument responseBody; InvokeRequest(uri, "GET", HttpStatusCode.OK, null, out responseBody); return responseBody.Element(wa + "StorageService"); } /// <summary> /// Calls the Update Storage Account operation in the Service Management /// REST API for the specified subscription, storage account name, new /// description, label, and geo-replication enabled setting. /// </summary> /// <param name="serviceName">The name of the storage account to update.</param> /// <param name="label">The new label for the storage account.</param> /// <param name="description">The new description for the storage account.</param> /// <param name="geoReplicationEnabled">The new geo-replication setting, if applicable. /// This optional parameter defaults to null.</param> private static void UpdateStorageAccount( string serviceName, string label, string description, bool? geoReplicationEnabled = null) { string uriFormat = "https://management.core.windows.net/{0}" + "/services/storageservices/{1}"; Uri uri = new Uri(String.Format(uriFormat, SubscriptionId, serviceName)); XDocument requestBody = new XDocument( new XDeclaration("1.0", "UTF-8", "no"), new XElement( wa + "UpdateStorageServiceInput", new XElement(wa + "Description", description), new XElement(wa + "Label", label.ToBase64()))); // Add the GeoReplicationEnabled element if the version supports it. if ((geoReplicationEnabled != null) && (String.CompareOrdinal(Version, "2011-12-01") >= 0)) { requestBody.Element(wa + "UpdateStorageServiceInput").Add( new XElement( wa + "GeoReplicationEnabled", geoReplicationEnabled.ToString().ToLowerInvariant())); } XDocument responseBody; InvokeRequest(uri, "PUT", HttpStatusCode.OK, requestBody, out responseBody); } /// <summary> /// Gets the certificate matching the thumbprint from the local store. /// Throws an ArgumentException if a matching certificate is not found. /// </summary> /// <param name="thumbprint">The thumbprint of the certificate to find.</param> /// <returns>The certificate with the specified thumbprint.</returns> private static X509Certificate2 GetStoreCertificate(string thumbprint) { List<StoreLocation> locations = new List<StoreLocation> { StoreLocation.CurrentUser, StoreLocation.LocalMachine }; foreach (var location in locations) { X509Store store = new X509Store("My", location); try { store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly); X509Certificate2Collection certificates = store.Certificates.Find( X509FindType.FindByThumbprint, thumbprint, false); if (certificates.Count == 1) { return certificates[0]; } } finally { store.Close(); } } throw new ArgumentException(string.Format( "A Certificate with Thumbprint '{0}' could not be located.", thumbprint)); } /// <summary> /// A helper function to invoke a Service Management REST API operation. /// Throws an ApplicationException on unexpected status code results. /// </summary> /// <param name="uri">The URI of the operation to invoke using a web request.</param> /// <param name="method">The method of the web request, GET, PUT, POST, or DELETE.</param> /// <param name="expectedCode">The expected status code.</param> /// <param name="requestBody">The XML body to send with the web request. Use null to send no request body.</param> /// <param name="responseBody">The XML body returned by the request, if any.</param> /// <returns>The requestId returned by the operation.</returns> private static string InvokeRequest( Uri uri, string method, HttpStatusCode expectedCode, XDocument requestBody, out XDocument responseBody) { responseBody = null; string requestId = String.Empty; HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri); request.Method = method; request.Headers.Add("x-ms-Version", Version); request.ClientCertificates.Add(Certificate); request.ContentType = "application/xml"; if (requestBody != null) { using (Stream requestStream = request.GetRequestStream()) { using (StreamWriter streamWriter = new StreamWriter( requestStream, System.Text.UTF8Encoding.UTF8)) { requestBody.Save(streamWriter, SaveOptions.DisableFormatting); } } } HttpWebResponse response; HttpStatusCode statusCode = HttpStatusCode.Unused; try { response = (HttpWebResponse)request.GetResponse(); } catch (WebException ex) { // GetResponse throws a WebException for 4XX and 5XX status codes response = (HttpWebResponse)ex.Response; } try { statusCode = response.StatusCode; if (response.ContentLength > 0) { using (XmlReader reader = XmlReader.Create(response.GetResponseStream())) { responseBody = XDocument.Load(reader); } } if (response.Headers != null) { requestId = response.Headers["x-ms-request-id"]; } } finally { response.Close(); } if (!statusCode.Equals(expectedCode)) { throw new ApplicationException(string.Format( "Call to {0} returned an error:{1}Status Code: {2} ({3}):{1}{4}", uri.ToString(), Environment.NewLine, (int)statusCode, statusCode, responseBody.ToString(SaveOptions.OmitDuplicateNamespaces))); } return requestId; } } /// <summary> /// Helpful extension methods for converting strings to and from Base-64. /// </summary> public static class StringExtensions { /// <summary> /// Converts a UTF-8 string to a Base-64 version of the string. /// </summary> /// <param name="s">The string to convert to Base-64.</param> /// <returns>The Base-64 converted string.</returns> public static string ToBase64(this string s) { byte[] bytes = System.Text.Encoding.UTF8.GetBytes(s); return Convert.ToBase64String(bytes); } /// <summary> /// Converts a Base-64 encoded string to UTF-8. /// </summary> /// <param name="s">The string to convert from Base-64.</param> /// <returns>The converted UTF-8 string.</returns> public static string FromBase64(this string s) { byte[] bytes = Convert.FromBase64String(s); return System.Text.Encoding.UTF8.GetString(bytes); } } }
Quando viene eseguito, il programma di esempio genera output simile al seguente:
Storage Account Properties for myexamplestorage1: <StorageService xmlns="https://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <Url>https://management.core.windows.net/01234567-89ab-cdef-0123-456789abcdef/services/storageservices/myexamplestorage1</Url> <ServiceName>myexamplestorage1</ServiceName> <StorageServiceProperties> <Description>myexamplestorage1 description</Description> <Location>North Central US</Location> <Label>My Example Label</Label> <Status>Created</Status> <Endpoints> <Endpoint>http://myexamplestorage1.blob.core.windows.net/</Endpoint> <Endpoint>http://myexamplestorage1.queue.core.windows.net/</Endpoint> <Endpoint>http://myexamplestorage1.table.core.windows.net/</Endpoint> </Endpoints> <GeoReplicationEnabled>true</GeoReplicationEnabled> <GeoPrimaryRegion>usnorth</GeoPrimaryRegion> <StatusOfPrimary>Available</StatusOfPrimary> <GeoSecondaryRegion>ussouth</GeoSecondaryRegion> <StatusOfSecondary>Available</StatusOfSecondary> </StorageServiceProperties> </StorageService> Updated Storage Account Properties for myexamplestorage1: <StorageService xmlns="https://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <Url>https://management.core.windows.net/01234567-89ab-cdef-0123-456789abcdef/services/storageservices/myexamplestorage1</Url> <ServiceName>myexamplestorage1</ServiceName> <StorageServiceProperties> <Description>Updated description for myexamplestorage1</Description> <Location>North Central US</Location> <Label>updated_myexamplestorage1_label</Label> <Status>Created</Status> <Endpoints> <Endpoint>http://myexamplestorage1.blob.core.windows.net/</Endpoint> <Endpoint>http://myexamplestorage1.queue.core.windows.net/</Endpoint> <Endpoint>http://myexamplestorage1.table.core.windows.net/</Endpoint> </Endpoints> <GeoReplicationEnabled>false</GeoReplicationEnabled> </StorageServiceProperties> </StorageService> Press any key to continue: