예제 #1
0
def iot_dps_create(cmd, client, dps_name, resource_group_name, location=None, sku=IotDpsSku.s1.value, unit=1):
    cli_ctx = cmd.cli_ctx
    _check_dps_name_availability(client.iot_dps_resource, dps_name)
    location = _ensure_location(cli_ctx, resource_group_name, location)
    dps_property = IotDpsPropertiesDescription()
    dps_description = ProvisioningServiceDescription(location, dps_property, IotDpsSkuInfo(sku, unit))
    return client.iot_dps_resource.create_or_update(resource_group_name, dps_name, dps_description)
예제 #2
0
파일: custom.py 프로젝트: yolocs/azure-cli
def iot_dps_linked_hub_update(client,
                              dps_name,
                              resource_group_name,
                              linked_hub,
                              apply_allocation_policy=None,
                              allocation_weight=None):
    dps_linked_hubs = []
    dps_linked_hubs.extend(
        iot_dps_linked_hub_list(client, dps_name, resource_group_name))
    if not _is_linked_hub_existed(dps_linked_hubs, linked_hub):
        raise CLIError("Access policy {0} doesn't existed.".format(linked_hub))

    for hub in dps_linked_hubs:
        if hub.name == linked_hub:
            if apply_allocation_policy is not None:
                hub.apply_allocation_policy = apply_allocation_policy
            if allocation_weight is not None:
                hub.allocation_weight = allocation_weight

    dps = iot_dps_get(client, dps_name, resource_group_name)
    dps_property = IotDpsPropertiesDescription(
        None, None, dps_linked_hubs, dps.properties.allocation_policy,
        dps.properties.authorization_policies)
    dps_description = ProvisioningServiceDescription(dps.location,
                                                     dps_property, dps.sku)

    client.iot_dps_resource.create_or_update(resource_group_name, dps_name,
                                             dps_description)
    return iot_dps_linked_hub_get(client, dps_name, resource_group_name,
                                  linked_hub)
예제 #3
0
def iot_dps_linked_hub_delete(cmd,
                              client,
                              dps_name,
                              resource_group_name,
                              linked_hub,
                              no_wait=False):
    dps_linked_hubs = []
    dps_linked_hubs.extend(
        iot_dps_linked_hub_list(client, dps_name, resource_group_name))
    if not _is_linked_hub_existed(dps_linked_hubs, linked_hub):
        raise CLIError("Linked hub {0} doesn't existed.".format(linked_hub))
    updated_hub = [
        p for p in dps_linked_hubs if p.name.lower() != linked_hub.lower()
    ]

    dps = iot_dps_get(client, dps_name, resource_group_name)
    dps_property = IotDpsPropertiesDescription(
        iot_hubs=updated_hub,
        allocation_policy=dps.properties.allocation_policy,
        authorization_policies=dps.properties.authorization_policies)
    dps_description = ProvisioningServiceDescription(location=dps.location,
                                                     properties=dps_property,
                                                     sku=dps.sku)

    if no_wait:
        return client.iot_dps_resource.create_or_update(
            resource_group_name, dps_name, dps_description)
    LongRunningOperation(cmd.cli_ctx)(client.iot_dps_resource.create_or_update(
        resource_group_name, dps_name, dps_description))
    return iot_dps_linked_hub_list(client, dps_name, resource_group_name)
예제 #4
0
def iot_dps_access_policy_update(cmd, client, dps_name, resource_group_name, access_policy_name, primary_key=None, secondary_key=None, rights=None, no_wait=False):
    dps_access_policies = []
    dps_access_policies.extend(iot_dps_access_policy_list(client, dps_name, resource_group_name))

    if not _is_policy_existed(dps_access_policies, access_policy_name):
        raise CLIError("Access policy {0} doesn't exist.".format(access_policy_name))

    for policy in dps_access_policies:
        if policy.key_name == access_policy_name:
            if primary_key is not None:
                policy.primary_key = primary_key
            if secondary_key is not None:
                policy.secondary_key = secondary_key
            if rights is not None:
                policy.rights = _convert_rights_to_access_rights(rights)

    dps = iot_dps_get(client, dps_name, resource_group_name)
    dps_property = IotDpsPropertiesDescription(iot_hubs=dps.properties.iot_hubs,
                                               allocation_policy=dps.properties.allocation_policy,
                                               authorization_policies=dps_access_policies)
    dps_description = ProvisioningServiceDescription(location=dps.location, properties=dps_property, sku=dps.sku)

    if no_wait:
        return client.iot_dps_resource.create_or_update(resource_group_name, dps_name, dps_description)
    LongRunningOperation(cmd.cli_ctx)(client.iot_dps_resource.create_or_update(resource_group_name, dps_name, dps_description))
    return iot_dps_access_policy_get(client, dps_name, resource_group_name, access_policy_name)
