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

[Breadth Coverage] Support StorageSync in Azure CLI cmdlets #1389

Merged
merged 10 commits into from
Apr 7, 2020
Prev Previous commit
Next Next commit
save to remote temp
  • Loading branch information
jsntcy committed Feb 21, 2020
commit c67cdef351cea2fef677bcef8718f5926c973af0
329 changes: 110 additions & 219 deletions src/storagesync/azext_storagesync/_help.py

Large diffs are not rendered by default.

40 changes: 15 additions & 25 deletions src/storagesync/azext_storagesync/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,24 @@


def load_arguments(self, _):
storage_sync_service_name_type = CLIArgumentType(options_list=['--storage-sync-service-name', '-sss'],
help='The name of storage sync service.')
sync_group_name_type = CLIArgumentType(options_list=['--sync-group-name', '-sg'], help='The name of sync group.')
cloud_endpoint_name_type = CLIArgumentType(options_list=['--cloud-endpoint-name', '-ce'],
help='The name of cloud endpoint.')
server_endpoint_name_type = CLIArgumentType(options_list=['--server-endpoint-name', '-se'],
help='The name of server endpoint.')
share_name_type = CLIArgumentType(options_list=['--share-name', '-s'], help='The name of Azure file share.')
storage_sync_service_name_type = CLIArgumentType(help='The name of storage sync service.')
sync_group_name_type = CLIArgumentType(help='The name of sync group.')
cloud_endpoint_name_type = CLIArgumentType(help='The name of cloud endpoint.')
server_endpoint_name_type = CLIArgumentType(help='The name of server endpoint.')
azure_file_share_name_type = CLIArgumentType(help='The name of Azure file share.')
storage_account_type = CLIArgumentType(options_list='--storage-account',
help='The name or ID of the storage account.',
validator=parse_storage_account, id_part='name')
storage_account_tenant_id_type = CLIArgumentType(options_list='--tenant-id',
help='The id of the tenant that the storage account is in.')
server_resource_id_type = CLIArgumentType(options_list='--server-id',
help='The resource id of the registered server.')
storage_account_tenant_id_type = CLIArgumentType(help='The id of the tenant that the storage account is in.')
server_resource_id_type = CLIArgumentType(help='The resource id of the registered server.')
server_id_type = CLIArgumentType(help='GUID identifying the on-premises server.')

with self.argument_context('storagesync storage-sync-service create') as c:
Copy link
Member

@fengzhou-msft fengzhou-msft Mar 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prefix of the subcommand name seems redundant. just use storagesync service create? #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After internal discussion, we decide to use 'storagesync create'


In reply to: 392831198 [](ancestors = 392831198)

c.argument('resource_group_name', resource_group_name_type)
c.argument('storage_sync_service_name', storage_sync_service_name_type)
c.argument('location', arg_type=get_location_type(self.cli_ctx),
validator=get_default_location_from_resource_group)
c.argument('tags', tags_type)
c.argument('properties', help='The properties of the storage sync service.')

with self.argument_context('storagesync storage-sync-service delete') as c:
c.argument('resource_group_name', resource_group_name_type)
Expand Down Expand Up @@ -79,7 +74,7 @@ def load_arguments(self, _):
c.argument('sync_group_name', sync_group_name_type)
c.argument('cloud_endpoint_name', cloud_endpoint_name_type)
c.argument('storage_account_resource_id', storage_account_type)
c.argument('azure_file_share_name', share_name_type)
c.argument('azure_file_share_name', azure_file_share_name_type)
c.argument('storage_account_tenant_id', storage_account_tenant_id_type)
Copy link
Contributor

@mmyyrroonn mmyyrroonn Mar 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we get this tenant id by storage_account_resource_id? #WontFix

Copy link
Member Author

@jsntcy jsntcy Mar 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I do it in validator: _get_tenant_id():


In reply to: 392868993 [](ancestors = 392868993)


with self.argument_context('storagesync cloud-endpoint delete') as c:
Expand Down Expand Up @@ -145,26 +140,21 @@ def load_arguments(self, _):
with self.argument_context('storagesync registered-server create') as c:
c.argument('resource_group_name', resource_group_name_type)
c.argument('storage_sync_service_name', storage_sync_service_name_type)
c.argument('server_id', help='Server Id')
c.argument('server_certificate', help='Registered Server Certificate')
c.argument('agent_version', help='Registered Server Agent Version')
c.argument('server_osversion', help='Registered Server OS Version')
c.argument('last_heart_beat', help='Registered Server last heart beat')
c.argument('server_role', help='Registered Server serverRole')
c.argument('cluster_id', help='Registered Server clusterId')
c.argument('cluster_name', help='Registered Server clusterName')
c.argument('friendly_name', help='Friendly Name')

