本文整理汇总了Python中msrestazure.tools.resource_id函数的典型用法代码示例。如果您正苦于以下问题:Python resource_id函数的具体用法?Python resource_id怎么用?Python resource_id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了resource_id函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_nw_test_connectivity_namespace
def process_nw_test_connectivity_namespace(cmd, namespace):
from msrestazure.tools import is_valid_resource_id, resource_id, parse_resource_id
compute_client = get_mgmt_service_client(cmd.cli_ctx, ResourceType.MGMT_COMPUTE).virtual_machines
vm_name = parse_resource_id(namespace.source_resource)['name']
rg = namespace.resource_group_name or parse_resource_id(namespace.source_resource).get('resource_group', None)
if not rg:
raise CLIError('usage error: --source-resource ID | --source-resource NAME --resource-group NAME')
vm = compute_client.get(rg, vm_name)
namespace.location = vm.location # pylint: disable=no-member
get_network_watcher_from_location(remove=True)(cmd, namespace)
if namespace.source_resource and not is_valid_resource_id(namespace.source_resource):
namespace.source_resource = resource_id(
subscription=get_subscription_id(cmd.cli_ctx),
resource_group=rg,
namespace='Microsoft.Compute',
type='virtualMachines',
name=namespace.source_resource)
if namespace.dest_resource and not is_valid_resource_id(namespace.dest_resource):
namespace.dest_resource = resource_id(
subscription=get_subscription_id(cmd.cli_ctx),
resource_group=namespace.resource_group_name,
namespace='Microsoft.Compute',
type='virtualMachines',
name=namespace.dest_resource)
示例2: process_nw_packet_capture_create_namespace
def process_nw_packet_capture_create_namespace(cmd, namespace):
from msrestazure.tools import is_valid_resource_id, resource_id
get_network_watcher_from_vm(cmd, namespace)
storage_usage = CLIError('usage error: --storage-account NAME_OR_ID [--storage-path '
'PATH] [--file-path PATH] | --file-path PATH')
if not namespace.storage_account and not namespace.file_path:
raise storage_usage
if namespace.storage_path and not namespace.storage_account:
raise storage_usage
if not is_valid_resource_id(namespace.vm):
namespace.vm = resource_id(
subscription=get_subscription_id(cmd.cli_ctx),
resource_group=namespace.resource_group_name,
namespace='Microsoft.Compute',
type='virtualMachines',
name=namespace.vm)
if namespace.storage_account and not is_valid_resource_id(namespace.storage_account):
namespace.storage_account = resource_id(
subscription=get_subscription_id(cmd.cli_ctx),
resource_group=namespace.resource_group_name,
namespace='Microsoft.Storage',
type='storageAccounts',
name=namespace.storage_account)
if namespace.file_path:
file_path = namespace.file_path
if not file_path.endswith('.cap'):
raise CLIError("usage error: --file-path PATH must end with the '*.cap' extension")
file_path = file_path.replace('/', '\\')
namespace.file_path = file_path
示例3: validate_diagnostic_settings
def validate_diagnostic_settings(cmd, namespace):
from azure.cli.core.commands.client_factory import get_subscription_id
from msrestazure.tools import is_valid_resource_id, resource_id
from knack.util import CLIError
resource_group_error = "--resource-group is required when name is provided for storage account or workspace or " \
"service bus namespace and rule. "
get_target_resource_validator('resource_uri', required=True, preserve_resource_group_parameter=True)(cmd, namespace)
if namespace.storage_account and not is_valid_resource_id(namespace.storage_account):
if namespace.resource_group_name is None:
raise CLIError(resource_group_error)
namespace.storage_account = resource_id(subscription=get_subscription_id(cmd.cli_ctx),
resource_group=namespace.resource_group_name,
namespace='microsoft.Storage',
type='storageAccounts',
name=namespace.storage_account)
if namespace.workspace and not is_valid_resource_id(namespace.workspace):
if namespace.resource_group_name is None:
raise CLIError(resource_group_error)
namespace.workspace = resource_id(subscription=get_subscription_id(cmd.cli_ctx),
resource_group=namespace.resource_group_name,
namespace='microsoft.OperationalInsights',
type='workspaces',
name=namespace.workspace)
if not namespace.storage_account and not namespace.workspace and not namespace.event_hub:
raise CLIError(
'One of the following parameters is expected: --storage-account, --event-hub-name, or --workspace.')
try:
del namespace.resource_group_name
except AttributeError:
pass
示例4: validate_diagnostic_settings
def validate_diagnostic_settings(cmd, namespace):
from azure.cli.core.commands.client_factory import get_subscription_id
from msrestazure.tools import is_valid_resource_id, resource_id, parse_resource_id
from knack.util import CLIError
get_target_resource_validator('resource_uri', required=True, preserve_resource_group_parameter=True)(cmd, namespace)
if not namespace.resource_group_name:
namespace.resource_group_name = parse_resource_id(namespace.resource_uri)['resource_group']
if namespace.storage_account and not is_valid_resource_id(namespace.storage_account):
namespace.storage_account = resource_id(subscription=get_subscription_id(cmd.cli_ctx),
resource_group=namespace.resource_group_name,
namespace='microsoft.Storage',
type='storageAccounts',
name=namespace.storage_account)
if namespace.workspace and not is_valid_resource_id(namespace.workspace):
namespace.workspace = resource_id(subscription=get_subscription_id(cmd.cli_ctx),
resource_group=namespace.resource_group_name,
namespace='microsoft.OperationalInsights',
type='workspaces',
name=namespace.workspace)
if namespace.event_hub and is_valid_resource_id(namespace.event_hub):
namespace.event_hub = parse_resource_id(namespace.event_hub)['name']
if namespace.event_hub_rule:
if not is_valid_resource_id(namespace.event_hub_rule):
if not namespace.event_hub:
raise CLIError('usage error: --event-hub-rule ID | --event-hub-rule NAME --event-hub NAME')
# use value from --event-hub if the rule is a name
namespace.event_hub_rule = resource_id(
subscription=get_subscription_id(cmd.cli_ctx),
resource_group=namespace.resource_group_name,
namespace='Microsoft.EventHub',
type='namespaces',
name=namespace.event_hub,
child_type_1='AuthorizationRules',
child_name_1=namespace.event_hub_rule)
elif not namespace.event_hub:
# extract the event hub name from `--event-hub-rule` if provided as an ID
namespace.event_hub = parse_resource_id(namespace.event_hub_rule)['name']
if not any([namespace.storage_account, namespace.workspace, namespace.event_hub]):
raise CLIError(
'usage error - expected one or more: --storage-account NAME_OR_ID | --workspace NAME_OR_ID '
'| --event-hub NAME_OR_ID | --event-hub-rule ID')
try:
del namespace.resource_group_name
except AttributeError:
pass
示例5: _replica_create
def _replica_create(cmd, client, resource_group_name, server_name, source_server, no_wait=False, **kwargs):
provider = 'Microsoft.DBForMySQL' if isinstance(client, MySqlServersOperations) else 'Microsoft.DBforPostgreSQL'
# set source server id
if not is_valid_resource_id(source_server):
if len(source_server.split('/')) == 1:
source_server = resource_id(subscription=get_subscription_id(cmd.cli_ctx),
resource_group=resource_group_name,
namespace=provider,
type='servers',
name=source_server)
else:
raise CLIError('The provided source-server {} is invalid.'.format(source_server))
source_server_id_parts = parse_resource_id(source_server)
try:
source_server_object = client.get(source_server_id_parts['resource_group'], source_server_id_parts['name'])
except CloudError as e:
raise CLIError('Unable to get source server: {}.'.format(str(e)))
parameters = None
if provider == 'Microsoft.DBForMySQL':
from azure.mgmt.rdbms import mysql
parameters = mysql.models.ServerForCreate(
sku=mysql.models.Sku(name=source_server_object.sku.name),
properties=mysql.models.ServerPropertiesForReplica(source_server_id=source_server),
location=source_server_object.location)
return sdk_no_wait(no_wait, client.create, resource_group_name, server_name, parameters)
示例6: simple_validator
def simple_validator(cmd, namespace):
if namespace.virtual_network_name is None and namespace.subnet is None:
return
if namespace.subnet == '':
return
usage_error = ValueError('incorrect usage: ( --subnet ID | --subnet NAME --vnet-name NAME)')
# error if vnet-name is provided without subnet
if namespace.virtual_network_name and not namespace.subnet:
raise usage_error
# determine if subnet is name or ID
is_id = is_valid_resource_id(namespace.subnet)
# error if vnet-name is provided along with a subnet ID
if is_id and namespace.virtual_network_name:
raise usage_error
elif not is_id and not namespace.virtual_network_name:
raise usage_error
if not is_id:
namespace.subnet = resource_id(
subscription=get_subscription_id(cmd.cli_ctx),
resource_group=namespace.resource_group_name,
namespace='Microsoft.Network',
type='virtualNetworks',
name=namespace.virtual_network_name,
child_type_1='subnets',
child_name_1=namespace.subnet)
示例7: create
def create(cmd, client, resource_group_name, activity_log_alert_name, scopes=None, condition=None,
action_groups=frozenset(), tags=None, disable=False, description=None, webhook_properties=None):
from msrestazure.tools import resource_id
from azure.mgmt.monitor.models import (ActivityLogAlertResource, ActivityLogAlertAllOfCondition,
ActivityLogAlertLeafCondition, ActivityLogAlertActionList)
from azure.mgmt.monitor.models import ActivityLogAlertActionGroup as ActionGroup
from azure.cli.core.commands.client_factory import get_subscription_id
from knack.util import CLIError
if not scopes:
scopes = [resource_id(subscription=get_subscription_id(cmd.cli_ctx), resource_group=resource_group_name)]
if _get_alert_settings(client, resource_group_name, activity_log_alert_name, throw_if_missing=False):
raise CLIError('The activity log alert {} already exists in resource group {}.'.format(activity_log_alert_name,
resource_group_name))
# Add alert conditions
condition = condition or ActivityLogAlertAllOfCondition(
all_of=[ActivityLogAlertLeafCondition(field='category', equals='ServiceHealth')])
# Add action groups
action_group_rids = _normalize_names(cmd.cli_ctx, action_groups, resource_group_name, 'microsoft.insights',
'actionGroups')
action_groups = [ActionGroup(action_group_id=i, webhook_properties=webhook_properties) for i in action_group_rids]
alert_actions = ActivityLogAlertActionList(action_groups=action_groups)
settings = ActivityLogAlertResource(location='global', scopes=scopes, condition=condition,
actions=alert_actions, enabled=not disable, description=description, tags=tags)
return client.create_or_update(resource_group_name=resource_group_name,
activity_log_alert_name=activity_log_alert_name, activity_log_alert=settings)
示例8: _validate_name_or_id
def _validate_name_or_id(public_ip):
# determine if public_ip_address is name or ID
is_id = is_valid_resource_id(public_ip)
return public_ip if is_id else resource_id(
subscription=get_subscription_id(cmd.cli_ctx),
resource_group=namespace.resource_group_name,
namespace='Microsoft.Network',
type='publicIPAddresses',
name=public_ip)
示例9: validate_virtual_hub
def validate_virtual_hub(cmd, namespace):
from msrestazure.tools import is_valid_resource_id, resource_id
if namespace.virtual_hub and not is_valid_resource_id(namespace.virtual_hub):
namespace.virtual_hub = resource_id(
subscription=get_subscription_id(cmd.cli_ctx),
resource_group=namespace.resource_group_name,
namespace='Microsoft.Network',
type='virtualHubs',
name=namespace.virtual_hub
)
示例10: validate_express_route_port
def validate_express_route_port(cmd, namespace):
from msrestazure.tools import is_valid_resource_id, resource_id
if namespace.express_route_port and not is_valid_resource_id(namespace.express_route_port):
namespace.express_route_port = resource_id(
subscription=get_subscription_id(cmd.cli_ctx),
resource_group=namespace.resource_group_name,
namespace='Microsoft.Network',
type='expressRoutePorts',
name=namespace.express_route_port
)
示例11: _generate_ag_subproperty_id
def _generate_ag_subproperty_id(cli_ctx, namespace, child_type, child_name, subscription=None):
from msrestazure.tools import resource_id
return resource_id(
subscription=subscription or get_subscription_id(cli_ctx),
resource_group=namespace.resource_group_name,
namespace='Microsoft.Network',
type='applicationGateways',
name=namespace.application_gateway_name,
child_type_1=child_type,
child_name_1=child_name)
示例12: validate_route_filter
def validate_route_filter(cmd, namespace):
from msrestazure.tools import is_valid_resource_id, resource_id
if namespace.route_filter:
if not is_valid_resource_id(namespace.route_filter):
namespace.route_filter = resource_id(
subscription=get_subscription_id(cmd.cli_ctx),
resource_group=namespace.resource_group_name,
namespace='Microsoft.Network',
type='routeFilters',
name=namespace.route_filter)
示例13: _generate_lb_subproperty_id
def _generate_lb_subproperty_id(cli_ctx, namespace, child_type, child_name, subscription=None):
from msrestazure.tools import resource_id
return resource_id(
subscription=subscription or get_subscription_id(cli_ctx),
resource_group=namespace.resource_group_name,
namespace='Microsoft.Network',
type='loadBalancers',
name=namespace.load_balancer_name,
child_type_1=child_type,
child_name_1=child_name)
示例14: validator
def validator(cmd, namespace):
from msrestazure.tools import resource_id
type_field_name = '{}_type'.format(property_name)
property_val = getattr(namespace, property_name, None)
parent_val = getattr(namespace, parent_name, None) if parent_name else None
# Check for the different scenarios (order matters)
# 1) provided value indicates None (pair of empty quotes)
if property_val in ('', '""', "''") or (property_val is None and default_none):
if not allow_none:
raise CLIError('{} cannot be None.'.format(property_option))
setattr(namespace, type_field_name, 'none')
setattr(namespace, property_name, None)
if parent_name and parent_val:
logger.warning('Ignoring: %s %s', parent_option, parent_val)
setattr(namespace, parent_name, None)
return # SUCCESS
# Create a resource ID we can check for existence.
(resource_id_parts, value_was_id) = _validate_name_or_id(
cmd.cli_ctx, namespace.resource_group_name, property_val, property_type, parent_val, parent_type)
# 2) resource exists
if resource_exists(cmd.cli_ctx, **resource_id_parts):
setattr(namespace, type_field_name, 'existingId')
setattr(namespace, property_name, resource_id(**resource_id_parts))
if parent_val:
if value_was_id:
logger.warning('Ignoring: %s %s', parent_option, parent_val)
setattr(namespace, parent_name, None)
return # SUCCESS
# if a parent name was required but not specified, raise a usage error
if has_parent and not value_was_id and not parent_val and not allow_new:
raise ValueError('incorrect usage: {0} ID | {0} NAME {1} NAME'.format(
property_option, parent_option))
# if non-existent ID was supplied, throw error depending on whether a new resource can
# be created.
if value_was_id:
usage_message = '{} NAME'.format(property_option) if not has_parent \
else '{} NAME [{} NAME]'.format(property_option, parent_option)
action_message = 'Specify ( {} ) to create a new resource.'.format(usage_message) if \
allow_new else 'Create the required resource and try again.'
raise CLIError('{} {} does not exist. {}'.format(
property_name, property_val, action_message))
# 3) try to create new resource
if allow_new:
setattr(namespace, type_field_name, 'new')
else:
raise CLIError(
'{} {} does not exist. Create the required resource and try again.'.format(
property_name, property_val))
示例15: validate_storageaccount
def validate_storageaccount(cmd, namespace):
from azure.cli.core.commands.client_factory import get_subscription_id
from msrestazure.tools import is_valid_resource_id, resource_id
if namespace.storage_account_resource_id:
if not is_valid_resource_id(namespace.storage_account_resource_id):
namespace.storage_account_resource_id = resource_id(
subscription=get_subscription_id(cmd.cli_ctx),
resource_group=namespace.resource_group_name,
namespace='Microsoft.Storage',
type='storageAccounts',
name=namespace.storage_account_resource_id)