def cli_redis_identity_remove(client, resource_group_name, cache_name, mi_system_assigned=None, mi_user_assigned=None): from azure.mgmt.redis.models import RedisUpdateParameters, ManagedServiceIdentityType, ManagedServiceIdentity redis_resourse = client.get(resource_group_name, cache_name) identity = redis_resourse.identity system_assigned = None none_identity = ManagedServiceIdentity( type=ManagedServiceIdentityType.NONE.value) if identity is None: return none_identity if (identity.type == ManagedServiceIdentityType.SYSTEM_ASSIGNED_USER_ASSIGNED.value or identity.type == ManagedServiceIdentityType.SYSTEM_ASSIGNED.value): system_assigned = True if mi_system_assigned is not None: system_assigned = None user_assigned = None if identity.user_assigned_identities is not None: user_assigned = list(identity.user_assigned_identities) if mi_user_assigned is not None and user_assigned is not None: for mi_user_id in mi_user_assigned: try: user_assigned.remove(mi_user_id) except ValueError: pass if len(user_assigned) == 0: user_assigned = None update_params = RedisUpdateParameters( identity=build_identity(system_assigned, user_assigned) ) updated_resourse = client.update(resource_group_name, cache_name, update_params) if updated_resourse.identity is None: updated_resourse.identity = none_identity return updated_resourse.identity
def update_rediscache(self): ''' Updates Azure Cache for Redis instance with the specified configuration. :return: Azure Cache for Redis instance state dictionary ''' self.log( "Updating 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 = RedisUpdateParameters( redis_configuration=redis_config, enable_non_ssl_port=self.enable_non_ssl_port, tenant_settings=self.tenant_settings, shard_count=self.shard_count, sku=Sku(self.sku['name'].title(), self.sku['size'][0], self.sku['size'][1:]), tags=self.tags ) response = self._client.redis.update(resource_group_name=self.resource_group, name=self.name, parameters=params) if isinstance(response, LROPoller) or isinstance(response, AzureOperationPoller): response = self.get_poller_result(response) except CloudError as exc: self.log('Error attempting to update the Azure Cache for Redis instance.') self.fail( "Error updating the Azure Cache for Redis instance: {0}".format(str(exc))) return rediscache_to_dict(response)
def cli_redis_update(cmd, instance, sku=None, vm_size=None): from azure.mgmt.redis.models import RedisUpdateParameters if sku is not None: instance.sku.name = sku if vm_size is not None: instance.sku.family = vm_size[0] instance.sku.capacity = vm_size[1:] # avoid setting memory configs for basic sku if instance.sku.name == 'Basic': if 'maxmemory-reserved' in instance.redis_configuration: instance.redis_configuration.pop('maxmemory-reserved') if 'maxfragmentationmemory-reserved' in instance.redis_configuration: instance.redis_configuration.pop('maxfragmentationmemory-reserved') if 'maxmemory-delta' in instance.redis_configuration: instance.redis_configuration.pop('maxmemory-delta') # Trim zonal-configuration if 'zonal-configuration' in instance.redis_configuration: instance.redis_configuration.pop('zonal-configuration') # pylint: disable=too-many-function-args update_params = RedisUpdateParameters( redis_configuration=instance.redis_configuration, enable_non_ssl_port=instance.enable_non_ssl_port, tenant_settings=instance.tenant_settings, shard_count=instance.shard_count, minimum_tls_version=instance.minimum_tls_version, sku=instance.sku, tags=instance.tags) return update_params
def cli_redis_update(cmd, instance, sku=None, vm_size=None): from azure.mgmt.redis.models import RedisUpdateParameters if sku is not None: instance.sku.name = sku if vm_size is not None: instance.sku.family = vm_size[0] instance.sku.capacity = vm_size[1:] update_params = RedisUpdateParameters( instance.redis_configuration, instance.enable_non_ssl_port, instance.tenant_settings, instance.shard_count, instance.subnet_id, instance.static_ip, instance.sku, instance.tags) return update_params
def cli_redis_update_settings(cmd, client, resource_group_name, name, redis_configuration): from azure.mgmt.redis.models import RedisUpdateParameters existing = client.get(resource_group_name, name) existing.redis_configuration.update(redis_configuration) # Due to swagger/mgmt SDK quirkiness, we have to manually copy over # the resource retrieved to a create_parameters object update_params = RedisUpdateParameters( existing.redis_configuration, existing.enable_non_ssl_port, existing.tenant_settings, existing.shard_count, existing.subnet_id, existing.static_ip, existing.sku, existing.tags) return client.update(resource_group_name, name, parameters=update_params)
def cli_redis_identity_assign(client, resource_group_name, cache_name, mi_system_assigned=None, mi_user_assigned=None): from azure.mgmt.redis.models import RedisUpdateParameters, ManagedServiceIdentityType redis_resourse = client.get(resource_group_name, cache_name) identity = redis_resourse.identity if identity is not None: if ManagedServiceIdentityType.SYSTEM_ASSIGNED.value in identity.type: mi_system_assigned = True if ManagedServiceIdentityType.USER_ASSIGNED.value in identity.type: old_user_identity = list(identity.user_assigned_identities) if mi_user_assigned is None: mi_user_assigned = [] for user_id in old_user_identity: mi_user_assigned.append(user_id) update_params = RedisUpdateParameters( identity=build_identity(mi_system_assigned, mi_user_assigned)) redis_resourse = client.update(resource_group_name, cache_name, update_params) return redis_resourse.identity
def cli_redis_update(cmd, instance, sku=None, vm_size=None): from azure.mgmt.redis.models import RedisUpdateParameters if sku is not None: instance.sku.name = sku if vm_size is not None: instance.sku.family = vm_size[0] instance.sku.capacity = vm_size[1:] # avoid setting memory configs for basic sku if instance.sku.name == 'Basic': memory_configs = ['maxmemory-reserved', 'maxfragmentationmemory-reserved', 'maxmemory-delta'] instance.redis_configuration.maxmemory_reserved = None instance.redis_configuration.maxfragmentationmemory_reserved = None instance.redis_configuration.maxmemory_delta = None properties = instance.redis_configuration.additional_properties for memory_config in memory_configs: if properties is not None and memory_config in properties: instance.redis_configuration.additional_properties.pop(memory_config, None) # trim RDB and AOF connection strings and zonal-configuration removable_keys = [ 'rdb-storage-connection-string', 'aof-storage-connection-string-0', 'aof-storage-connection-string-1', 'zonal-configuration'] instance.redis_configuration.rdb_storage_connection_string = None instance.redis_configuration.aof_storage_connection_string0 = None instance.redis_configuration.aof_storage_connection_string1 = None properties = instance.redis_configuration.additional_properties for key in removable_keys: if properties is not None and key in properties: instance.redis_configuration.additional_properties.pop(key, None) # pylint: disable=too-many-function-args update_params = RedisUpdateParameters( redis_configuration=instance.redis_configuration, enable_non_ssl_port=instance.enable_non_ssl_port, tenant_settings=instance.tenant_settings, shard_count=instance.shard_count, minimum_tls_version=instance.minimum_tls_version, redis_version=instance.redis_version, sku=instance.sku, tags=instance.tags ) return update_params
def cli_redis_update(cmd, instance, sku=None, vm_size=None): from azure.mgmt.redis.models import RedisUpdateParameters if sku is not None: instance.sku.name = sku if vm_size is not None: instance.sku.family = vm_size[0] instance.sku.capacity = vm_size[1:] # pylint: disable=too-many-function-args update_params = RedisUpdateParameters( redis_configuration=instance.redis_configuration, enable_non_ssl_port=instance.enable_non_ssl_port, tenant_settings=instance.tenant_settings, shard_count=instance.shard_count, minimum_tls_version=instance.minimum_tls_version, sku=instance.sku, tags=instance.tags) return update_params
def cli_redis_update(cmd, instance, sku=None, vm_size=None): from azure.mgmt.redis.models import RedisUpdateParameters if sku is not None: instance.sku.name = sku if vm_size is not None: instance.sku.family = vm_size[0] instance.sku.capacity = vm_size[1:] # avoid setting memory configs for basic sku if instance.sku.name == 'Basic': memory_configs = [ 'maxmemory-reserved', 'maxfragmentationmemory-reserved', 'maxmemory-delta' ] for memory_config in memory_configs: if memory_config in instance.redis_configuration: instance.redis_configuration.pop(memory_config) # trim RDB and AOF connection strings rdb_aof_connection_strings = [ 'rdb-storage-connection-string', 'aof-storage-connection-string-0', 'aof-storage-connection-string-1' ] for connection_string in rdb_aof_connection_strings: if connection_string in instance.redis_configuration: instance.redis_configuration.pop(connection_string) # Trim zonal-configuration if 'zonal-configuration' in instance.redis_configuration: instance.redis_configuration.pop('zonal-configuration') # pylint: disable=too-many-function-args update_params = RedisUpdateParameters( redis_configuration=instance.redis_configuration, enable_non_ssl_port=instance.enable_non_ssl_port, tenant_settings=instance.tenant_settings, shard_count=instance.shard_count, minimum_tls_version=instance.minimum_tls_version, sku=instance.sku, tags=instance.tags) return update_params