Ejemplo n.º 1
0
def create_profile(client, resource_group_name, name,
                   sku=SkuName.standard_akamai.value,
                   location=None, tags=None):
    # pylint: disable=too-many-arguments
    from azure.mgmt.cdn.models import (Profile, Sku)
    profile = Profile(location, Sku(name=sku), tags=tags)
    return client.profiles.create(resource_group_name, name, profile)
Ejemplo n.º 2
0
    def create_cdnprofile(self):
        '''
        Creates a Azure CDN profile.

        :return: deserialized Azure CDN profile instance state dictionary
        '''
        self.log("Creating the Azure CDN profile instance {0}".format(
            self.name))

        parameters = Profile(location=self.location,
                             sku=Sku(name=self.sku),
                             tags=self.tags)

        import uuid
        xid = str(uuid.uuid1())

        try:
            poller = self.cdn_client.profiles.create(
                self.resource_group,
                self.name,
                parameters,
                custom_headers={'x-ms-client-request-id': xid})
            response = self.get_poller_result(poller)
            return cdnprofile_to_dict(response)
        except ErrorResponseException as exc:
            self.log('Error attempting to create Azure CDN profile instance.')
            self.fail(
                "Error creating Azure CDN profile instance: {0}.\n Request id: {1}"
                .format(exc.message, xid))
Ejemplo n.º 3
0
def create_afd_profile(client: ProfilesOperations, resource_group_name, profile_name,
                       sku: SkuName,
                       tags=None):
    from azure.mgmt.cdn.models import (Profile, Sku)

    # Force location to global
    profile = Profile(location="global", sku=Sku(name=sku), tags=tags)
    return client.create(resource_group_name, profile_name, profile)
Ejemplo n.º 4
0
def create_profile(client,
                   resource_group_name,
                   name,
                   sku=SkuName.standard_akamai.value,
                   location=None,
                   tags=None):
    from azure.mgmt.cdn.models import (Profile, Sku)
    profile = Profile(location=location, sku=Sku(name=sku), tags=tags)
    return client.profiles.begin_create(resource_group_name, name, profile)
Ejemplo n.º 5
0
def create_afd_profile(client: ProfilesOperations,
                       resource_group_name,
                       profile_name,
                       sku: SkuName,
                       origin_response_timeout_seconds=30,
                       tags=None):
    from azure.mgmt.cdn.models import (Profile, Sku)

    # Force location to global
    profile = Profile(
        location="global",
        sku=Sku(name=sku),
        tags=tags,
        origin_response_timeout_seconds=origin_response_timeout_seconds)
    return client.begin_create(resource_group_name, profile_name, profile)
Ejemplo n.º 6
0
def set_waf_policy(client,
                   resource_group_name,
                   name,
                   sku=SkuName.standard_microsoft.value,
                   disabled=None,
                   mode=PolicyMode.detection.value,
                   redirect_url=None,
                   block_response_body=None,
                   block_response_status_code=None,
                   tags=None):
    from azure.mgmt.cdn.models import (PolicySettings, ErrorResponseException,
                                       Sku)
    policy = CdnWebApplicationFirewallPolicy(
        tags=tags,
        sku=Sku(name=sku),
        location='Global',
        policy_settings=PolicySettings(
            enabled_state=PolicyEnabledState.disabled.value
            if disabled else PolicyEnabledState.enabled.value,
            mode=mode,
            default_redirect_url=redirect_url,
            default_custom_block_response_status_code=
            block_response_status_code,
            default_custom_block_response_body=block_response_body))

    # Copy config set by sub-commands for updating an existing policy.
    try:
        existing = client.get(resource_group_name, name)
        # Update, let's copy over config set by sub-commands
        policy.custom_rules = existing.custom_rules
        policy.rate_limit_rules = existing.rate_limit_rules
        policy.managed_rules = existing.managed_rules
    except ErrorResponseException as e:
        # If the error isn't a 404, rethrow it.
        props = getattr(e.inner_exception, 'additional_properties')
        if not isinstance(props, dict) or not isinstance(
                props.get('error'), dict):
            raise e
        props = props['error']
        if props.get('code') != 'ResourceNotFound':
            raise e
        # 404 error means it's a new policy, nothing to copy.

    return client.create_or_update(resource_group_name, name, policy)
Ejemplo n.º 7
0
def set_waf_policy(client,
                   resource_group_name,
                   name,
                   sku=SkuName.standard_microsoft.value,
                   disabled=None,
                   mode=PolicyMode.detection.value,
                   redirect_url=None,
                   block_response_body=None,
                   block_response_status_code=None,
                   tags=None):
    from azure.core.exceptions import ResourceNotFoundError
    from azure.mgmt.cdn.models import (PolicySettings, Sku)
    policy = CdnWebApplicationFirewallPolicy(
        tags=tags,
        sku=Sku(name=sku),
        location='Global',
        policy_settings=PolicySettings(
            enabled_state=PolicyEnabledState.disabled.value
            if disabled else PolicyEnabledState.enabled.value,
            mode=mode,
            default_redirect_url=redirect_url,
            default_custom_block_response_status_code=
            block_response_status_code,
            default_custom_block_response_body=block_response_body))

    # Copy config set by sub-commands for updating an existing policy.
    try:
        existing = client.get(resource_group_name, name)
        # Update, let's copy over config set by sub-commands
        policy.custom_rules = existing.custom_rules
        policy.rate_limit_rules = existing.rate_limit_rules
        policy.managed_rules = existing.managed_rules
    except ResourceNotFoundError:
        pass
        # 404 error means it's a new policy, nothing to copy.

    return client.begin_create_or_update(resource_group_name, name, policy)