저장소 계정 삭제

 

Delete Storage Account 비동기 작업은 지정 된 저장소 계정을 삭제 합니다.

요청

Delete Storage Account 요청을 다음과 같이 지정할 수 있습니다. 대체 <subscription-id> 를 구독 ID로, 및 <service-name> 저장소 계정의 이름으로 합니다.

메서드

요청 URI

삭제

https://management.core.windows.net/<subscription-id>/services/storageservices/<service-name>

요청 된 관리 서비스는 안전한 지 확인 해야 합니다. 자세한 내용은 참조 하십시오. 서비스 관리 요청 인증합니다.

URI 매개 변수

None입니다.

요청 헤더

다음 표에서 요청 헤더에 설명 합니다.

응답 헤더

설명

x-ms-version

필요합니다. 이 요청에 대해 사용 하 여 작업의 버전을 지정 합니다. 이 헤더의 값 설정 해야 2011-06-01 이상. 버전 관리 헤더에 대 한 자세한 내용은 참조 서비스 관리 버전 관리합니다.

요청 본문

None입니다.

응답

응답에는 HTTP 상태 코드, 응답 헤더 집합 및 응답 본문이 포함 되어 있습니다.

상태 코드

작업에 성공 하면 상태 코드 200 (OK)을 반환합니다. 상태 코드에 대 한 정보를 참조 하십시오. 서비스 관리 상태 및 오류 코드합니다.

응답 헤더

이 작업에 대 한 응답에는 다음 헤더가 포함 됩니다. 응답 추가 표준 HTTP 헤더가 포함 될 수도 있습니다. 모든 표준 헤더 준수 하는 HTTP/1.1 프로토콜 사양을https://go.microsoft.com/fwlink/?linkid=150478합니다.

응답 헤더

설명

x-ms-request-id

관리 서비스에 대 한 요청을 고유 하 게 식별 하는 값입니다. 비동기 작업을 호출할 수 있습니다 작업 상태 가져오기 작업이 완료 되었는지 확인 하려면 헤더의 값, 실패 또는 아직 진행 중입니다.

응답 본문

None입니다.

설명

사용 하는 Delete Storage Account 이름별으로 저장소 계정을 삭제 하는 작업이 있습니다. 삭제 된 저장소 계정에 저장 된 데이터를 복구할 수 없으므로 및 삭제 된 저장소 계정 이름은 다른 사용자가 사용할 수 있습니다.

저장소 계정을 삭제 하기 전에 모든 OS 이미지, VM 이미지와 계정에 있는 디스크를 삭제 합니다. 비동기 작업은 저장소 계정에서 아티팩트를 삭제 하는 데 사용 됩니다. 사용할 수는 작업 상태 가져오기 작업을 저장소 계정 삭제를 시도 하기 전에 작업이 완료 되었는지 확인 합니다. 저장소 계정을 삭제할 수까지 모든 작업에 대해 최대 15 분까지 걸릴 수 있습니다.

예제

다음 예제 프로그램에서는 구독 id는 연결 된 관리 인증서 지문, 작업 버전, 및는 저장소 계정 이름 및 호출 된 Delete Storage Account 명명 된 저장소 계정을 제거 하는 작업입니다. 초기화는 Version 버전 헤더 문자열, 상수 SubscriptionId 구독에 대 한 GUID 식별자를 가진 Thumbprint 관리 인증서 지문 값을 가진 및 ServiceName 예제 코드를 실행 하려면 삭제 될 저장소 계정의 이름으로 합니다.

using System;
using System.Collections.Generic;
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-10-01";
    private const string Thumbprint = "management-certificate-thumbprint";
    private const string SubscriptionId = "subscription-id-guid";
    private const string ServiceName = "storage-account-name";

    /// <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 = GetCertificate(Thumbprint);

            DeleteStorageAccount(SubscriptionId, ServiceName);
            Console.WriteLine("Storage Account {0} deleted.", ServiceName);
        }
        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 Delete Storage Account operation in the Service Management
    /// REST API for the specified subscription and storage account name.
    /// Throws an ApplicationException on status code results other than OK.
    /// </summary>
    /// <param name="subscriptionId">The subscription identifier.</param>
    /// <param name="serviceName">The name of the storage account to delete.</param>
    private static void DeleteStorageAccount(
        string subscriptionId,
        string serviceName)
    {
        string uriFormat = "https://management.core.windows.net/{0}/services/storageservices/{1}";
        Uri uri = new Uri(String.Format(uriFormat, subscriptionId, serviceName));

        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
        request.Method = "DELETE";
        request.Headers.Add("x-ms-version", Version);
        request.ClientCertificates.Add(Certificate);
        request.ContentType = "application/xml";

        XDocument responseBody = null;
        HttpStatusCode statusCode = HttpStatusCode.Unused;
        HttpWebResponse response;
        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);
                }
            }
        }
        finally
        {
            response.Close();
        }

        if (!statusCode.Equals(HttpStatusCode.OK))
        {
            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;
    }

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

이 예제 프로그램에서는 다음과 유사한 결과가 생성 됩니다.

Storage Account myexamplestorage1 deleted.
Press any key to continue: