def container_export(cmd, resource_group_name, name, file): resource_client = _resource_client_factory(cmd.cli_ctx) container_group_client = cf_container_groups(cmd.cli_ctx) resource = resource_client.resources.get(resource_group_name, "Microsoft.ContainerInstance", '', "containerGroups", name, container_group_client.api_version, False).__dict__ # Remove unwanted properites resource['properties'].pop('instanceView', None) resource.pop('sku', None) resource.pop('id', None) resource.pop('plan', None) resource.pop('identity', None) resource.pop('kind', None) resource.pop('managed_by', None) resource['properties'].pop('provisioningState', None) for i in range(len(resource['properties']['containers'])): resource['properties']['containers'][i]['properties'].pop('instanceView', None) # Add the api version resource['apiVersion'] = container_group_client.api_version with open(file, 'w+') as f: yaml.dump(resource, f, default_flow_style=False)
def container_export(cmd, resource_group_name, name, file): resource_client = _resource_client_factory(cmd.cli_ctx) container_group_client = cf_container_groups(cmd.cli_ctx) resource = resource_client.resources.get(resource_group_name, "Microsoft.ContainerInstance", '', "containerGroups", name, container_group_client.api_version, False).__dict__ # Remove unwanted properites resource['properties'].pop('instanceView', None) resource.pop('sku', None) resource.pop('id', None) resource.pop('plan', None) resource.pop('identity', None) resource.pop('kind', None) resource.pop('managed_by', None) resource['properties'].pop('provisioningState', None) for i in range(len(resource['properties']['containers'])): resource['properties']['containers'][i]['properties'].pop('instanceView', None) # Add the api version resource['apiVersion'] = container_group_client.api_version with open(file, 'w+') as f: yaml.dump(resource, f, default_flow_style=False)
def get_resource_types_completion_list(cmd, prefix, namespace, **kwargs): # pylint: disable=unused-argument rcf = _resource_client_factory(cmd.cli_ctx) result = rcf.providers.list() types = [] for p in list(result): for r in p.resource_types: types.append(p.namespace + '/' + r.resource_type) return types
def _create_update_from_file(cli_ctx, resource_group_name, name, location, file): resource_client = _resource_client_factory(cli_ctx) container_group_client = cf_container_groups(cli_ctx) cg_defintion = None try: with open(file, 'r') as f: cg_defintion = yaml.load(f) except FileNotFoundError: raise CLIError("No such file or directory: " + file) except yaml.YAMLError as e: raise CLIError("Error while parsing yaml file:\n\n" + str(e)) # Validate names match if both are provided if name and cg_defintion.get('name', None): if name != cg_defintion.get('name', None): raise CLIError( "The name parameter and name from yaml definition must match.") else: # Validate at least one name is provided name = name or cg_defintion.get('name', None) if cg_defintion.get('name', None) is None and not name: raise CLIError("The name of the container group is required") cg_defintion['name'] = name location = location or cg_defintion.get('location', None) if not location: location = resource_client.resource_groups.get( resource_group_name).location cg_defintion['location'] = location api_version = cg_defintion.get('apiVersion', None) or container_group_client.api_version resource = resource_client.resources.create_or_update( resource_group_name, "Microsoft.ContainerInstance", '', "containerGroups", name, api_version, cg_defintion, raw=True) return resource.output
def _classic_vm_exists(cmd, resource_group_name, vm_name): classic_vm_provider = 'Microsoft.ClassicCompute' vm_resource_type = 'virtualMachines' try: rcf = _resource_client_factory(cmd.cli_ctx) api_version = _resolve_api_version(rcf, classic_vm_provider, None, vm_resource_type) resource_client = rcf.resources resource_client.get(resource_group_name, classic_vm_provider, '', vm_resource_type, vm_name, api_version) except CloudError as cloudError: # Resource does not exist or the API failed logger.debug(cloudError) return False except Exception as exception: # Unknown error, so return false for default resource not found error message logger.debug(exception) return False return True
def _create_update_from_file(cli_ctx, resource_group_name, name, location, file, no_wait): resource_client = _resource_client_factory(cli_ctx) container_group_client = cf_container_groups(cli_ctx) cg_defintion = None try: with open(file, 'r') as f: cg_defintion = yaml.load(f) except FileNotFoundError: raise CLIError("No such file or directory: " + file) except yaml.YAMLError as e: raise CLIError("Error while parsing yaml file:\n\n" + str(e)) # Validate names match if both are provided if name and cg_defintion.get('name', None): if name != cg_defintion.get('name', None): raise CLIError("The name parameter and name from yaml definition must match.") else: # Validate at least one name is provided name = name or cg_defintion.get('name', None) if cg_defintion.get('name', None) is None and not name: raise CLIError("The name of the container group is required") cg_defintion['name'] = name location = location or cg_defintion.get('location', None) if not location: location = resource_client.resource_groups.get(resource_group_name).location cg_defintion['location'] = location api_version = cg_defintion.get('apiVersion', None) or container_group_client.api_version return sdk_no_wait(no_wait, resource_client.resources.create_or_update, resource_group_name, "Microsoft.ContainerInstance", '', "containerGroups", name, api_version, cg_defintion)
def get_providers_completion_list(cmd, prefix, namespace, **kwargs): # pylint: disable=unused-argument rcf = _resource_client_factory(cmd.cli_ctx) result = rcf.providers.list() return [r.namespace for r in result]
__name__, 'group deployment operation show', 'azure.cli.command_modules.resource.custom#get_deployment_operations', cf_deployment_operations, exception_handler=empty_on_404) cli_generic_update_command( __name__, 'resource update', 'azure.cli.command_modules.resource.custom#show_resource', 'azure.cli.command_modules.resource.custom#update_resource') cli_generic_update_command( __name__, 'group update', 'azure.mgmt.resource.resources.operations.resource_groups_operations#ResourceGroupsOperations.get', 'azure.mgmt.resource.resources.operations.resource_groups_operations#ResourceGroupsOperations.create_or_update', lambda: _resource_client_factory().resource_groups) cli_command( __name__, 'policy assignment create', 'azure.cli.command_modules.resource.custom#create_policy_assignment') cli_command( __name__, 'policy assignment delete', 'azure.cli.command_modules.resource.custom#delete_policy_assignment') cli_command( __name__, 'policy assignment list', 'azure.cli.command_modules.resource.custom#list_policy_assignment') cli_command(__name__, 'policy assignment show', 'azure.cli.command_modules.resource.custom#show_policy_assignment', exception_handler=empty_on_404)
cli_command(__name__, 'group deployment delete', 'azure.mgmt.resource.resources.operations.deployments_operations#DeploymentsOperations.delete', cf_deployments) cli_command(__name__, 'group deployment validate', 'azure.cli.command_modules.resource.custom#validate_arm_template', table_transformer=deployment_validate_table_format) cli_command(__name__, 'group deployment export', 'azure.cli.command_modules.resource.custom#export_deployment_as_template') # Resource group deployment operations commands cli_command(__name__, 'group deployment operation list', 'azure.mgmt.resource.resources.operations.deployment_operations#DeploymentOperations.list', cf_deployment_operations) cli_command(__name__, 'group deployment operation show', 'azure.cli.command_modules.resource.custom#get_deployment_operations', cf_deployment_operations, exception_handler=empty_on_404) cli_generic_update_command(__name__, 'resource update', 'azure.cli.command_modules.resource.custom#show_resource', 'azure.cli.command_modules.resource.custom#update_resource') cli_generic_update_command(__name__, 'group update', 'azure.mgmt.resource.resources.operations.resource_groups_operations#ResourceGroupsOperations.get', 'azure.mgmt.resource.resources.operations.resource_groups_operations#ResourceGroupsOperations.create_or_update', lambda: _resource_client_factory().resource_groups) cli_command(__name__, 'policy assignment create', 'azure.cli.command_modules.resource.custom#create_policy_assignment') cli_command(__name__, 'policy assignment delete', 'azure.cli.command_modules.resource.custom#delete_policy_assignment') cli_command(__name__, 'policy assignment list', 'azure.cli.command_modules.resource.custom#list_policy_assignment') cli_command(__name__, 'policy assignment show', 'azure.cli.command_modules.resource.custom#show_policy_assignment', exception_handler=empty_on_404) cli_command(__name__, 'policy definition create', 'azure.cli.command_modules.resource.custom#create_policy_definition') cli_command(__name__, 'policy definition delete', 'azure.mgmt.resource.policy.operations#PolicyDefinitionsOperations.delete', cf_policy_definitions) cli_command(__name__, 'policy definition list', 'azure.mgmt.resource.policy.operations#PolicyDefinitionsOperations.list', cf_policy_definitions) cli_command(__name__, 'policy definition show', 'azure.cli.command_modules.resource.custom#get_policy_definition', exception_handler=empty_on_404) cli_command(__name__, 'policy definition update', 'azure.cli.command_modules.resource.custom#update_policy_definition') if supported_api_version(ResourceType.MGMT_RESOURCE_POLICY, min_api='2017-06-01-preview'): cli_command(__name__, 'policy set-definition create', 'azure.cli.command_modules.resource.custom#create_policy_setdefinition') cli_command(__name__, 'policy set-definition delete', 'azure.mgmt.resource.policy.operations#PolicySetDefinitionsOperations.delete', cf_policy_set_definitions)