Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AutoPR storage/resource-manager] [Storage] Support Failover #3510

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions azure-mgmt-storage/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
include *.rst
include azure/__init__.py
include azure/mgmt/__init__.py

Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from .list_account_sas_response_py3 import ListAccountSasResponse
from .service_sas_parameters_py3 import ServiceSasParameters
from .list_service_sas_response_py3 import ListServiceSasResponse
from .get_last_sync_time_result_py3 import GetLastSyncTimeResult
from .proxy_resource_py3 import ProxyResource
from .azure_entity_resource_py3 import AzureEntityResource
from .resource_py3 import Resource
Expand Down Expand Up @@ -90,6 +91,7 @@
from .list_account_sas_response import ListAccountSasResponse
from .service_sas_parameters import ServiceSasParameters
from .list_service_sas_response import ListServiceSasResponse
from .get_last_sync_time_result import GetLastSyncTimeResult
from .proxy_resource import ProxyResource
from .azure_entity_resource import AzureEntityResource
from .resource import Resource
Expand Down Expand Up @@ -130,6 +132,7 @@
Permissions,
HttpProtocol,
SignedResource,
ReplicationStatus,
PublicAccess,
LeaseStatus,
LeaseState,
Expand Down Expand Up @@ -171,6 +174,7 @@
'ListAccountSasResponse',
'ServiceSasParameters',
'ListServiceSasResponse',
'GetLastSyncTimeResult',
'ProxyResource',
'AzureEntityResource',
'Resource',
Expand Down Expand Up @@ -210,6 +214,7 @@
'Permissions',
'HttpProtocol',
'SignedResource',
'ReplicationStatus',
'PublicAccess',
'LeaseStatus',
'LeaseState',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------

from msrest.serialization import Model


class GetLastSyncTimeResult(Model):
"""The response from the get last synctime operation.

Variables are only populated by the server, and will be ignored when
sending a request.

:ivar status: The status of the secondary location of the Storage Account.
Live: Indicates that the secondary location is active and operational;
Bootstrap: Indicates initial synchronization from the primary location to
the secondary location is in progress, this typically occurs when
replication is first enabled; Unavailable: Indicates that the secondary
location is temporarily unavailable. Possible values include: 'Live',
'Bootstrap', 'Unavailable'
:vartype status: str or
~azure.mgmt.storage.v2018_07_01.models.ReplicationStatus
:ivar last_sync_time: All primary writes preceding this value are
guaranteed to be replicated to secondary. Primary writes after this point
in time may or may not be replicated. It is the minimum last sync time of
the account’s Blob/Table/Queue/File endpoints. The value may be account’s
creation time if LastSyncTime is not available. This can happen if the
replication status is bootstrap or unavailable.
:vartype last_sync_time: datetime
"""

_validation = {
'status': {'readonly': True},
'last_sync_time': {'readonly': True},
}

_attribute_map = {
'status': {'key': 'status', 'type': 'str'},
'last_sync_time': {'key': 'lastSyncTime', 'type': 'iso-8601'},
}

def __init__(self, **kwargs):
super(GetLastSyncTimeResult, self).__init__(**kwargs)
self.status = None
self.last_sync_time = None
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------

from msrest.serialization import Model


class GetLastSyncTimeResult(Model):
"""The response from the get last synctime operation.

Variables are only populated by the server, and will be ignored when
sending a request.

:ivar status: The status of the secondary location of the Storage Account.
Live: Indicates that the secondary location is active and operational;
Bootstrap: Indicates initial synchronization from the primary location to
the secondary location is in progress, this typically occurs when
replication is first enabled; Unavailable: Indicates that the secondary
location is temporarily unavailable. Possible values include: 'Live',
'Bootstrap', 'Unavailable'
:vartype status: str or
~azure.mgmt.storage.v2018_07_01.models.ReplicationStatus
:ivar last_sync_time: All primary writes preceding this value are
guaranteed to be replicated to secondary. Primary writes after this point
in time may or may not be replicated. It is the minimum last sync time of
the account’s Blob/Table/Queue/File endpoints. The value may be account’s
creation time if LastSyncTime is not available. This can happen if the
replication status is bootstrap or unavailable.
:vartype last_sync_time: datetime
"""

_validation = {
'status': {'readonly': True},
'last_sync_time': {'readonly': True},
}

