예제 #1
0
파일: custom.py 프로젝트: yanjuna/azure-cli
def create(
        client, resource_group_name, account_name, sku_name, kind, location, custom_domain=None,
        tags=None, api_properties=None, assign_identity=False, storage=None, encryption=None, yes=None):

    terms = 'Notice\nMicrosoft will use data you send to Bing Search Services'\
        ' to improve Microsoft products and services.'\
        'Where you send personal data to these Cognitive Services, you are responsible '\
        'for obtaining sufficient consent from the data subjects.'\
        'The General Privacy and Security Terms in the Online Services Terms '\
        'do not apply to these Cognitive Services.'\
        'Please refer to the Microsoft Cognitive Services section in the Online '\
        'Services Terms'\
        ' (https://www.microsoft.com/Licensing/product-licensing/products.aspx)'\
        ' for details.'\
        'Microsoft offers policy controls that may be used to disable new Cognitive'\
        ' Services deployments (https://docs.microsoft.com/azure/cognitive-servic'\
        'es/cognitive-services-apis-create-account).'
    hint = '\nPlease select'
    import re
    pattern = re.compile("^[Bb]ing\\..*$")
    if pattern.match(kind):
        if yes:
            logger.warning(terms)
        else:
            logger.warning(terms)
            option = prompt_y_n(hint)
            if not option:
                raise CLIError('Operation cancelled.')
    sku = Sku(name=sku_name)

    properties = CognitiveServicesAccountProperties()
    if api_properties is not None:
        api_properties = CognitiveServicesAccountApiProperties.deserialize(api_properties)
        properties.api_properties = api_properties
    if custom_domain:
        properties.custom_sub_domain_name = custom_domain
    params = CognitiveServicesAccount(sku=sku, kind=kind, location=location,
                                      properties=properties, tags=tags)
    if assign_identity:
        params.identity = Identity(type=IdentityType.system_assigned)

    if storage is not None:
        params.properties.user_owned_storage = json.loads(storage)

    if encryption is not None:
        params.properties.encryption = json.loads(encryption)

    return client.create(resource_group_name, account_name, params)
예제 #2
0
def recover(client, location, resource_group_name, account_name):
    properties = CognitiveServicesAccountProperties()
    properties.restore = True
    params = CognitiveServicesAccount(properties=properties)
    params.location = location

    return client.begin_create(resource_group_name, account_name, params)
예제 #3
0
def add_network_rule(client,
                     resource_group_name,
                     account_name,
                     subnet=None,
                     vnet_name=None,
                     ip_address=None):  # pylint: disable=unused-argument
    sa = client.get(resource_group_name, account_name)
    rules = sa.properties.network_acls
    if rules is None:
        rules = default_network_acls()

    if subnet:
        from msrestazure.tools import is_valid_resource_id
        if not is_valid_resource_id(subnet):
            raise CLIError(
                "Expected fully qualified resource ID: got '{}'".format(
                    subnet))

        if not rules.virtual_network_rules:
            rules.virtual_network_rules = []
        rules.virtual_network_rules.append(
            VirtualNetworkRule(id=subnet,
                               ignore_missing_vnet_service_endpoint=True))
    if ip_address:
        if not rules.ip_rules:
            rules.ip_rules = []
        rules.ip_rules.append(IpRule(value=ip_address))

    properties = CognitiveServicesAccountProperties()
    properties.network_acls = rules
    params = CognitiveServicesAccount(properties=properties)

    return client.begin_update(resource_group_name, account_name, params)
예제 #4
0
def update(client,
           resource_group_name,
           account_name,
           sku_name=None,
           custom_domain=None,
           tags=None,
           api_properties=None,
           storage=None,
           encryption=None):

    if sku_name is None:
        sa = client.get(resource_group_name, account_name)
        sku_name = sa.sku.name

    sku = Sku(name=sku_name)

    properties = CognitiveServicesAccountProperties()
    if api_properties is not None:
        api_properties = CognitiveServicesAccountApiProperties.deserialize(
            api_properties)
        properties.api_properties = api_properties
    if custom_domain:
        properties.custom_sub_domain_name = custom_domain
    params = CognitiveServicesAccount(sku=sku,
                                      properties=properties,
                                      tags=tags)

    if storage is not None:
        params.properties.user_owned_storage = json.loads(storage)

    if encryption is not None:
        params.properties.encryption = json.loads(encryption)

    return client.begin_update(resource_group_name, account_name, params)
예제 #5
0
def identity_remove(client, resource_group_name, account_name):
    """
    Remove the identity for Azure Cognitive Services account.
    """
    params = CognitiveServicesAccount()
    params.identity = Identity(type=IdentityType.none)
    client.begin_update(resource_group_name, account_name, params)
예제 #6
0
def remove_network_rule(client,
                        resource_group_name,
                        account_name,
                        ip_address=None,
                        subnet=None,
                        vnet_name=None):  # pylint: disable=unused-argument
    """
    Remove a network rule for Azure Cognitive Services account.
    """
    sa = client.get(resource_group_name, account_name)
    rules = sa.properties.network_acls
    if rules is None:
        # nothing to update, but return the object
        return client.update(resource_group_name, account_name)

    if subnet:
        rules.virtual_network_rules = [
            x for x in rules.virtual_network_rules if not x.id.endswith(subnet)
        ]
    if ip_address:
        rules.ip_rules = [x for x in rules.ip_rules if x.value != ip_address]

    properties = CognitiveServicesAccountProperties()
    properties.network_acls = rules
    params = CognitiveServicesAccount(properties=properties)

    return client.begin_update(resource_group_name, account_name, params)
예제 #7
0
def identity_assign(client, resource_group_name, account_name):
    """
    Assign the identity for Azure Cognitive Services account.
    """
    params = CognitiveServicesAccount()
    params.identity = Identity(type=IdentityType.system_assigned)
    sa = client.begin_update(resource_group_name, account_name,
                             params).result()
    return sa.identity if sa.identity else {}
예제 #8
0
def create_resource (resource_name, kind, sku_name, location):
	print("Creating resource: " + resource_name + "...")
# The parameter "properties" must be an empty object.
	parameters = CognitiveServicesAccount(sku=Sku(name=sku_name), kind=kind, location=location, properties={})
	result = client.accounts.create(resource_group_name, resource_name, parameters)
	print("Resource created.")
	print()
	print("ID: " + result.id)
	print("Name: " + result.name)
	print("Type: " + result.type)
	print()
예제 #9
0
def create_resource(resource_name, kind, sku_name, location):
    print("Creating resource: " + resource_name + "...")
    # NOTE If you do not want to use a custom subdomain name, remove the customSubDomainName
    # property from the properties object.
    parameters = CognitiveServicesAccount(
        sku=Sku(name=sku_name),
        kind=kind,
        location=location,
        properties={'custom_sub_domain_name': subdomain_name})
    result = client.accounts.create(resource_group_name, resource_name,
                                    parameters)
    print("Resource created.")
    print()
    print("ID: " + result.id)
    print("Name: " + result.name)
    print("Type: " + result.type)
    print()
예제 #10
0
def identity_remove(client, resource_group_name, account_name):
    params = CognitiveServicesAccount()
    params.identity = Identity(type=IdentityType.none)
    client.update(resource_group_name, account_name, params)
예제 #11
0
def identity_assign(client, resource_group_name, account_name):
    params = CognitiveServicesAccount()
    params.identity = Identity(type=IdentityType.system_assigned)
    sa = client.update(resource_group_name, account_name, params)
    return sa.identity if sa.identity else {}