with self.argument_context('storagesync registered-server delete') as c:
c.argument('resource_group_name', resource_group_name_type)
c.argument('storage_sync_service_name', storage_sync_service_name_type)
c.argument('server_id', help='Server Id')
c.argument('server_id', server_id_type)

with self.argument_context('storagesync registered-server show') as c:
c.argument('resource_group_name', resource_group_name_type)
c.argument('storage_sync_service_name', storage_sync_service_name_type)
c.argument('server_id', help='Server Id')
c.argument('server_id', server_id_type)

with self.argument_context('storagesync registered-server list') as c:
c.argument('resource_group_name', resource_group_name_type)
c.argument('storage_sync_service_name', storage_sync_service_name_type)

with self.argument_context('storagesync registered-server rollover-certificate') as c:
c.argument('resource_group_name', resource_group_name_type)
c.argument('storage_sync_service_name', storage_sync_service_name_type)
1 change: 1 addition & 0 deletions src/storagesync/azext_storagesync/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ def load_command_table(self, _):
g.custom_command('delete', 'delete_storagesync_registered_server', confirmation=True)
g.custom_show_command('show', 'get_storagesync_registered_server')
g.custom_command('list', 'list_storagesync_registered_server')
g.custom_command('rollover-certificate', 'rollover_certificate_storagesync_registered_server')
63 changes: 53 additions & 10 deletions src/storagesync/azext_storagesync/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,36 @@
# pylint: disable=too-many-lines
# pylint: disable=too-many-locals
# pylint: disable=unused-argument
import uuid

import pythoncom
import win32com.client

import abc


class IEcsManagement(object):
__metaclass__ = abc.ABCMeta

@abc.abstractmethod
def register_sync_server(self, service_uri, subscription_id, storage_sync_service_name, resource_group_name,
certificate_provider_name, certificate_hash_algorithm, certificate_key_length,
monitoring_data_path):
return


class EcsManagementInteropClient(IEcsManagement):
_reg_clsid_ = "{41E24E95-D45A-11D2-852C-204C4F4F5020}"

def __init__(self):
clsid = pythoncom.MakeIID('{3EC1199D-20EB-40C0-8294-EB684E89AB2B}')
iid = pythoncom.MakeIID('{F29EAB44-2C63-4ACE-8C05-67C2203CBED2}')
mgmt_object = pythoncom.CoCreateInstance(clsid, None, pythoncom.CLSCTX_LOCAL_SERVER, iid)

def register_sync_server(self, service_uri, subscription_id, storage_sync_service_name, resource_group_name,
certificate_provider_name, certificate_hash_algorithm, certificate_key_length,
monitoring_data_path):
return


def create_storagesync_storage_sync_service(client,
Expand Down Expand Up @@ -176,17 +206,22 @@ def list_storagesync_server_endpoint(client,

def create_storagesync_registered_server(client,
resource_group_name,
storage_sync_service_name,
server_id,
server_certificate=None,
agent_version=None,
server_osversion=None,
last_heart_beat=None,
server_role=None,
cluster_id=None,
cluster_name=None,
friendly_name=None):
storage_sync_service_name):
body = {}
xl = win32com.client.Dispatch("Excel.Application")
mgmt_object = pythoncom.CoCreateInstance(uuid.UUID('{3EC1199D-20EB-40C0-8294-EB684E89AB2B}'), None, pythoncom.CLSCTX_LOCAL_SERVER,
uuid.UUID('{F29EAB44-2C63-4ACE-8C05-67C2203CBED2}'))
# Generate from local call
server_id = None
server_certificate = None,
agent_version = None,
server_osversion = None,
last_heart_beat = None,
server_role = None,
cluster_id = None,
cluster_name = None,
friendly_name = None
# Generate from local call
body['server_certificate'] = server_certificate # str
body['agent_version'] = agent_version # str
body['server_osversion'] = server_osversion # str
Expand Down Expand Up @@ -216,3 +251,11 @@ def list_storagesync_registered_server(client,
resource_group_name,
storage_sync_service_name):
return client.list_by_storage_sync_service(resource_group_name=resource_group_name, storage_sync_service_name=storage_sync_service_name)


def rollover_certificate_storagesync_registered_server(client,
resource_group,
storage_sync_service_name):
body = {}
server_id = None # Generate from local call
return client.trigger_rollover(resource_group_name=resource_group, storage_sync_service_name=storage_sync_service_name, server_id=server_id, parameters=body)
Loading