示例#1
0
    def handle_folding(namespace):
        base_name_val = getattr(namespace, base_name)
        type_field_val = getattr(namespace, type_field)
        parent_name_val = getattr(namespace,
                                  parent_name) if parent_name else None

        if base_name_val is None or type_field_val is not None:
            # Either no name was specified, or the user specified the type of resource
            # (i.e. new/existing/none)
            pass
        elif base_name_val in ('', '""', "''"):
            # An empty name specified - that means that we are neither referencing an existing
            # field, or the name is set to an empty string.  We check for all types of quotes
            # so scripts can run cross-platform.
            if not none_flag_value:
                raise CLIError('Field {} cannot be none.'.format(
                    make_camel_case(base_name)))
            setattr(namespace, type_field, none_flag_value)
            setattr(namespace, base_name, None)
        else:
            from azure.cli.core.commands.client_factory import get_subscription_id
            has_parent = parent_name is not None and parent_type is not None
            if is_valid_resource_id(base_name_val):
                resource_id_parts = parse_resource_id(base_name_val)
            elif has_parent:
                if not parent_name_val and base_required:
                    raise CLIError(
                        "Must specify '{}' when specifying '{}' name.".format(
                            parent_option_flag or parent_name, base_name))
                resource_id_parts = dict(
                    name=parent_name_val,
                    resource_group=namespace.resource_group_name,
                    namespace=parent_type.split('/')[0],
                    type=parent_type.split('/')[1],
                    subscription=get_subscription_id(),
                    child_name=base_name_val,
                    child_type=resource_type)
            else:
                resource_id_parts = dict(
                    name=base_name_val,
                    resource_group=namespace.resource_group_name,
                    namespace=resource_type.split('/')[0],
                    type=resource_type.split('/')[1],
                    subscription=get_subscription_id())

            if resource_exists(**resource_id_parts):
                setattr(namespace, type_field, existing_id_flag_value)
                setattr(namespace, base_name, resource_id(**resource_id_parts))
            elif is_valid_resource_id(base_name_val):
                raise CLIError('ID {} does not exist. Please specify '
                               'a name to create a new resource.'.format(
                                   resource_id(**resource_id_parts)))
            elif not new_flag_value:
                raise CLIError(
                    'Referenced resource {} does not exist. Please create the required '
                    'resource and try again.'.format(
                        resource_id(**resource_id_parts)))
            else:
                setattr(namespace, type_field, new_flag_value)
示例#2
0
def transform_queue_stats_output(result):
    if isinstance(result, dict):
        new_result = {}
        from azure.cli.core.commands.arm import make_camel_case
        for key in result.keys():
            new_key = make_camel_case(key)
            new_result[new_key] = transform_queue_stats_output(result[key])
        return new_result
    return result
示例#3
0
    def handle_folding(namespace):
        base_name_val = getattr(namespace, base_name)
        type_field_val = getattr(namespace, type_field)
        parent_name_val = getattr(namespace, parent_name) if parent_name else None

        if base_name_val is None or type_field_val is not None:
            # Either no name was specified, or the user specified the type of resource
            # (i.e. new/existing/none)
            pass
        elif base_name_val in ('', '""', "''"):
            # An empty name specified - that means that we are neither referencing an existing
            # field, or the name is set to an empty string.  We check for all types of quotes
            # so scripts can run cross-platform.
            if not none_flag_value:
                raise CLIError('Field {} cannot be none.'.format(make_camel_case(base_name)))
            setattr(namespace, type_field, none_flag_value)
            setattr(namespace, base_name, None)
        else:
            from azure.cli.core.commands.client_factory import get_subscription_id
            has_parent = parent_name is not None and parent_type is not None
            if is_valid_resource_id(base_name_val):
                resource_id_parts = parse_resource_id(base_name_val)
            elif has_parent:
                if not parent_name_val and base_required:
                    raise CLIError("Must specify '{}' when specifying '{}' name.".format(
                        parent_option_flag or parent_name, base_name))
                resource_id_parts = dict(
                    name=parent_name_val,
                    resource_group=namespace.resource_group_name,
                    namespace=parent_type.split('/')[0],
                    type=parent_type.split('/')[1],
                    subscription=get_subscription_id(),
                    child_name=base_name_val,
                    child_type=resource_type)
            else:
                resource_id_parts = dict(
                    name=base_name_val,
                    resource_group=namespace.resource_group_name,
                    namespace=resource_type.split('/')[0],
                    type=resource_type.split('/')[1],
                    subscription=get_subscription_id())

            if resource_exists(**resource_id_parts):
                setattr(namespace, type_field, existing_id_flag_value)
                setattr(namespace, base_name, resource_id(**resource_id_parts))
            elif is_valid_resource_id(base_name_val):
                raise CLIError('ID {} does not exist. Please specify '
                               'a name to create a new resource.'.format(
                                   resource_id(**resource_id_parts)))
            elif not new_flag_value:
                raise CLIError('Referenced resource {} does not exist. Please create the required '
                               'resource and try again.'.format(resource_id(**resource_id_parts)))
            else:
                setattr(namespace, type_field, new_flag_value)
示例#4
0
def transform_message_output(result):
    result = todict(result)
    new_result = {
        'expirationTime': result.pop('expiresOn', None),
        'insertionTime': result.pop('insertedOn', None),
        'timeNextVisible': result.pop('nextVisibleOn', None)
    }
    from azure.cli.core.commands.arm import make_camel_case
    for key in sorted(result.keys()):
        new_result[make_camel_case(key)] = result[key]
    return new_result
def transform_blob_service_properties(result):
    from azure.cli.core.commands.arm import make_camel_case
    static_website = todict(result.pop("static_website", None))
    static_website["errorDocument_404Path"] = static_website.pop(
        "errorDocument404Path", None)
    new_result = {
        "cors": result.pop("cors", None),
        "deleteRetentionPolicy": result.pop("delete_retention_policy", None),
        "hourMetrics": result.pop("hour_metrics", None),
        "logging": result.pop("analytics_logging", None),
        "minuteMetrics": result.pop("minute_metrics", None),
        "staticWebsite": static_website
    }
    for key in result:
        new_result[make_camel_case(key)] = result[key]
    return new_result