列出儲存體帳戶

 

List Storage Accounts 作業會列出指定的訂閱中可用的儲存體帳戶。

要求

List Storage Accounts 要求可能會以下面方式指定。 取代 <subscription-id> 與您的訂用帳戶 id。

方法 要求 URI
GET https://management.core.windows.net/<subscription-id>/services/storageservices

您必須確定對管理服務發出的要求是安全的。 如需詳細資訊,請參閱 驗證服務管理要求

URI 參數

無。

要求標頭

下表描述要求標頭。

要求標頭 說明
x-ms-version 必要項。 指定用於這個要求的作業版本。 此標頭應該設定為 2009年-10-01 或更高版本。 如需有關版本設定標頭的詳細資訊,請參閱 服務管理版本控制

要求本文

無。

回應

回應包括 HTTP 狀態碼、一組回應標頭和回應主體。

狀態碼

成功的作業會傳回狀態碼 200 (OK)。

如需狀態碼的相關資訊,請參閱 服務管理狀態和錯誤碼

回應標頭

這項作業的回應包括下列標頭。 回應也可能包括其他標準 HTTP 標頭。 所有標準標頭符合 HTTP/1.1 通訊協定規格

回應標頭 說明
x-ms-request-id 唯一識別對管理服務發出之要求的值。

回應主體

回應主體的格式如下:

  
<?xml version="1.0" encoding="utf-8"?> <StorageServices xmlns=”https://schemas.microsoft.com/windowsazure”> <StorageService> <Url>storage-service-address</Url> <ServiceName>storage-service-name</ServiceName> <StorageServiceProperties> <Description>description</Description> <AffinityGroup>affinity-group</AffinityGroup> <Location>location-of-storage-account</Location> <Label>base64-encoded-label</Label> <Status>status</Status> <Endpoints> <Endpoint>storage-service-blob-endpoint</Endpoint> <Endpoint>storage-service-queue-endpoint</Endpoint> <Endpoint>storage-service-table-endpoint</Endpoint> <Endpoint>storage-service-file-endpoint</Endpoint> </Endpoints> <GeoReplicationEnabled>geo-replication-indicator</GeoReplicationEnabled> <GeoPrimaryRegion>primary-region</GeoPrimaryRegion> <StatusOfPrimary>primary-status</StatusOfPrimary> <LastGeoFailoverTime>DateTime</LastGeoFailoverTime> <GeoSecondaryRegion>secondary-region</GeoSecondaryRegion> <StatusOfSecondary>secondary-status</StatusOfSecondary> <CreationTime>time-of-creation</CreationTime> <CustomDomains> <CustomDomain> <Name>name-of-custom-domain</Name> </CustomDomain> </CustomDomains> <SecondaryReadEnabled>secondary-read-indicator</SecondaryReadEnabled> <SecondaryEndpoints> <Endpoint>storage-secondary-service-blob-endpoint</Endpoint> <Endpoint>storage-secondary-service-queue-endpoint</Endpoint> <Endpoint>storage-secondary-service-table-endpoint</Endpoint> </SecondaryEndpoints> <AccountType>type-of-storage-account</AccountType> </StorageServiceProperties> <ExtendedProperties> <ExtendedProperty> <Name>property-name</Name> <Value>property-value</Value> </ExtendedProperty> </ExtendedProperties> </StorageService> </StorageServices>  
  

下表描述回應本文的元素。

元素名稱 說明
URL 指定儲存體帳戶的 URI。
ServiceName 指定儲存體帳戶的名稱。 這個名稱是 DNS 首碼名稱,可用來存取儲存體帳戶中的 Blob、佇列和資料表。

例如,如果服務名稱是 MyStorageAccount 您可以藉由呼叫來存取 blob 容器: http://MyStorageAccount.blob.core.windows.net/mycontainer/
StorageServiceProperties 指定儲存體帳戶的屬性。
ExtendedProperties 指定已加入至儲存體帳戶之擴充屬性的名稱和值。

StorageServiceProperties

指定儲存體帳戶的屬性。

元素名稱 說明
說明 選擇項。 儲存體帳戶的描述。 描述的長度最多可以有 1024 個字元。

 Description 項目只是使用 2012年-03-01 版或更高版本。
AffinityGroup Location 未指定。 與這個訂閱相關聯之現有同質群組的名稱。 這個名稱是 GUID,可以藉由檢查所傳回的回應主體的名稱項目擷取 列出同質群組 作業。

 AffinityGroup 項目只是使用 2012年-03-01 版或更高版本。
位置 AffinityGroup 未指定。 即將建立儲存體帳戶的位置。

 Location 項目只是使用 2012年-03-01 版或更高版本。
Label 必要項。 託管服務的 Base-64 編碼格式名稱。 名稱的長度最多可以有 100 個字元。 在您進行追蹤時,此名稱可用來識別儲存體帳戶。

 Label 項目只是使用 2012年-03-01 版或更高版本。
狀態 儲存體帳戶的狀態。 可能的值為:

- Creating
- Created
- Deleting
- Deleted
- Changing
- ResolvingDns

 Status 項目只是使用 2012年-03-01 版或更高版本。
端點 Blob、資料表、佇列和檔案端點。

附註 1:檔案端點處於預覽模式,而且只會針對已啟用預覽的訂用傳回。

也請注意該附註 2: Standard_ZRS 帳戶類型,傳回 blob 端點。 此外,ZRS 僅支援區塊 Blob (不支援分頁 Blob),因此與 IaaS VM 不相容。

附註 3:對於 Premium_LRS 帳戶類型,只會傳回 Blob 端點。
GeoReplicationEnabled 指出儲存體帳戶中的資料是否在多個地理位置之間複寫,以便在面臨重大服務中斷的情況時啟用恢復功能。 值是 true 如果地理複寫已啟用,否則為 false

 GeoReplicationEnabled 項目才提供使用 2012年-03-01 版或更高版本和取代由 AccountType 元素與 2014年-06-01 版或更高版本。
GeoPrimaryRegion 表示儲存體帳戶目前所在的主要地理區域。

 GeoPrimaryRegion 項目只是使用 2012年-03-01 版或更高版本。
StatusOfPrimary 指出主要儲存體地區是否可用。

可能的值為:

- Available
- Unavailable

 StatusOfPrimary 項目只是使用 2013年-11-01 版或更高版本。
LastGeoFailoverTime 表示容錯移轉至次要地區之最新執行個體的時間戳記。 如果有多次容錯移轉,只會保留最新的容錯移轉日期和時間。

傳回的時間戳記格式為:[4DigitYear]-[2DigitMonth]-[2DigitDay]T[2DigitMinute]:[2DigitSecond]:[7DigitsOfPrecision]Z

例如: < LastGeoFailoverTime > 2010年-01-18T13:15:30.0000000Z < / LastGeoFailoverTime >

如果沒有容錯移轉的執行個體,就不會傳回 LastGeoFailoverTime。

 LastGeoFailoverTime 項目只是使用 2012年-03-01 版或更高版本。
GeoSecondaryRegion 表示正在複寫儲存體帳戶的地理區域。

如果此帳戶的地理複寫為「關閉」,就不會傳回 GeoSecondaryRegion 元素。

 GeoSecondaryRegion 項目只是使用 2012年-03-01 版或更高版本。
StatusOfSecondary 指出次要儲存體地區是否可用。

 StatusOfSecondary 項目只是使用 2013年-11-01 版或更高版本。

可能的值為:

- Available
- Unavailable
CreationTime 指定建立儲存體帳戶的時間。
CustomDomains 指定與儲存體帳戶相關聯的自訂網域。

 CustomDomains 項目只是使用 2013年-06-01 版或更高版本。
SecondaryReadEnabled 指出儲存體帳戶已啟用次要讀取。

可能的值為:

- true
- false

 SecondaryReadEnabled 項目只有使用 2013年-11-01 版或更高且取代由 AccountType 元素與 2014年-06-01 版或更高版本。
SecondaryEndpoints 指定儲存體帳戶的次要端點。

 SecondaryEndpoints 項目只是使用 2013年-11-01 版或更高版本。
AccountType 指定帳戶是否支援本機備援儲存體、地理備援儲存體、區域備援儲存體或讀取權限地理備援儲存體。

可能的值為:

- Standard_LRS
- Standard_ZRS
- Standard_GRS
- Standard_RAGRS
- Premium_LRS

 AccountType 項目只是使用 2014年-06-01 版或更高版本,並取代 SecondaryReadEnabled 和 GeoReplicationEnabled 元素。

 Premium_LRS 項目只是使用 2014年-10-01 版或更高版本。

端點

指定儲存體帳戶的端點。

元素名稱 說明
Endpoint 包含採用下列格式的 blob 服務端點: https://<storage-service-name>.blob.core.windows.net

 Endpoint 項目只是使用 2012年-03-01 版或更高版本。 HTTP 端點是使用 2014-04-01 版或更低版本傳回。
Endpoint 包含採用下列格式的佇列服務端點: https://<storage-service-name>.queue.core.windows.net

 Endpoint 項目只是使用 2012年-03-01 版或更高版本。 HTTP 端點是使用 2014-04-01 版或更低版本傳回。
Endpoint 包含採用下列格式的表格服務端點: https://<storage-service-name>.table.core.windows.net

 Endpoint 項目只是使用 2012年-03-01 版或更高版本。 HTTP 端點是使用 2014-04-01 版或更低版本傳回。
Endpoint 包含採用下列格式的檔案服務端點: https://<storage-service-name>.file.core.windows.net

 Endpoint 項目只是使用 2012年-03-01 版或更高版本。 HTTP 端點是使用 2014-04-01 版或更低版本傳回。

CustomDomains

指定與儲存體帳戶相關聯的自訂網域。

元素名稱 說明
CustomDomain 指定與儲存體帳戶相關聯之自訂網域的相關資訊。
名稱 指定自訂網域的名稱。

SecondaryEndpoints