예제 #5
0
파일: custom.py 프로젝트: yolocs/azure-cli
def iot_dps_linked_hub_create(client,
                              dps_name,
                              resource_group_name,
                              connection_string,
                              location,
                              apply_allocation_policy=None,
                              allocation_weight=None):
    dps_linked_hubs = []
    dps_linked_hubs.extend(
        iot_dps_linked_hub_list(client, dps_name, resource_group_name))
    dps_linked_hubs.append(
        IotHubDefinitionDescription(connection_string, location,
                                    apply_allocation_policy,
                                    allocation_weight))

    dps = iot_dps_get(client, dps_name, resource_group_name)
    dps_property = IotDpsPropertiesDescription(
        None, None, dps_linked_hubs, dps.properties.allocation_policy,
        dps.properties.authorization_policies)
    dps_description = ProvisioningServiceDescription(dps.location,
                                                     dps_property, dps.sku)

    client.iot_dps_resource.create_or_update(resource_group_name, dps_name,
                                             dps_description)
    return iot_dps_linked_hub_list(client, dps_name, resource_group_name)
예제 #6
0
파일: custom.py 프로젝트: yolocs/azure-cli
def iot_dps_access_policy_create(client,
                                 dps_name,
                                 resource_group_name,
                                 access_policy_name,
                                 rights,
                                 primary_key=None,
                                 secondary_key=None):
    dps_access_policies = []
    dps_access_policies.extend(
        iot_dps_access_policy_list(client, dps_name, resource_group_name))
    if _is_policy_existed(dps_access_policies, access_policy_name):
        raise CLIError(
            "Access policy {0} already existed.".format(access_policy_name))

    access_policy_rights = _convert_rights_to_access_rights(rights)
    dps_access_policies.append(
        SharedAccessSignatureAuthorizationRuleAccessRightsDescription(
            access_policy_name, access_policy_rights, primary_key,
            secondary_key))

    dps = iot_dps_get(client, dps_name, resource_group_name)
    dps_property = IotDpsPropertiesDescription(
        None, None, dps.properties.iot_hubs, dps.properties.allocation_policy,
        dps_access_policies)
    dps_description = ProvisioningServiceDescription(dps.location,
                                                     dps_property, dps.sku)

    client.iot_dps_resource.create_or_update(resource_group_name, dps_name,
                                             dps_description)
    return iot_dps_access_policy_get(client, dps_name, resource_group_name,
                                     access_policy_name)
예제 #7
0
파일: custom.py 프로젝트: zooba/azure-cli
def iot_dps_access_policy_delete(cmd,
                                 client,
                                 dps_name,
                                 resource_group_name,
                                 access_policy_name,
                                 no_wait=False):
    dps_access_policies = []
    dps_access_policies.extend(
        iot_dps_access_policy_list(client, dps_name, resource_group_name))
    if not _is_policy_existed(dps_access_policies, access_policy_name):
        raise CLIError(
            "Access policy {0} doesn't existed.".format(access_policy_name))
    updated_policies = [
        p for p in dps_access_policies
        if p.key_name.lower() != access_policy_name.lower()
    ]

    dps = iot_dps_get(client, dps_name, resource_group_name)
    dps_property = IotDpsPropertiesDescription(
        None, None, dps.properties.iot_hubs, dps.properties.allocation_policy,
        updated_policies)
    dps_description = ProvisioningServiceDescription(dps.location,
                                                     dps_property, dps.sku)

    if no_wait:
        return client.iot_dps_resource.create_or_update(
            resource_group_name, dps_name, dps_description)
    LongRunningOperation(cmd.cli_ctx)(client.iot_dps_resource.create_or_update(
        resource_group_name, dps_name, dps_description))
    return iot_dps_access_policy_list(client, dps_name, resource_group_name)
