Update Storage Account异步操作更新指定的存储帐户的标签、说明,并启用或禁用指定的存储帐户的地理复制状态。

请求

可以按以下方式指定 Update Storage Account 请求。 请将 <subscription-id> 替换为你的订阅 ID,将 <service-name> 替换为你的存储帐户的名称。

方法 请求 URI
PUT https://management.core.windows.net/<subscription-id>/services/storageservices/<service-name>

你必须确保向管理服务发出的请求是安全的。 有关其他详细信息,请参阅 进行身份验证服务管理请求

URI 参数

无。

请求标头

下表介绍请求标头。

请求标头 说明
Content-Type 必需。 将此标头设置为 application/xml
x-ms-version 必需。 指定用于此请求的操作的版本。 必须将此标头的值设置为 01.06.11 或更高版本。 若要使用地域复制功能,版本至少应为“2012-03-01”。

若要使用自定义域功能,版本至少应为“2013-06-01”。

若要使用 SecondaryReadEnabled 功能,版本至少应为“2013-11-01”。

若要使用 AccountType 字段,版本至少应为“2014-06-01”。 请注意,以后将不再支持 GeoReplicationEnabledSecondaryReadEnabled - 其功能已包含在 AccountType 中。

有关版本控制标头的详细信息,请参阅 服务管理版本控制

请求正文

请求正文的格式如下所示:

  
<?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>  
  

下表说明了请求正文的元素。

元素名称 说明
Label 可选。 指定存储帐户的 Base-64 编码名称。 该标签的长度最长可以为 100 个字符。 该标签可用于标识存储帐户,以便进行跟踪。 必须为 Label 和/或 Description 指定一个值。
说明 可选。 存储帐户的说明。 该说明的长度最长可以为 1024 个字符。 必须为 Label 和/或 Description 指定一个值。
GeoReplicationEnabled 可选。 启用或禁用针对指定存储的地域复制。 如果设置为 true,则在多个地理位置间复制存储帐户中的数据,以便可在服务严重中断时迅速恢复。 如果设置为 false,则禁用地域复制。 如果在请求正文中不包含该元素,则当前值保持不变。 Important: 如果你启用了地域复制,则可以通过将该元素设置为 false 来选择禁用它。 禁用后,你的数据将不再复制到辅助数据中心,并且将删除辅助位置中的所有数据。 如果在禁用地域复制后启用地域复制,将导致针对将数据的当前副本复制到辅助数据中心而对存储帐户计费。 在数据的现有副本复制到辅助数据中心后,将对更新进行地域复制而不收取额外费用。

只有使用 01.03.12 或更高版本时,GeoReplicationEnabled 元素才可用并且将被版本为 2014-06-01 或更高版本的 AccountType 元素替换。
ExtendedProperties 指定已添加到存储帐户的扩展属性的名称和值。
CustomDomains 指定与存储帐户关联的自定义域。

仅在 2013-06-01 或更高版本中才可以使用 CustomDomains 元素。
SecondaryReadEnabled 指示为存储帐户启用了辅助读。

可能的值有:

- true
- false

只有使用 2013/11/1 或更高版本时,SecondaryReadEnabled 元素才可用并且将被版本为 2014-06-01 或更高版本的 AccountType 元素替换。
AccountType 指定帐户是否支持本地冗余存储、地域冗余存储或读取访问地域冗余存储。 在更新存储帐户时没有区域冗余存储这一选项。

可能的值有:

- Standard_LRS
- Standard_GRS
- Standard_RAGRS

只有使用 2014-06-01 或更高版本时,AccountType 元素才可用,并且会替换 SecondaryReadEnabled 和 GeoReplicationEnabled 元素。 Note:  Standard_ZRSPremium_LRS 帐户类型不是选项,因为这些帐户不能更改为任何其他帐户类型。 此外,所有其他帐户类型也不能更改为 Standard_ZRSPremium_LRS

ExtendedProperties

指定已添加到存储帐户的扩展属性的名称和值。

元素名称 说明
名称 可选。 表示某个扩展的存储帐户属性的名称。 每个扩展属性都必须有定义的名称和值。 最多可有 50 个扩展属性的名称/值对。

Name 元素的最大长度为 64 个字符,仅字母数字字符和下划线在 Name 中有效,并且该名称必须以字母开头。 Name 元素中包含其他字符、以非字母字符开头或输入的名称与同一存储帐户拥有的另一扩展属性同名,将导致状态代码 400(错误请求)错误。

仅在 01.03.12 版或更高版本中才可以使用 Name 元素。
可选。 表示某个扩展的存储帐户属性的值。 每个扩展属性都必须有定义的名称和值。 最多可有 50 个扩展属性的名称/值对,并且每个扩展属性值的最大长度为 255 个字符。

仅在 01.03.12 版或更高版本中才可以使用 Value 元素。

CustomDomains

指定与存储帐户关联的自定义域。

元素名称 说明
CustomDomain 指定与存储帐户关联的自定义域的信息。
名称 指定自定义域的名称。
UseSubDomainName 指示是否启用间接 CName 验证。

可能的值有:

- true
- false

响应

响应包括 HTTP 状态代码、一组响应标头和响应正文。

状态代码

此操作成功后返回状态代码 200(正常)。 有关状态代码的信息,请参阅 服务管理状态和错误代码

响应标头

此操作的响应包括以下标头。 该响应还可能包括其他标准 HTTP 标头。 所有标准标头都符合 HTTP/1.1 协议规范

响应标头 说明
x-ms-request-id 一个值,它唯一地标识对管理服务做出的请求。 对于异步操作,可使用此标头的值调用获取操作状态以确定操作是已完成、已失败还是仍在进行中。

响应正文

无。

备注

使用 Update Storage Account 操作可更改存储帐户的说明、标签或地域复制设置值。 你可以使用 获取存储帐户属性 操作查看这些值。

示例

下面的示例调用 获取存储帐户属性 操作以便列出存储帐户的初始属性值,通过调用 Label 操作更新 DescriptionUpdate Storage Account 属性,然后通过另一个对 获取存储帐户属性 的调用显示更新后的结果。 将 Version 字符串的值更改为所需版本,将 Thumbprint 值更改为你的管理证书的指纹,将 SubscriptionId 更改为你的订阅标识符,并且将 ServiceName 值更改为用于运行该示例的你的存储帐户的名称。

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); } } }  
  

运行后,示例程序将生成类似于以下内容的输出:

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:  

请参阅

获取存储帐户属性