_attribute_map = {
'status': {'key': 'status', 'type': 'str'},
'last_sync_time': {'key': 'lastSyncTime', 'type': 'iso-8601'},
}

def __init__(self, **kwargs) -> None:
super(GetLastSyncTimeResult, self).__init__(**kwargs)
self.status = None
self.last_sync_time = None
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ class StorageAccount(TrackedResource):
:param is_hns_enabled: Account HierarchicalNamespace enabled if sets to
true.
:type is_hns_enabled: bool
:ivar failover_in_progress: If the failover is in progress, the value will
be true, otherwise, it will be null.
:vartype failover_in_progress: bool
"""

_validation = {
Expand All @@ -127,6 +130,7 @@ class StorageAccount(TrackedResource):
'encryption': {'readonly': True},
'access_tier': {'readonly': True},
'network_rule_set': {'readonly': True},
'failover_in_progress': {'readonly': True},
}

_attribute_map = {
Expand Down Expand Up @@ -154,6 +158,7 @@ class StorageAccount(TrackedResource):
'enable_https_traffic_only': {'key': 'properties.supportsHttpsTrafficOnly', 'type': 'bool'},
'network_rule_set': {'key': 'properties.networkAcls', 'type': 'NetworkRuleSet'},
'is_hns_enabled': {'key': 'properties.isHnsEnabled', 'type': 'bool'},
'failover_in_progress': {'key': 'properties.failoverInProgress', 'type': 'bool'},
}

def __init__(self, **kwargs):
Expand All @@ -177,3 +182,4 @@ def __init__(self, **kwargs):
self.enable_https_traffic_only = kwargs.get('enable_https_traffic_only', None)
self.network_rule_set = None
self.is_hns_enabled = kwargs.get('is_hns_enabled', None)
self.failover_in_progress = None
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ class StorageAccount(TrackedResource):
:param is_hns_enabled: Account HierarchicalNamespace enabled if sets to
true.
:type is_hns_enabled: bool
:ivar failover_in_progress: If the failover is in progress, the value will
be true, otherwise, it will be null.
:vartype failover_in_progress: bool
"""

_validation = {
Expand All @@ -127,6 +130,7 @@ class StorageAccount(TrackedResource):
'encryption': {'readonly': True},
'access_tier': {'readonly': True},
'network_rule_set': {'readonly': True},
'failover_in_progress': {'readonly': True},
}

_attribute_map = {
Expand Down Expand Up @@ -154,6 +158,7 @@ class StorageAccount(TrackedResource):
'enable_https_traffic_only': {'key': 'properties.supportsHttpsTrafficOnly', 'type': 'bool'},
'network_rule_set': {'key': 'properties.networkAcls', 'type': 'NetworkRuleSet'},
'is_hns_enabled': {'key': 'properties.isHnsEnabled', 'type': 'bool'},
'failover_in_progress': {'key': 'properties.failoverInProgress', 'type': 'bool'},
}

