desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Returns database metrics. :param resource_group_name: The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal. :type resource_group_name: str :param server_name: The name of the server. :type server_name: str :param database_name: The name ...
def list_metrics(self, resource_group_name, server_name, database_name, filter, custom_headers=None, raw=False, **operation_config):
api_version = '2014-04-01' def internal_paging(next_link=None, raw=False): if (not next_link): url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/metrics' path_format_arguments = {'subscr...
'Returns database metric definitions. :param resource_group_name: The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal. :type resource_group_name: str :param server_name: The name of the server. :type server_name: str :param database_name...
def list_metric_definitions(self, resource_group_name, server_name, database_name, custom_headers=None, raw=False, **operation_config):
api_version = '2014-04-01' def internal_paging(next_link=None, raw=False): if (not next_link): url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/metricDefinitions' path_format_arguments ...
'Deletes a database replication link. Cannot be done during failover. :param resource_group_name: The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal. :type resource_group_name: str :param server_name: The name of the server. :type serve...
def delete_replication_link(self, resource_group_name, server_name, database_name, link_id, custom_headers=None, raw=False, **operation_config):
api_version = '2014-04-01' url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}' path_format_arguments = {'subscriptionId': self._serialize.url('self.config.subscription_id', self.config.subs...
'Gets a database replication link. :param resource_group_name: The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal. :type resource_group_name: str :param server_name: The name of the server. :type server_name: str :param database_name: T...
def get_replication_link(self, resource_group_name, server_name, database_name, link_id, custom_headers=None, raw=False, **operation_config):
api_version = '2014-04-01' url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}' path_format_arguments = {'subscriptionId': self._serialize.url('self.config.subscription_id', self.config.subs...
'Sets which replica database is primary by failing over from the current primary replica database. :param resource_group_name: The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal. :type resource_group_name: str :param server_name: The na...
def failover_replication_link(self, resource_group_name, server_name, database_name, link_id, custom_headers=None, raw=False, **operation_config):
api_version = '2014-04-01' url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}/failover' path_format_arguments = {'subscriptionId': self._serialize.url('self.config.subscription_id', self.co...
'Sets which replica database is primary by failing over from the current primary replica database. This operation might result in data loss. :param resource_group_name: The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal. :type resource_...
def failover_replication_link_allow_data_loss(self, resource_group_name, server_name, database_name, link_id, custom_headers=None, raw=False, **operation_config):
api_version = '2014-04-01' url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks/{linkId}/forceFailoverAllowDataLoss' path_format_arguments = {'subscriptionId': self._serialize.url('self.config.subscri...
'Lists a database\'s replication links. :param resource_group_name: The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal. :type resource_group_name: str :param server_name: The name of the server. :type server_name: str :param database_na...
def list_replication_links(self, resource_group_name, server_name, database_name, custom_headers=None, raw=False, **operation_config):
api_version = '2014-04-01' def internal_paging(next_link=None, raw=False): if (not next_link): url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/replicationLinks' path_format_arguments =...
'Pauses a data warehouse. :param resource_group_name: The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal. :type resource_group_name: str :param server_name: The name of the server. :type server_name: str :param database_name: The name o...
def pause(self, resource_group_name, server_name, database_name, custom_headers=None, raw=False, **operation_config):
api_version = '2014-04-01' url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/pause' path_format_arguments = {'subscriptionId': self._serialize.url('self.config.subscription_id', self.config.subscription_id, 'str'),...
'Resumes a data warehouse. :param resource_group_name: The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal. :type resource_group_name: str :param server_name: The name of the server. :type server_name: str :param database_name: The name ...
def resume(self, resource_group_name, server_name, database_name, custom_headers=None, raw=False, **operation_config):
api_version = '2014-04-01' url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/resume' path_format_arguments = {'subscriptionId': self._serialize.url('self.config.subscription_id', self.config.subscription_id, 'str')...
'Creates a new database or updates an existing database. Location is a required property in the request body, and it must be the same as the location of the SQL server. :param resource_group_name: The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or...
def create_or_update(self, resource_group_name, server_name, database_name, parameters, custom_headers=None, raw=False, **operation_config):
api_version = '2014-04-01' url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}' path_format_arguments = {'subscriptionId': self._serialize.url('self.config.subscription_id', self.config.subscription_id, 'str'), 'reso...
'Deletes a database. :param resource_group_name: The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal. :type resource_group_name: str :param server_name: The name of the server. :type server_name: str :param database_name: The name of the...
def delete(self, resource_group_name, server_name, database_name, custom_headers=None, raw=False, **operation_config):
api_version = '2014-04-01' url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}' path_format_arguments = {'subscriptionId': self._serialize.url('self.config.subscription_id', self.config.subscription_id, 'str'), 'reso...
'Gets a database. :param resource_group_name: The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal. :type resource_group_name: str :param server_name: The name of the server. :type server_name: str :param database_name: The name of the da...
def get(self, resource_group_name, server_name, database_name, expand=None, custom_headers=None, raw=False, **operation_config):
api_version = '2014-04-01' url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}' path_format_arguments = {'subscriptionId': self._serialize.url('self.config.subscription_id', self.config.subscription_id, 'str'), 'reso...
'Returns a list of databases in a server. :param resource_group_name: The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal. :type resource_group_name: str :param server_name: The name of the server. :type server_name: str :param expand: A...
def list_by_server(self, resource_group_name, server_name, expand=None, filter=None, custom_headers=None, raw=False, **operation_config):
api_version = '2014-04-01' def internal_paging(next_link=None, raw=False): if (not next_link): url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases' path_format_arguments = {'subscriptionId': self._serial...
'Gets a service tier advisor. :param resource_group_name: The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal. :type resource_group_name: str :param server_name: The name of the server. :type server_name: str :param database_name: The na...
def get_service_tier_advisor(self, resource_group_name, server_name, database_name, service_tier_advisor_name, custom_headers=None, raw=False, **operation_config):
api_version = '2014-04-01' url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/serviceTierAdvisors/{serviceTierAdvisorName}' path_format_arguments = {'subscriptionId': self._serialize.url('self.config.subscription_id...
'Returns service tier advisors for specified database. :param resource_group_name: The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal. :type resource_group_name: str :param server_name: The name of the server. :type server_name: str :pa...
def list_service_tier_advisors(self, resource_group_name, server_name, database_name, custom_headers=None, raw=False, **operation_config):
api_version = '2014-04-01' def internal_paging(next_link=None, raw=False): if (not next_link): url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/serviceTierAdvisors' path_format_argument...
'Creates or updates a database\'s transparent data encryption configuration. :param resource_group_name: The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal. :type resource_group_name: str :param server_name: The name of the server. :typ...
def create_or_update_transparent_data_encryption_configuration(self, resource_group_name, server_name, database_name, status=None, custom_headers=None, raw=False, **operation_config):
parameters = models.TransparentDataEncryption(status=status) api_version = '2014-04-01' url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/transparentDataEncryption/current' path_format_arguments = {'subscriptio...
'Gets a database\'s transparent data encryption configuration. :param resource_group_name: The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal. :type resource_group_name: str :param server_name: The name of the server. :type server_name:...
def get_transparent_data_encryption_configuration(self, resource_group_name, server_name, database_name, custom_headers=None, raw=False, **operation_config):
api_version = '2014-04-01' url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/transparentDataEncryption/current' path_format_arguments = {'subscriptionId': self._serialize.url('self.config.subscription_id', self.con...
'Returns a database\'s transparent data encryption operation result. :param resource_group_name: The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal. :type resource_group_name: str :param server_name: The name of the server. :type server...
def list_transparent_data_encryption_activity(self, resource_group_name, server_name, database_name, custom_headers=None, raw=False, **operation_config):
api_version = '2014-04-01' def internal_paging(next_link=None, raw=False): if (not next_link): url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/transparentDataEncryption/current/operationResults' ...
'Gets a database\'s threat detection policy. :param resource_group_name: The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal. :type resource_group_name: str :param server_name: The name of the server. :type server_name: str :param databa...
def get_threat_detection_policy(self, resource_group_name, server_name, database_name, custom_headers=None, raw=False, **operation_config):
api_version = '2014-04-01' url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/securityAlertPolicies/{securityAlertPolicyName}' path_format_arguments = {'subscriptionId': self._serialize.url('self.config.subscription...
'Creates or updates a database\'s threat detection policy. :param resource_group_name: The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal. :type resource_group_name: str :param server_name: The name of the server. :type server_name: str...
def create_or_update_threat_detection_policy(self, resource_group_name, server_name, database_name, parameters, custom_headers=None, raw=False, **operation_config):
api_version = '2014-04-01' url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/securityAlertPolicies/{securityAlertPolicyName}' path_format_arguments = {'subscriptionId': self._serialize.url('self.config.subscription...
'Returns a database backup long term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal. :type resource_group_name: str :param server_name: The name of the server. :type server_name: str :pa...
def get_backup_long_term_retention_policy(self, resource_group_name, server_name, database_name, custom_headers=None, raw=False, **operation_config):
api_version = '2014-04-01' url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/backupLongTermRetentionPolicies/{backupLongTermRetentionPolicyName}' path_format_arguments = {'subscriptionId': self._serialize.url('self...
'Creates or updates a database backup long term retention policy. :param resource_group_name: The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal. :type resource_group_name: str :param server_name: The name of the server. :type server_na...
def create_or_update_long_term_retention_policy(self, resource_group_name, server_name, database_name, state, recovery_services_backup_policy_resource_id, custom_headers=None, raw=False, **operation_config):
parameters = models.BackupLongTermRetentionPolicy(state=state, recovery_services_backup_policy_resource_id=recovery_services_backup_policy_resource_id) api_version = '2014-04-01' url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/...
'Returns database usages. :param resource_group_name: The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal. :type resource_group_name: str :param server_name: The name of the server. :type server_name: str :param database_name: The name o...
def list_usages(self, resource_group_name, server_name, database_name, custom_headers=None, raw=False, **operation_config):
api_version = '2014-04-01' def internal_paging(next_link=None, raw=False): if (not next_link): url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/usages' path_format_arguments = {'subscri...
'Gets a database\'s blob auditing policy. :param resource_group_name: The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal. :type resource_group_name: str :param server_name: The name of the server. :type server_name: str :param database_...
def get_blob_auditing_policy(self, resource_group_name, server_name, database_name, custom_headers=None, raw=False, **operation_config):
api_version = '2015-05-01-preview' url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/auditingSettings/{blobAuditingPolicyName}' path_format_arguments = {'resourceGroupName': self._serialize.url('resource_group_name...
'Creates or updates a database\'s blob auditing policy. :param resource_group_name: The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal. :type resource_group_name: str :param server_name: The name of the server. :type server_name: str :p...
def create_or_update_blob_auditing_policy(self, resource_group_name, server_name, database_name, parameters, custom_headers=None, raw=False, **operation_config):
api_version = '2015-05-01-preview' url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/auditingSettings/{blobAuditingPolicyName}' path_format_arguments = {'resourceGroupName': self._serialize.url('resource_group_name...
'Return distribution full name with - replaced with _'
@property def wheel_dist_name(self):
return '-'.join((safer_name(self.distribution.get_name()), safer_version(self.distribution.get_version())))
'Return archive name without extension'
def get_archive_basename(self):
(impl_tag, abi_tag, plat_tag) = self.get_tag() archive_basename = ('%s-%s-%s-%s' % (self.wheel_dist_name, impl_tag, abi_tag, plat_tag)) return archive_basename
'Return license filename from a license-file key in setup.cfg, or None.'
def license_file(self):
metadata = self.distribution.get_option_dict('metadata') if (not ('license_file' in metadata)): return None return metadata['license_file'][1]
'Generate requirements from setup.cfg as (\'Requires-Dist\', \'requirement; qualifier\') tuples. From a metadata section in setup.cfg: [metadata] provides-extra = extra1 extra2 requires-dist = requirement; qualifier another; qualifier2 unqualified Yields (\'Provides-Extra\', \'extra1\'), (\'Provides-Extra\', \'extra2\'...
def setupcfg_requirements(self):
metadata = self.distribution.get_option_dict('metadata') for (key, title) in (('provides_extra', 'Provides-Extra'), ('requires_dist', 'Requires-Dist')): if (not (key in metadata)): continue field = metadata[key] for line in field[1].splitlines(): line = line.strip...
'Add additional requirements from setup.cfg to file metadata_path'
def add_requirements(self, metadata_path):
additional = list(self.setupcfg_requirements()) if (not additional): return pkg_info = read_pkg_info(metadata_path) if (('Provides-Extra' in pkg_info) or ('Requires-Dist' in pkg_info)): warnings.warn('setup.cfg requirements overwrite values from setup.py') del pkg_...
'Convert an .egg-info directory into a .dist-info directory'
def egg2dist(self, egginfo_path, distinfo_path):
def adios(p): 'Appropriately delete directory, file or link.' if (os.path.exists(p) and (not os.path.islink(p)) and os.path.isdir(p)): shutil.rmtree(p) elif os.path.exists(p): os.unlink(p) adios(distinfo_path) if (not os.path.exists(egginfo_path...
'- src: Relative path from the repo root - dest: Relative path to file to patch in the packaged release'
def __init__(self, src_of_patch, path_to_patch):
self.src_of_patch = src_of_patch self.path_to_patch = path_to_patch
'Perform post-recording cleanup on the YAML file that can\'t be accomplished with the VCR recording hooks.'
def _post_recording_scrub(self):
src_path = self.cassette_path rg_name = getattr(self, 'resource_group', None) rg_original = getattr(self, 'resource_group_original', None) t = tempfile.NamedTemporaryFile('r+') with open(src_path, 'r') as f: for line in f: if (rg_original and (rg_name != rg_original)): ...
'Method to actually start execution of the test. Must be called from the test_<name> method of the test class.'
def execute(self):
try: if self.run_live: print('RUN LIVE: {}'.format(self.test_name)) self._execute_live_or_recording() elif self.playback: print('PLAYBACK: {}'.format(self.test_name)) self._execute_playback() else: print('RECORDING: {}'....
'Return distribution full name with - replaced with _'
@property def wheel_dist_name(self):
return '-'.join((safer_name(self.distribution.get_name()), safer_version(self.distribution.get_version())))
'Return archive name without extension'
def get_archive_basename(self):
(impl_tag, abi_tag, plat_tag) = self.get_tag() archive_basename = ('%s-%s-%s-%s' % (self.wheel_dist_name, impl_tag, abi_tag, plat_tag)) return archive_basename
'Return license filename from a license-file key in setup.cfg, or None.'
def license_file(self):
metadata = self.distribution.get_option_dict('metadata') if (not ('license_file' in metadata)): return None return metadata['license_file'][1]
'Generate requirements from setup.cfg as (\'Requires-Dist\', \'requirement; qualifier\') tuples. From a metadata section in setup.cfg: [metadata] provides-extra = extra1 extra2 requires-dist = requirement; qualifier another; qualifier2 unqualified Yields (\'Provides-Extra\', \'extra1\'), (\'Provides-Extra\', \'extra2\'...
def setupcfg_requirements(self):
metadata = self.distribution.get_option_dict('metadata') for (key, title) in (('provides_extra', 'Provides-Extra'), ('requires_dist', 'Requires-Dist')): if (not (key in metadata)): continue field = metadata[key] for line in field[1].splitlines(): line = line.strip...
'Add additional requirements from setup.cfg to file metadata_path'
def add_requirements(self, metadata_path):
additional = list(self.setupcfg_requirements()) if (not additional): return pkg_info = read_pkg_info(metadata_path) if (('Provides-Extra' in pkg_info) or ('Requires-Dist' in pkg_info)): warnings.warn('setup.cfg requirements overwrite values from setup.py') del pkg_...
'Convert an .egg-info directory into a .dist-info directory'
def egg2dist(self, egginfo_path, distinfo_path):
def adios(p): 'Appropriately delete directory, file or link.' if (os.path.exists(p) and (not os.path.islink(p)) and os.path.isdir(p)): shutil.rmtree(p) elif os.path.exists(p): os.unlink(p) adios(distinfo_path) if (not os.path.exists(egginfo_path...
'writes the progress'
def write(self, args):
raise NotImplementedError
'flushes the message out the pipeline'
def flush(self):
raise NotImplementedError
'resets the view to neutral'
def clear(self):
pass
'adds a progress report :param kwargs: dictionary containing \'message\', \'total_val\', \'value\''
def add(self, **kwargs):
message = kwargs.get('message', self.message) total_val = kwargs.get('total_val', self.total_val) value = kwargs.get('value', self.value) if (value and total_val): assert ((value >= 0) and (value <= total_val) and (total_val >= 0)) self.closed = (value == total_val) self.total_val = ...
'report the progress'
def report(self):
percent = ((self.value / self.total_val) if ((self.value is not None) and self.total_val) else None) return {'message': self.message, 'percent': percent}
'activate a view'
def init_progress(self, progress_view):
self.active_progress = progress_view
'adds a progress report'
def add(self, **kwargs):
self.reporter.add(**kwargs) self.update()
'updates the view with the progress'
def update(self):
self.active_progress.write(self.reporter.report()) self.active_progress.flush()
'if there is an abupt stop before ending'
def stop(self):
self.reporter.closed = True self.add(message='Interrupted') self.active_progress.clear()
'start reporting progress'
def begin(self, **kwargs):
kwargs['message'] = kwargs.get('message', 'Starting') self.add(**kwargs) self.reporter.closed = False
'ending reporting of progress'
def end(self, **kwargs):
kwargs['message'] = kwargs.get('message', 'Finished') self.reporter.closed = True self.add(**kwargs) self.active_progress.clear()
'whether progress is continuing'
def is_running(self):
return (not self.reporter.closed)
'writes the progress :param args: dictionary containing key \'message\''
def write(self, args):
if (self.spinner is None): self.spinner = humanfriendly.Spinner(label='In Progress', stream=self.out, hide_cursor=False) msg = args.get('message', 'In Progress') self.spinner.step(label=msg)
'writes the progress :param args: args is a dictionary containing \'percent\', \'message\''
def write(self, args):
percent = args.get('percent', 0) message = args.get('message', '') if percent: progress = _format_value(message, percent) self.out.write(progress)
'gets the progress for template deployments'
def _generate_template_progress(self, correlation_id):
from azure.cli.core.commands.client_factory import get_mgmt_service_client from azure.monitor import MonitorClient if (correlation_id is not None): formatter = 'eventTimestamp ge {}' end_time = datetime.datetime.utcnow() start_time = (end_time - datetime.timedelta(seconds=DEFAU...
'Register a CLI command :param name: Name of the command as it will be called on the command line :type name: str :param method_name: Name of the method the command maps to on the service adapter :type method_name: str :param transform: Transform function for transforming the output of the command :type transform: func...
def command(self, name, method_name, transform=None, table_transformer=None, confirmation=None, exception_handler=None):
cli_command(self._scope, '{} {}'.format(self._group_name, name), self._service_adapter(method_name), client_factory=self._client_factory, transform=transform, table_transformer=table_transformer, confirmation=confirmation, exception_handler=(exception_handler or self._exception_handler))
'Verifies that the first sentence of a docstring is extracted as the short description. Verifies that line breaks in the long summary are removed and leaves the text wrapping to the help system.'
@redirect_io def test_help_long_description_from_docstring(self):
def test_handler(): 'Short Description. Long description with\nline break.' pass setattr(sys.modules[__name__], test_handler.__name__, test_handler) cli_command(None, 'test', '{}#{}'.format(__name__, test_handler.__name__)) _update_command_definitions(command_table) co...
'The operation to get a virtual machine. :param resource_group_name: The name of the resource group. :type resource_group_name: str :param vm_name: The name of the virtual machine. :type vm_name: str :param opt_param: Used to verify reflection correctly identifies optional params. :type opt_param: object :param expand:...
@staticmethod def sample_vm_get(resource_group_name, vm_name, opt_param=None, expand=None, custom_headers=None, raw=False, **operation_config):
pass
'Load a command table into our parser.'
def load_command_table(self, command_table):
if (not self.subparsers): sp = self.add_subparsers(dest='_command_package') sp.required = True self.subparsers = {(): sp} for (command_name, metadata) in command_table.items(): subparser = self._get_subparser(command_name.split()) command_verb = command_name.split()[(-1)]...
'For each part of the path, walk down the tree of subparsers, creating new ones if one doesn\'t already exist.'
def _get_subparser(self, path):
for length in range(0, len(path)): parent_subparser = self.subparsers.get(tuple(path[0:length]), None) if (not parent_subparser): grandparent_subparser = self.subparsers[tuple(path[:(length - 1)])] new_parser = grandparent_subparser.add_parser(path[(length - 1)]) ...
'Determine if this parser instance represents a group or a command. Anything that has a func default is considered a group. This includes any dummy commands served up by the "filter out irrelevant commands based on argv" command filter'
def is_group(self):
cmd = self._defaults.get('func', None) return (not (cmd and cmd.handler))
'Since getting the description can be expensive (require module loads), we defer this until someone actually wants to use it (i.e. show help for the command)'
def __getattribute__(self, name):
if (name == 'description'): if self._description: self.description = (self._description() if callable(self._description) else self._description) self._description = None return object.__getattribute__(self, name)
'Constructor. :param import_prefix: Path to the (unversioned) module. :type import_prefix: str. :param client_name: Name the client for this resource type. :type client_name: str.'
def __init__(self, import_prefix, client_name):
self.import_prefix = import_prefix self.client_name = client_name
'From the list of commands names, find the exact match or set of potential matches that we are looking for'
@staticmethod def build_command_tree(command_table):
result = {} for command in command_table: index = result parts = command.split() for part in parts[:(-1)]: if (part not in index): index[part] = {} index = index[part] index[parts[(-1)]] = command_table[command] return result
'Raise the event `name`.'
def raise_event(self, name, **kwargs):
data = truncate_text(str(kwargs), width=500) logger.debug("Application event '%s' with event data %s", name, data) for func in list(self._event_handlers[name]): func(**kwargs)
'Register a callable that will be called when the event `name` is raised. param: name: The name of the event param: handler: Function that takes two parameters; name: name of the event raised event_data: `dict` with event specific data.'
def register(self, name, handler):
self._event_handlers[name].append(handler) logger.debug("Registered application event handler '%s' at %s", name, handler)
'Remove a callable that is registered to be called when the event `name` is raised. param: name: The name of the event param: handler: Function that takes two parameters; name: name of the event raised event_data: `dict` with event specific data.'
def remove(self, name, handler):
self._event_handlers[name].remove(handler) logger.debug("Removed application event handler '%s' at %s", name, handler)
'Assign a new randome GUID as x-ms-client-request-id The method must be invoked before each command execution in order to ensure unique client side request ID is generated.'
def refresh_request_id(self):
self.session['headers']['x-ms-client-request-id'] = str(uuid.uuid1())
'Return distribution full name with - replaced with _'
@property def wheel_dist_name(self):
return '-'.join((safer_name(self.distribution.get_name()), safer_version(self.distribution.get_version())))
'Return archive name without extension'
def get_archive_basename(self):
(impl_tag, abi_tag, plat_tag) = self.get_tag() archive_basename = ('%s-%s-%s-%s' % (self.wheel_dist_name, impl_tag, abi_tag, plat_tag)) return archive_basename
'Return license filename from a license-file key in setup.cfg, or None.'
def license_file(self):
metadata = self.distribution.get_option_dict('metadata') if (not ('license_file' in metadata)): return None return metadata['license_file'][1]
'Generate requirements from setup.cfg as (\'Requires-Dist\', \'requirement; qualifier\') tuples. From a metadata section in setup.cfg: [metadata] provides-extra = extra1 extra2 requires-dist = requirement; qualifier another; qualifier2 unqualified Yields (\'Provides-Extra\', \'extra1\'), (\'Provides-Extra\', \'extra2\'...
def setupcfg_requirements(self):
metadata = self.distribution.get_option_dict('metadata') for (key, title) in (('provides_extra', 'Provides-Extra'), ('requires_dist', 'Requires-Dist')): if (not (key in metadata)): continue field = metadata[key] for line in field[1].splitlines(): line = line.strip...
'Add additional requirements from setup.cfg to file metadata_path'
def add_requirements(self, metadata_path):
additional = list(self.setupcfg_requirements()) if (not additional): return pkg_info = read_pkg_info(metadata_path) if (('Provides-Extra' in pkg_info) or ('Requires-Dist' in pkg_info)): warnings.warn('setup.cfg requirements overwrite values from setup.py') del pkg_...
'Convert an .egg-info directory into a .dist-info directory'
def egg2dist(self, egginfo_path, distinfo_path):
def adios(p): 'Appropriately delete directory, file or link.' if (os.path.exists(p) and (not os.path.islink(p)) and os.path.isdir(p)): shutil.rmtree(p) elif os.path.exists(p): os.unlink(p) adios(distinfo_path) if (not os.path.exists(egginfo_path...
'Return distribution full name with - replaced with _'
@property def wheel_dist_name(self):
return '-'.join((safer_name(self.distribution.get_name()), safer_version(self.distribution.get_version())))
'Return archive name without extension'
def get_archive_basename(self):
(impl_tag, abi_tag, plat_tag) = self.get_tag() archive_basename = ('%s-%s-%s-%s' % (self.wheel_dist_name, impl_tag, abi_tag, plat_tag)) return archive_basename
'Return license filename from a license-file key in setup.cfg, or None.'
def license_file(self):
metadata = self.distribution.get_option_dict('metadata') if (not ('license_file' in metadata)): return None return metadata['license_file'][1]
'Generate requirements from setup.cfg as (\'Requires-Dist\', \'requirement; qualifier\') tuples. From a metadata section in setup.cfg: [metadata] provides-extra = extra1 extra2 requires-dist = requirement; qualifier another; qualifier2 unqualified Yields (\'Provides-Extra\', \'extra1\'), (\'Provides-Extra\', \'extra2\'...
def setupcfg_requirements(self):
metadata = self.distribution.get_option_dict('metadata') for (key, title) in (('provides_extra', 'Provides-Extra'), ('requires_dist', 'Requires-Dist')): if (not (key in metadata)): continue field = metadata[key] for line in field[1].splitlines(): line = line.strip...
'Add additional requirements from setup.cfg to file metadata_path'
def add_requirements(self, metadata_path):
additional = list(self.setupcfg_requirements()) if (not additional): return pkg_info = read_pkg_info(metadata_path) if (('Provides-Extra' in pkg_info) or ('Requires-Dist' in pkg_info)): warnings.warn('setup.cfg requirements overwrite values from setup.py') del pkg_...
'Convert an .egg-info directory into a .dist-info directory'
def egg2dist(self, egginfo_path, distinfo_path):
def adios(p): 'Appropriately delete directory, file or link.' if (os.path.exists(p) and (not os.path.islink(p)) and os.path.isdir(p)): shutil.rmtree(p) elif os.path.exists(p): os.unlink(p) adios(distinfo_path) if (not os.path.exists(egginfo_path...
'Return distribution full name with - replaced with _'
@property def wheel_dist_name(self):
return '-'.join((safer_name(self.distribution.get_name()), safer_version(self.distribution.get_version())))
'Return archive name without extension'
def get_archive_basename(self):
(impl_tag, abi_tag, plat_tag) = self.get_tag() archive_basename = ('%s-%s-%s-%s' % (self.wheel_dist_name, impl_tag, abi_tag, plat_tag)) return archive_basename
'Return license filename from a license-file key in setup.cfg, or None.'
def license_file(self):
metadata = self.distribution.get_option_dict('metadata') if (not ('license_file' in metadata)): return None return metadata['license_file'][1]
'Generate requirements from setup.cfg as (\'Requires-Dist\', \'requirement; qualifier\') tuples. From a metadata section in setup.cfg: [metadata] provides-extra = extra1 extra2 requires-dist = requirement; qualifier another; qualifier2 unqualified Yields (\'Provides-Extra\', \'extra1\'), (\'Provides-Extra\', \'extra2\'...
def setupcfg_requirements(self):
metadata = self.distribution.get_option_dict('metadata') for (key, title) in (('provides_extra', 'Provides-Extra'), ('requires_dist', 'Requires-Dist')): if (not (key in metadata)): continue field = metadata[key] for line in field[1].splitlines(): line = line.strip...
'Add additional requirements from setup.cfg to file metadata_path'
def add_requirements(self, metadata_path):
additional = list(self.setupcfg_requirements()) if (not additional): return pkg_info = read_pkg_info(metadata_path) if (('Provides-Extra' in pkg_info) or ('Requires-Dist' in pkg_info)): warnings.warn('setup.cfg requirements overwrite values from setup.py') del pkg_...
'Convert an .egg-info directory into a .dist-info directory'
def egg2dist(self, egginfo_path, distinfo_path):
def adios(p): 'Appropriately delete directory, file or link.' if (os.path.exists(p) and (not os.path.islink(p)) and os.path.isdir(p)): shutil.rmtree(p) elif os.path.exists(p): os.unlink(p) adios(distinfo_path) if (not os.path.exists(egginfo_path...
'Creates a connection to the remote server. :param host: Remote host :type host: String :param username: User name to connect to the remote host :type username: String :param port: Remote host port :type port: Number'
def connect(self, host, username, port=2200, key_filename=None):
if (not host): raise ValueError('Host is missing') if (not username): raise ValueError('Username is missing') if (not port): raise ValueError('Missing port') self.host = host self.username = username self.port = port if (self.client is None): se...
'Runs a command on the remote host :param command: Command to run on the remote host :type command: String :param background: True to run it in a separate thread, False should be run in the foreground :type command: Boolean'
def run(self, command, background=False):
if background: t = threading.Thread(target=ACSClient._run_cmd, args=(self, command)) t.daemon = True t.start() return return self._run_cmd(command)
'Runs a command on the remote host :param command: Command to run on the remote host :type command: String'
def _run_cmd(self, command):
if (not command): raise ValueError('Command is missing') (_, stdout, stderr) = self.client.exec_command(command) return (stdout, stderr)
'Checks if file on the remote exists :param file_path: Full path to the file on remote machine :type file_path: String'
def file_exists(self, file_path):
if (not file_path): raise ValueError('Missing file path') if (self.transport is None): raise TypeError('Transport cannot be none') sftp = self.transport.open_sftp_client() result = None try: sftp.stat(file_path) result = True except IOError: ...
'Creates a tunnel to the remote host :param remote_host: Remote host to tunnel to :type remote_host: String :param remote_port: Remote port to tunnel to :type remote_port: Number :param local_port: Local port. If set to 0, random local port is selected :type local_port: Number'
def create_tunnel(self, remote_host, remote_port, local_port=0):
if (local_port is 0): local_port = self.get_available_local_port() with SSHTunnelForwarder((self.host, self.port), ssh_username=self.username, remote_bind_address=(remote_host, remote_port), local_bind_address=('0.0.0.0', local_port)): try: while True: sleep(1) ...
'Gets a random, available local port'
@staticmethod def get_available_local_port():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(('', 0)) s.listen(1) port = s.getsockname()[1] s.close() return port
'Sets the HTTP proxy'
@abstractmethod def set_http_proxy(self, host, port):
pass
'Disables the HTTP proxy'
@abstractmethod def disable_http_proxy(self):
pass
'Sets the HTTP proxy on Linux'
def set_http_proxy(self, host, port):
subprocess.call("sudo gsettings set org.gnome.system.proxy mode 'manual'", shell=True) subprocess.call("sudo gsettings set org.gnome.system.proxy.http host '{}'".format(host), shell=True) subprocess.call('sudo gsettings set org.gnome.system.proxy.http port {}'.fo...
'Disables the HTTP proxy'
def disable_http_proxy(self):
subprocess.call("sudo gsettings set org.gnome.system.proxy mode 'none'", shell=True)
'Sets the HTTP proxy'
def set_http_proxy(self, host, port):
cmd = 'sudo networksetup -setwebproxy wi-fi {} {}'.format(host, port) subprocess.call(cmd, shell=True)
'Disables the HTTP proxy'
def disable_http_proxy(self):
subprocess.call('sudo networksetup -setwebproxystate wi-fi off', shell=True)
'Sets the HTTP proxy on Windows'
def set_http_proxy(self, host, port):
setting = create_unicode_buffer(((host + ':') + str(port))) self._set_internet_options(setting)
'Disables the HTTP proxy'
def disable_http_proxy(self):
self._set_internet_options(None, False)