コード例 #1
0
def cli_redis_create(cmd,
                     client,
                     resource_group_name,
                     name,
                     location,
                     sku,
                     vm_size,
                     tags=None,
                     redis_configuration=None,
                     enable_non_ssl_port=None,
                     tenant_settings=None,
                     shard_count=None,
                     subnet_id=None,
                     static_ip=None):
    # pylint:disable=line-too-long
    """Create new Redis Cache instance
    :param resource_group_name: Name of resource group
    :param name: Name of redis cache
    :param location: Location
    :param sku: What type of redis cache to deploy. Valid values: (Basic, Standard, Premium).
    :param vm_size: What size of redis cache to deploy. Valid values for C family (C0, C1, C2, C3, C4, C5, C6), for P family (P1, P2, P3, P4)
    :param redis_configuration: All Redis Settings. Few possible keys rdb-backup-enabled, rdb-storage-connection-string, rdb-backup-frequency, maxmemory-delta, maxmemory-policy, notify-keyspace-events, maxmemory-samples, slowlog-log-slower-than, slowlog-max-len, list-max-ziplist-entries, list-max-ziplist-value, hash-max-ziplist-entries, hash-max-ziplist-value, set-max-intset-entries, zset-max-ziplist-entries, zset-max-ziplist-value etc.
    :param enable_non_ssl_port: If the value is true, then the non-ssl redis server port (6379) will be enabled.
    :param tenant_settings: Json dictionary with tenant settings
    :param shard_count: The number of shards to be created on a Premium Cluster Cache.
    :param subnet_id: The full resource ID of a subnet in a virtual network to deploy the redis cache in. Example format /subscriptions/{subid}/resourceGroups/{resourceGroupName}/Microsoft.{Network|ClassicNetwork}/VirtualNetworks/vnet1/subnets/subnet1
    :param static_ip: Required when deploying a redis cache inside an existing Azure Virtual Network.
    """
    from azure.mgmt.redis.models import RedisCreateParameters, Sku
    params = RedisCreateParameters(location, Sku(sku, vm_size[0], vm_size[1:]),
                                   tags, redis_configuration,
                                   enable_non_ssl_port, tenant_settings,
                                   shard_count, subnet_id, static_ip)
    return client.create(resource_group_name, name, params)
コード例 #2
0
def cli_redis_create(cmd, client,
                     resource_group_name, name, location, sku, vm_size, tags=None,
                     redis_configuration=None, enable_non_ssl_port=None, tenant_settings=None,
                     shard_count=None, minimum_tls_version=None, subnet_id=None, static_ip=None,
                     zones=None, replicas_per_master=None, redis_version=None, mi_system_assigned=None,
                     mi_user_assigned=None):
    # pylint:disable=line-too-long
    if ((sku.lower() in ['standard', 'basic'] and vm_size.lower() not in allowed_c_family_sizes) or (sku.lower() in ['premium'] and vm_size.lower() not in allowed_p_family_sizes)):
        raise wrong_vmsize_error
    tenant_settings_in_json = {}
    if tenant_settings is not None:
        for item in tenant_settings:
            tenant_settings_in_json.update(get_key_value_pair(item))
    from azure.mgmt.redis.models import RedisCreateParameters, Sku, RedisCommonPropertiesRedisConfiguration
    identity = build_identity(mi_system_assigned, mi_user_assigned)
    if identity.type == "None":
        identity = None
    # pylint: disable=too-many-function-args
    params = RedisCreateParameters(
        sku=Sku(name=sku, family=vm_size[0], capacity=vm_size[1:]),
        location=location,
        redis_configuration=RedisCommonPropertiesRedisConfiguration(additional_properties=redis_configuration),
        enable_non_ssl_port=enable_non_ssl_port,
        replicas_per_master=replicas_per_master,
        tenant_settings=tenant_settings_in_json,
        shard_count=shard_count,
        minimum_tls_version=minimum_tls_version,
        subnet_id=subnet_id,
        static_ip=static_ip,
        zones=zones,
        redis_version=redis_version,
        identity=identity,
        public_network_access=None,
        tags=tags)
    return client.begin_create(resource_group_name, name, params)
コード例 #3
0
def newRedisCache(clientId, password, tenant, subscriptionId):
    
    logging.warning(msg='Please confirm you have the azure Python SDK installed. If you do not, run pip install azure')

    try:
        credentials = ServicePrincipalCredentials(
            client_id=clientId,
            secret=password,
            tenant=tenant
        )

        redis_connect = azure.mgmt.redis.RedisManagementClient(credentials, subscriptionId)
        rg_name = input('Please enter resource group name: ')
        cache = input('Please enter the name for your new Redis cache: ')


        createRedis = redis_connect.redis.create(
            rg_name,
            cache,
            RedisCreateParameters(sku = Sku(name = input('Please enter Sky type. For example: Basic: '),
                                            family = input('Please enter family. For example: C: '),
                                            capacity = int(input('Please enter capacity. For example: 1: '))),
                                            location = input('Please enter location. For example: eastus: '))
                                            )
        print('Creating Redis Cache')
    
    except azure.common.exceptions.AuthenticationError:
        logging.error('ERROR: There was an authentication issue. Please confirm your client id, secret, tenant, subscription, and try again')

    except CloudError as clo:
        logging.error(clo)
    
    except Exception as e:
        logging.error(e)
コード例 #4
0
def run(job, **kwargs):
    resource = kwargs.get('resource')
    create_custom_fields_as_needed()

    env_id = '{{ env_id }}'
    env = Environment.objects.get(id=env_id)
    rh = env.resource_handler.cast()
    location = env.node_location
    set_progress('Location: %s' % location)

    resource_group_name = '{{ resource_group }}'
    redis_cache_name = '{{ redis_cache_name }}'
    sku = '{{ sku }}'
    capacity = '{{ capacity }}'

    resource.name = 'Azure redis cache - ' + redis_cache_name
    resource.azure_redis_cache_name = redis_cache_name
    resource.resource_group_name = resource_group_name
    resource.azure_location = location
    resource.azure_rh_id = rh.id
    resource.save()

    set_progress("Connecting To Azure...")
    credentials = ServicePrincipalCredentials(
        client_id=rh.client_id,
        secret=rh.secret,
        tenant=rh.tenant_id,
    )
    redis_client = RedisManagementClient(credentials, rh.serviceaccount)
    set_progress("Connection to Azure established")

    set_progress('Creating redis cache "%s"...' % redis_cache_name)
    if sku in ['Basic', 'Standard']:
        family = 'C'
    elif sku == 'Premium':
        family = 'P'

    try:
        async_cache_create = redis_client.redis.create(
            resource_group_name, redis_cache_name,
            RedisCreateParameters(sku=Sku(name=sku,
                                          family=family,
                                          capacity=capacity),
                                  location=location))
    except CloudError as e:
        set_progress('Azure Clouderror: {}'.format(e))
        return "FAILURE", "%s Redis cache name provided is not valid or is not available for use" % redis_cache_name

    cache = async_cache_create.result()

    assert cache.name == redis_cache_name

    got_cache = redis_client.redis.get(resource_group_name, redis_cache_name)
    assert got_cache.name == redis_cache_name

    set_progress('Redis cache "%s" has been created.' % redis_cache_name)
コード例 #5
0
    def create_rediscache(self):
        '''
        Creates Azure Cache for Redis instance with the specified configuration.

        :return: deserialized Azure Cache for Redis instance state dictionary
        '''
        self.log("Creating Azure Cache for Redis instance {0}".format(
            self.name))

        try:
            redis_config = dict()
            for key in self.redis_configuration_properties:
                if getattr(self, key, None):
                    redis_config[underline_to_hyphen(
                        key)] = underline_to_hyphen(getattr(self, key))

            params = RedisCreateParameters(
                location=self.location,
                sku=Sku(self.sku['name'].title(), self.sku['size'][0],
                        self.sku['size'][1:]),
                tags=self.tags,
                redis_configuration=redis_config,
                enable_non_ssl_port=self.enable_non_ssl_port,
                tenant_settings=self.tenant_settings,
                shard_count=self.shard_count,
                subnet_id=self.subnet,
                static_ip=self.static_ip)

            response = self._client.redis.create(
                resource_group_name=self.resource_group,
                name=self.name,
                parameters=params)
            if isinstance(response, AzureOperationPoller) or isinstance(
                    response, LROPoller):
                response = self.get_poller_result(response)

            if self.wait_for_provisioning:
                self.wait_for_redis_running()

        except CloudError as exc:
            self.log(
                'Error attempting to create the Azure Cache for Redis instance.'
            )
            self.fail("Error creating the Azure Cache for Redis instance: {0}".
                      format(str(exc)))
        return rediscache_to_dict(response)
コード例 #6
0
ファイル: custom.py プロジェクト: Avik-devops/Azure-CLI
def cli_redis_create(cmd,
                     client,
                     resource_group_name,
                     name,
                     location,
                     sku,
                     vm_size,
                     tags=None,
                     redis_configuration=None,
                     enable_non_ssl_port=None,
                     tenant_settings=None,
                     shard_count=None,
                     minimum_tls_version=None,
                     subnet_id=None,
                     static_ip=None,
                     zones=None):
    # pylint:disable=line-too-long
    if ((sku.lower() in ['standard', 'basic']
         and vm_size.lower() not in allowed_c_family_sizes)
            or (sku.lower() in ['premium']
                and vm_size.lower() not in allowed_p_family_sizes)):
        raise wrong_vmsize_error
    tenant_settings_in_json = {}
    if tenant_settings is not None:
        for item in tenant_settings:
            tenant_settings_in_json.update(get_key_value_pair(item))
    from azure.mgmt.redis.models import RedisCreateParameters, Sku
    # pylint: disable=too-many-function-args
    params = RedisCreateParameters(sku=Sku(name=sku,
                                           family=vm_size[0],
                                           capacity=vm_size[1:]),
                                   location=location,
                                   redis_configuration=redis_configuration,
                                   enable_non_ssl_port=enable_non_ssl_port,
                                   tenant_settings=tenant_settings_in_json,
                                   shard_count=shard_count,
                                   minimum_tls_version=minimum_tls_version,
                                   subnet_id=subnet_id,
                                   static_ip=static_ip,
                                   zones=zones,
                                   tags=tags)
    return client.create(resource_group_name, name, params)