def __init__(self, *, location: str, tags=None, identity=None, enable_azure_files_aad_integration: bool=None, enable_https_traffic_only: bool=None, is_hns_enabled: bool=None, **kwargs) -> None:
Expand All @@ -177,3 +182,4 @@ def __init__(self, *, location: str, tags=None, identity=None, enable_azure_file
self.enable_https_traffic_only = enable_https_traffic_only
self.network_rule_set = None
self.is_hns_enabled = is_hns_enabled
self.failover_in_progress = None
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ class SignedResource(str, Enum):
s = "s"


class ReplicationStatus(str, Enum):

live = "Live"
bootstrap = "Bootstrap"
unavailable = "Unavailable"


class PublicAccess(str, Enum):

container = "Container"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -840,3 +840,153 @@ def list_service_sas(

return deserialized
list_service_sas.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/ListServiceSas'}


def _failover_initial(
self, resource_group_name, account_name, custom_headers=None, raw=False, **operation_config):
# Construct URL
url = self.failover.metadata['url']
path_format_arguments = {
'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3),
'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str', min_length=1)
}
url = self._client.format_url(url, **path_format_arguments)

# Construct parameters
query_parameters = {}
query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str', min_length=1)

# Construct headers
header_parameters = {}
if self.config.generate_client_request_id:
header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
if custom_headers:
header_parameters.update(custom_headers)
if self.config.accept_language is not None:
header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')

# Construct and send request
request = self._client.post(url, query_parameters, header_parameters)
response = self._client.send(request, stream=False, **operation_config)

if response.status_code not in [200, 202]:
exp = CloudError(response)
exp.request_id = response.headers.get('x-ms-request-id')
raise exp

if raw:
client_raw_response = ClientRawResponse(None, response)
return client_raw_response

def failover(
self, resource_group_name, account_name, custom_headers=None, raw=False, polling=True, **operation_config):
"""Failover request can be triggered for a storage account in case of
availability issues. The failover occurs from the storage account's
primary cluster to secondary cluster for RA-GRS accounts. The secondary
cluster will become primary after failover.

:param resource_group_name: The name of the resource group within the
user's subscription. The name is case insensitive.
:type resource_group_name: str
:param account_name: The name of the storage account within the
specified resource group. Storage account names must be between 3 and
24 characters in length and use numbers and lower-case letters only.
:type account_name: str
:param dict custom_headers: headers that will be added to the request
:param bool raw: The poller return type is ClientRawResponse, the
direct response alongside the deserialized response
:param polling: True for ARMPolling, False for no polling, or a
polling object for personal polling strategy
:return: An instance of LROPoller that returns None or
ClientRawResponse<None> if raw==True
:rtype: ~msrestazure.azure_operation.AzureOperationPoller[None] or
~msrestazure.azure_operation.AzureOperationPoller[~msrest.pipeline.ClientRawResponse[None]]
:raises: :class:`CloudError<msrestazure.azure_exceptions.CloudError>`
"""
raw_result = self._failover_initial(
resource_group_name=resource_group_name,
account_name=account_name,
custom_headers=custom_headers,
raw=True,
**operation_config
)

def get_long_running_output(response):
if raw:
client_raw_response = ClientRawResponse(None, response)
return client_raw_response

lro_delay = operation_config.get(
'long_running_operation_timeout',
self.config.long_running_operation_timeout)
if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **operation_config)
elif polling is False: polling_method = NoPolling()
else: polling_method = polling
return LROPoller(self._client, raw_result, get_long_running_output, polling_method)
failover.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/failover'}

def get_last_sync_time(
self, resource_group_name, account_name, custom_headers=None, raw=False, **operation_config):
"""Retrieve last sync time for his or her RA-GRS and GRS accounts.

:param resource_group_name: The name of the resource group within the
user's subscription. The name is case insensitive.
:type resource_group_name: str
:param account_name: The name of the storage account within the
specified resource group. Storage account names must be between 3 and
24 characters in length and use numbers and lower-case letters only.
:type account_name: str
:param dict custom_headers: headers that will be added to the request
:param bool raw: returns the direct response alongside the
deserialized response
:param operation_config: :ref:`Operation configuration
overrides<msrest:optionsforoperations>`.
:return: GetLastSyncTimeResult or ClientRawResponse if raw=true
:rtype: ~azure.mgmt.storage.v2018_07_01.models.GetLastSyncTimeResult
or ~msrest.pipeline.ClientRawResponse
:raises: :class:`CloudError<msrestazure.azure_exceptions.CloudError>`
"""
# Construct URL
url = self.get_last_sync_time.metadata['url']
path_format_arguments = {
'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1, pattern=r'^[-\w\._\(\)]+$'),
'accountName': self._serialize.url("account_name", account_name, 'str', max_length=24, min_length=3),
'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str', min_length=1)
}
url = self._client.format_url(url, **path_format_arguments)

# Construct parameters
query_parameters = {}
query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str', min_length=1)

# Construct headers
header_parameters = {}
header_parameters['Accept'] = 'application/json'
if self.config.generate_client_request_id:
header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
if custom_headers:
header_parameters.update(custom_headers)
if self.config.accept_language is not None:
header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')

# Construct and send request
request = self._client.get(url, query_parameters, header_parameters)
response = self._client.send(request, stream=False, **operation_config)

if response.status_code not in [200]:
exp = CloudError(response)
exp.request_id = response.headers.get('x-ms-request-id')
raise exp

deserialized = None

if response.status_code == 200:
deserialized = self._deserialize('GetLastSyncTimeResult', response)

if raw:
client_raw_response = ClientRawResponse(deserialized, response)
return client_raw_response

return deserialized
get_last_sync_time.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/lastSyncTime'}