Exemple #1
0
def create_mediaservice(client, resource_group_name, account_name, storage_account, location=None, tags=None):
    from azure.mgmt.media.models import StorageAccount
    storage_account_primary = StorageAccount(type='Primary', id=storage_account)

    return create_or_update_mediaservice(client, resource_group_name, account_name, [storage_account_primary],
                                         location,
                                         tags)
Exemple #2
0
def create_mediaservice(client, resource_group_name, account_name, storage_account, location=None,
                        mi_system_assigned=False, mi_user_assigned=None, disable_public_network=False,
                        default_action=None, ip_allow_list=None, tags=None):
    storage_account_primary = StorageAccount(type='Primary', id=storage_account)
    return create_or_update_mediaservice(client, resource_group_name, account_name, [storage_account_primary],
                                         location, mi_system_assigned, mi_user_assigned, disable_public_network,
                                         default_action, ip_allow_list, tags)
Exemple #3
0
def create_mediaservice(client,
                        resource_group_name,
                        account_name,
                        storage_account,
                        location=None,
                        assign_identity=False,
                        tags=None):
    storage_account_primary = StorageAccount(type='Primary',
                                             id=storage_account)

    return create_or_update_mediaservice(client, resource_group_name,
                                         account_name,
                                         [storage_account_primary], location,
                                         assign_identity, tags)
Exemple #4
0
def add_mediaservice_secondary_storage(client, resource_group_name, account_name, storage_account):
    ams = client.get(resource_group_name, account_name)

    storage_accounts_filtered = list(filter(lambda s: storage_account in s.id, ams.storage_accounts))

    storage_account_secondary = StorageAccount(type='Secondary', id=storage_account)

    if not storage_accounts_filtered:
        ams.storage_accounts.append(storage_account_secondary)

    return create_or_update_mediaservice(client, resource_group_name, account_name,
                                         ams.storage_accounts,
                                         ams.location,
                                         ams.tags)
Exemple #5
0
def add_mediaservice_secondary_storage(client, resource_group_name, account_name, storage_account,
                                       system_assigned=False, user_assigned=None):
    ams = client.get(resource_group_name, account_name)
    if (system_assigned is False and user_assigned is None and ams.storage_authentication == 'ManagedIdentity'):
        error_msg = 'Please specify either system assigned identity or a user assigned identity'
        raise ValidationError(error_msg)

    storage_accounts_filtered = list(filter(lambda s: storage_account in s.id, ams.storage_accounts))

    storage_account_secondary = StorageAccount(type='Secondary', id=storage_account)
    if ams.storage_authentication == 'ManagedIdentity':
        storage_account_secondary.identity = ResourceIdentity(use_system_assigned_identity=system_assigned,
                                                              user_assigned_identity=user_assigned)
    if not storage_accounts_filtered:
        ams.storage_accounts.append(storage_account_secondary)

    media_service = MediaService(name=ams.name, location=ams.location, key_delivery=ams.key_delivery,
                                 identity=ams.identity, encryption=ams.encryption,
                                 storage_accounts=ams.storage_accounts,
                                 storage_authentication=ams.storage_authentication,
                                 public_network_access=ams.public_network_access)

    return client.create_or_update(resource_group_name, account_name, media_service)
account_location = 'westus'

#  Check if the existing storage account name exists
if storage_account_name is None:
  raise Exception("No storage account name provided in .env file.")

# Set up the values for you Media Services account
parameters = MediaService(
  location=account_location,
  storage_accounts=[
    StorageAccount(
      # This should point to an already created storage account that is Blob storage General purpose v2. 
      # Recommend to use ZRS or Geo redundant ZRS in regions that support availability zones
      type=StorageAccountType.PRIMARY,
      id=f"/subscriptions/{subscription_id}/resourceGroups/{resource_group}/providers/Microsoft.Storage/storageAccounts/{storage_account_name}",
      # Set the user assigned managed identity resource and set system assigned to false here.
      identity=ResourceIdentity(
        user_assigned_identity=managed_identity_resource,
        use_system_assigned_identity=False
      )
    )
  ],
  # Sets the account encryption used. This can be changed to customer key and point to a key vault key.
  encryption=AccountEncryption(
    type="SystemKey",
    # Optional settings if using key vault encryption key and managed identity
    # identity = ResourceIdentity(
    #   user_assigned_identity = managed_identity_resource,
    #   use_system_assigned_identity = False
    # ),
    # key_vault_properties = KeyVaultProperties(
Exemple #7
0
    storage_async_operation = storage_client.storage_accounts.begin_create(
        resource_group_name, storage_account_name, storage_account_parameters)
    storage_account = storage_async_operation.result()
    print(storage_account)


create_storage(resource_group, storage_account_name, stor_avail_params,
               stor_account_params)

# Set up the values for you Media Services account
parameters = MediaService(
    location=account_location,
    storage_accounts=[
        StorageAccount(
            type=StorageAccountType.PRIMARY,
            id=
            f"/subscriptions/{subscription_id}/resourceGroups/{resource_group}/providers/Microsoft.Storage/storageAccounts/{storage_account_name}"
        )
    ],
    key_delivery=KeyDelivery(access_control=AccessControl(
        default_action=DefaultAction.ALLOW,
        ip_allow_list=[
            # List the IPv3 addresses to Allow or Deny based on the default action.
            # "10.0.0.1/32", you can use the CIDR IPv3 format,
            # "127.0.0.1" or a single individual IPv4 address as well
        ])))

availability = client.locations.check_name_availability(
    account_location,
    parameters=CheckNameAvailabilityInput(
        name=account_name, type="Microsoft.Media/mediaservices"))