Share via


Update Storage Account

 

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 必須です。 この要求に使用する操作のバージョンを指定します。 このヘッダーの値を設定する必要があります 2011年-06-01 またはそれ以降。 geo レプリケーション機能を使用するには、バージョンが "2012-03-01" 以上である必要があります。

カスタム ドメイン機能を使用するには、バージョンが "2013-06-01" 以上である必要があります。

SecondaryReadEnabled 機能を使用するには、バージョンが "2013-11-01" 以上である必要があります。

そのバージョンは、少なくとも「2014年-06-01」を使用するをするか、 AccountType フィールドです。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, 、あるいはその両方です。
説明 省略可能です。 ストレージ アカウントの説明。 説明の最大長は 1,024 文字です。 いずれかの値を指定する必要があります Label または Description, 、あるいはその両方です。
GeoReplicationEnabled 省略可能です。 指定されたストレージのジオレプリケーションを有効または無効にします。 場合に設定 true, 、サービスの致命的な損失が発生した場合に回復できるように、1 つ以上の地理的な場所の間でストレージ アカウント内のデータをレプリケートします。 場合に設定 false, 、地理的レプリケーションが無効になっています。 この要素が要求本文に含まれていない場合は、現在の値がそのまま使用されます。 Important: ジオレプリケーションを有効にしている場合、この要素を false に設定することで無効にすることができます。 無効にした場合、データはセカンダリ データ センターにレプリケートされなくなり、そのデータ センターのすべてのデータが削除されます。 無効になっているジオレプリケーションを有効にすると、データの現在のコピーをセカンダリ データ センターにレプリケートするため、ストレージ アカウントに課金されます。 データの既存のコピーをセカンダリ データ センターにレプリケートした後は、追加料金なしで更新のジオレプリケーションが実行されます。

 GeoReplicationEnabled 要素は、バージョン 2012年-03-01 を使用して利用可能なまたはそれ以上し、は、バージョン 2014年-06-01 AccountType 要素によって置き換えられた以降。
ExtendedProperties ストレージ アカウントに追加された拡張プロパティの名前と値を指定します。
CustomDomains ストレージ アカウントに関連付けられたカスタム ドメインを指定します。

 CustomDomains 要素ではバージョン 2013年-06-01 を使用して利用可能なまたはそれ以上のみです。
SecondaryReadEnabled ストレージ アカウントでセカンダリ読み取りが有効になっていることを示します。

次の値をとります。

- true
- false

 SecondaryReadEnabled 要素はバージョン 2013年-11-01 を使用して利用可能な以降だけとは、バージョン 2014年-06-01 AccountType 要素によって置き換えられた以降。
AccountType アカウントが、ローカル冗長ストレージ、地理冗長ストレージ、読み取りアクセス地理冗長ストレージのいずれをサポートするかを指定します。 ゾーン冗長ストレージは、ストレージ アカウントを更新する際のオプションではありません。

次の値をとります。

- Standard_LRS
- Standard_GRS
- Standard_RAGRS

 AccountType 要素ではバージョン 2014年-06-01 を使用して利用可能なまたはそれ以上のみと SecondaryReadEnabled および GeoReplicationEnabled 要素に置き換えられます。 Note:  Standard_ZRSPremium_LRS 勘定科目の種類がオプションでないため、これらのアカウントを他の勘定科目の種類を変更することはできません。 その他のすべての勘定科目の種類を変更できません Standard_ZRS または Premium_LRSです。

ExtendedProperties

ストレージ アカウントに追加された拡張プロパティの名前と値を指定します。

要素名 説明
名前 省略可能です。 ストレージ アカウントの拡張プロパティの名前を表します。 各拡張プロパティには、定義済みの名前と値の両方が必要です。 拡張プロパティの名前と値のペアは最大 50 組使用できます。

Name 要素の最大長は 64 文字です。Name では英数字とアンダースコアのみが有効であり、名前の先頭にはアルファベットを使用する必要があります。 他の文字を使用しようとした場合、Name の先頭がアルファベット以外の文字の場合、または同じストレージ アカウントが所有する別の拡張プロパティの名前と同一の名前を入力した場合は、ステータス コード 400 (Bad Request) のエラーが発生します。

 Name 要素で、バージョン 2012年-03-01 を使用して利用可能なまたはそれ以上のみです。
省略可能です。 ストレージ アカウントの拡張プロパティの値を表します。 各拡張プロパティには、定義済みの名前と値の両方が必要です。 拡張プロパティの名前と値のペアは最大 50 組使用できます。各拡張プロパティ値の最大長は 255 文字です。

 Value 要素で、バージョン 2012年-03-01 を使用して利用可能なまたはそれ以上のみです。

CustomDomains

ストレージ アカウントに関連付けられたカスタム ドメインを指定します。

要素名 説明
CustomDomain ストレージ アカウントに関連付けられたカスタム ドメインに関する情報を指定します。
名前 カスタム ドメインの名前を指定します。
UseSubDomainName 間接 CName 検証が有効かどうかを示します。

次の値をとります。

- true
- false

応答

応答には、HTTP ステータス コード、一連の応答ヘッダー、および応答本文が含まれています。

ステータス コード

操作が正常に終了では、ステータス コード 200 (OK) を返します。 状態コードについては、次を参照してください。 サービス管理のステータス コードとエラー コードです。

応答ヘッダー

この操作の応答には、次のヘッダーが含まれています。 追加の標準 HTTP ヘッダーが応答に含まれていることもあります。 すべての標準ヘッダーに準拠している、 http/1.1 プロトコル仕様です。

応答ヘッダー 説明
x-ms-request-id 管理サービスに対して行われた要求を一意に識別する値。 非同期操作を呼び出すことができます 操作の状態を取得します。 、操作が完了するかどうかを判断するヘッダーの値を含むが失敗、または進行中です。

応答本文

ありません。

解説

使用して、 Update Storage Account ストレージ アカウントの説明、ラベル、または地理的レプリケーションの設定値を変更する操作。 使用することができます、 Get Storage Account Properties 操作をこれらの値を確認します。

使用例

次の例では、 Get Storage Account Properties 操作をストレージ アカウントの初期プロパティの値を一覧表示を更新、 LabelDescription プロパティへの呼び出しで、 Update Storage Account 操作は、更新後の結果を別の呼び出しでしが表示されます。 Get Storage Account Propertiesです。 値を変更、 Version を目的のバージョンでは、文字列、 Thumbprint 値、[管理証明書のサムプリントに、 SubscriptionId をサブスクリプション id、および 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:  

参照

Get Storage Account Properties