예제 #8
0
def iot_dps_access_policy_create(cmd, client, dps_name, resource_group_name, access_policy_name, rights, primary_key=None, secondary_key=None, no_wait=False):
    dps_access_policies = []
    dps_access_policies.extend(iot_dps_access_policy_list(client, dps_name, resource_group_name))
    if _is_policy_existed(dps_access_policies, access_policy_name):
        raise CLIError("Access policy {0} already existed.".format(access_policy_name))

    access_policy_rights = _convert_rights_to_access_rights(rights)
    dps_access_policies.append(SharedAccessSignatureAuthorizationRuleAccessRightsDescription(
        key_name=access_policy_name, rights=access_policy_rights, primary_key=primary_key, secondary_key=secondary_key))

    dps = iot_dps_get(client, dps_name, resource_group_name)
    dps_property = IotDpsPropertiesDescription(iot_hubs=dps.properties.iot_hubs,
                                               allocation_policy=dps.properties.allocation_policy,
                                               authorization_policies=dps_access_policies)
    dps_description = ProvisioningServiceDescription(location=dps.location, properties=dps_property, sku=dps.sku)

    if no_wait:
        return client.iot_dps_resource.create_or_update(resource_group_name, dps_name, dps_description)
    LongRunningOperation(cmd.cli_ctx)(client.iot_dps_resource.create_or_update(resource_group_name, dps_name, dps_description))
    return iot_dps_access_policy_get(client, dps_name, resource_group_name, access_policy_name)
예제 #9
0
파일: custom.py 프로젝트: yolocs/azure-cli
def iot_dps_linked_hub_delete(client, dps_name, resource_group_name,
                              linked_hub):
    dps_linked_hubs = []
    dps_linked_hubs.extend(
        iot_dps_linked_hub_list(client, dps_name, resource_group_name))
    if not _is_linked_hub_existed(dps_linked_hubs, linked_hub):
        raise CLIError("Linked hub {0} doesn't existed.".format(linked_hub))
    updated_hub = [
        p for p in dps_linked_hubs if p.name.lower() != linked_hub.lower()
    ]

    dps = iot_dps_get(client, dps_name, resource_group_name)
    dps_property = IotDpsPropertiesDescription(
        None, None, updated_hub, dps.properties.allocation_policy,
        dps.properties.authorization_policies)
    dps_description = ProvisioningServiceDescription(dps.location,
                                                     dps_property, dps.sku)

    client.iot_dps_resource.create_or_update(resource_group_name, dps_name,
                                             dps_description)
    return iot_dps_linked_hub_list(client, dps_name, resource_group_name)
예제 #10
0
def iot_dps_linked_hub_create(cmd,
                              client,
                              dps_name,
                              resource_group_name,
                              connection_string,
                              location,
                              apply_allocation_policy=None,
                              allocation_weight=None,
                              no_wait=False):
    dps_linked_hubs = []
    dps_linked_hubs.extend(
        iot_dps_linked_hub_list(client, dps_name, resource_group_name))

    # Hack due to DPS Swagger/SDK issue
    # In the newer API version the name parameter is required
    # however in the SDK name is read-only/assigned to None
    client.api_version = '2017-11-15'
    dps_linked_hubs.append(
        IotHubDefinitionDescription(
            connection_string=connection_string,
            location=location,
            apply_allocation_policy=apply_allocation_policy,
            allocation_weight=allocation_weight))

    dps = iot_dps_get(client, dps_name, resource_group_name)
    dps_property = IotDpsPropertiesDescription(
        iot_hubs=dps_linked_hubs,
        allocation_policy=dps.properties.allocation_policy,
        authorization_policies=dps.properties.authorization_policies)
    dps_description = ProvisioningServiceDescription(location=dps.location,
                                                     properties=dps_property,
                                                     sku=dps.sku)

    if no_wait:
        return client.iot_dps_resource.create_or_update(
            resource_group_name, dps_name, dps_description)
    LongRunningOperation(cmd.cli_ctx)(client.iot_dps_resource.create_or_update(
        resource_group_name, dps_name, dps_description))
    return iot_dps_linked_hub_list(client, dps_name, resource_group_name)