指定儲存體帳戶的次要端點。

元素名稱 說明
Endpoint 包含採用下列格式的 blob 次要服務端點: https://<storage-secondary-service-name>.blob.core.windows.net

HTTP 端點是使用 2014-04-01 版或更低版本傳回。
Endpoint 包含採用下列格式的佇列服務端點: https://<storage-secondary-service-name>.queue.core.windows.net

HTTP 端點是使用 2014-04-01 版或更低版本傳回。
Endpoint 包含採用下列格式的表格服務端點: https://<storage-secondary-service-name>.table.core.windows.net

HTTP 端點是使用 2014-04-01 版或更低版本傳回。

ExtendedProperties

指定已加入至儲存體帳戶之擴充屬性的名稱和值。

元素名稱 說明
名稱 選擇項。 代表擴充儲存體帳戶屬性的名稱。 每個擴充屬性都必須具有已定義的名稱和值。 您最多可以擁有 50 個擴充屬性名稱/值組。

Name 元素的長度上限為 64 個字元、只有英數字元和底線可用於 Name,而且名稱必須以字母當做開頭。 如果您嘗試使用其他字元、以非字母字元當做 Name 的開頭,或者輸入的名稱與相同儲存體帳戶所擁有之其他擴充屬性的名稱完全相同,就會產生狀態碼 400 (不正確的要求) 錯誤。

 Name 項目只是使用 2012年-03-01 版或更高版本。
選擇項。 代表擴充儲存體帳戶屬性的值。 每個擴充屬性都必須具有已定義的名稱和值。 您最多可以擁有 50 個擴充屬性名稱/值組,而且每個擴充屬性值的長度上限為 255 個字元。

 Value 項目只是使用 2012年-03-01 版或更高版本。

備註

如果 x-ms-version 是 2012年-03-01 或更新版本和同質群組建立在已被取代的其中一個 Anywhere US, ,Anywhere Europe, ,Anywhere Asia 區域 Location 元素就會傳回這個同質群組目前的配置的位置。

List Storage Accounts 作業可以用來取得要用於儲存體帳戶上的其他作業例如 Uri 取得儲存體帳戶屬性, ,取得儲存體帳戶金鑰, ,刪除儲存體帳戶, ,和 更新儲存體帳戶

範例

下列範例程式會採用訂用帳戶識別碼、相關聯的管理憑證指紋及作業版本字串,並且將儲存體帳戶的清單列印到主控台。 初始化 msVersion, ,subscriptionId, ,和 thumbprint 具有自己的值來執行範例程式碼的變數。 這個範例會使用 x-ms-version 2011年-10-01。

using System; using System.Collections.Generic; using System.Net; using System.Security.Cryptography.X509Certificates; using System.Xml; using System.Xml.Linq; class Program { static void Main(string[] args) { string msVersion = "2011-10-01"; string subscriptionId = "subscription-id-guid"; string thumbprint = "certificate-thumbprint"; try { // Obtain the certificate with the specified thumbprint X509Certificate2 certificate = GetCertificate(thumbprint); ListStorageAccountsExample(subscriptionId, certificate, msVersion); } catch (Exception ex) { Console.WriteLine("Exception caught in Main:"); Console.WriteLine(ex.Message); } } public static X509Certificate2 GetCertificate(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)); } public static void ListStorageAccountsExample( string subscriptionId, X509Certificate2 certificate, string version) { string uriFormat = "https://management.core.windows.net/{0}/services/storageservices"; Uri uri = new Uri(String.Format(uriFormat, subscriptionId)); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri); request.Method = "GET"; request.Headers.Add("x-ms-version", version); request.ClientCertificates.Add(certificate); request.ContentType = "application/xml"; XDocument responseBody = null; HttpStatusCode statusCode; HttpWebResponse response; try { response = (HttpWebResponse)request.GetResponse(); } catch (WebException ex) { // GetResponse throws a WebException for 400 and 500 status codes response = (HttpWebResponse)ex.Response; } statusCode = response.StatusCode; if (response.ContentLength > 0) { using (XmlReader reader = XmlReader.Create(response.GetResponseStream())) { responseBody = XDocument.Load(reader); } } response.Close(); if (statusCode.Equals(HttpStatusCode.OK)) { XNamespace wa = "https://schemas.microsoft.com/windowsazure"; XElement storageServices = responseBody.Element(wa + "StorageServices"); int storageCount = 0; foreach (XElement storageService in storageServices.Elements(wa + "StorageService")) { string url = storageService.Element(wa + "Url").Value; string serviceName = storageService.Element(wa + "ServiceName").Value; Console.WriteLine( "Location[{0}]{1}  Name: {2}{1}  DisplayName: {3}", storageCount++, Environment.NewLine, url, serviceName); } } else { Console.WriteLine("Call to List Storage Accounts returned an error:"); Console.WriteLine("Status Code: {0} ({1}):{2}{3}", (int)statusCode, statusCode, Environment.NewLine, responseBody.ToString(SaveOptions.OmitDuplicateNamespaces)); } return; } }