Ejemplo n.º 1
0
    def _create_container_group(self, resource_group_name,
                                name,
                                location,
                                image,
                                memory,
                                cpu,
                                algorithm,
                                asset,
                                input_mount_point,
                                output_moint_point,
                                account_name,
                                account_key,
                                share_name_input,
                                share_name_output):
        # setup default values
        result_file = 'result-' + str(int(time.time()))
        command = ['python', input_mount_point + '/' + algorithm, input_mount_point + '/' + asset,
                   output_moint_point + '/' + result_file]
        environment_variables = None
        az_file_input = AzureFileVolume(share_name=share_name_input,
                                        storage_account_name=account_name,
                                        storage_account_key=account_key,
                                        )

        az_file_output = AzureFileVolume(share_name=share_name_output,
                                         storage_account_name=account_name,
                                         storage_account_key=account_key,
                                         )

        volume = [Volume(name=share_name_input, azure_file=az_file_input),
                  Volume(name=share_name_output, azure_file=az_file_output)]
        volume_mount = [VolumeMount(name=share_name_input, mount_path=input_mount_point),
                        VolumeMount(name=share_name_output, mount_path=output_moint_point)]

        # set memory and cpu
        container_resource_requests = ResourceRequests(memory_in_gb=memory, cpu=cpu)
        container_resource_requirements = ResourceRequirements(requests=container_resource_requests)

        container = Container(name=name,
                              image=image,
                              resources=container_resource_requirements,
                              command=command,
                              environment_variables=environment_variables,
                              volume_mounts=volume_mount,
                              )

        # defaults for container group
        cgroup_os_type = OperatingSystemTypes.linux

        cgroup = ContainerGroup(location=location,
                                containers=[container],
                                os_type=cgroup_os_type,
                                restart_policy=ContainerGroupRestartPolicy.never,
                                volumes=volume,
                                )

        self.client.container_groups.create_or_update(resource_group_name, name, cgroup)
        return result_file
Ejemplo n.º 2
0
def create_container_group(az_conf, client, resource_group_name, name, location, image, memory, cpu):
    # Start new containers
    # setup default values
    port = 80
    container_resource_requirements = None
    command = None
    environment_variables = None
    volume_mount = [VolumeMount(name='config', mount_path='/mnt/conf'),VolumeMount(name='data', mount_path='/mnt/data')]
    # data_volume_mount = [VolumeMount(name='data', mount_path='/mnt/data')]

    # set memory and cpu
    container_resource_requests = ResourceRequests(memory_in_gb = memory, cpu = cpu)
    container_resource_requirements = ResourceRequirements(requests = container_resource_requests)

    az_config_file_volume = AzureFileVolume(share_name='config',
                            storage_account_name=az_conf['storage_account_name'],
                            storage_account_key=az_conf['storage_account_key'])
    az_data_file_volume = AzureFileVolume(share_name='data',
                            storage_account_name=az_conf['storage_account_name'],
                            storage_account_key=az_conf['storage_account_key'])


    #volume_mount = VolumeMount(name='config', mount_path='/mnt/config')
    volumes = [Volume(name='config', azure_file=az_config_file_volume),Volume(name='data', azure_file=az_data_file_volume)]
    container = Container(name = name,
                         image = image,
                         resources = container_resource_requirements,
                         command = command,
                         ports = [ContainerPort(port=port)],
                         environment_variables = environment_variables,
                         volume_mounts = volume_mount)
    # defaults for container group
    cgroup_os_type = OperatingSystemTypes.linux
    cgroup_restart_policy = ContainerGroupRestartPolicy.never

    image_registry_credential = ImageRegistryCredential(server=az_conf['container_registry'],
                                                        username=az_conf['container_registry_user'],
                                                        password=az_conf['container_registry_pwd'])

    cgroup = ContainerGroup(location = location,
                           containers = [container],
                           os_type = cgroup_os_type,
                           image_registry_credentials = [image_registry_credential],
                           restart_policy = cgroup_restart_policy,
                           volumes = volumes)

    toto = client.container_groups.create_or_update(resource_group_name, name, cgroup)
    #print(toto.containers)
    """
Ejemplo n.º 3
0
def _create_azure_file_volume(azure_file_volume_share_name,
                              azure_file_volume_account_name,
                              azure_file_volume_account_key):
    """Create Azure File volume. """
    azure_file_volume = None
    if azure_file_volume_share_name:
        if not azure_file_volume_account_name:
            raise CLIError(
                'Please specify --azure-file-volume-account-name in order to use Azure File volume.'
            )
        if not azure_file_volume_account_key:
            try:
                azure_file_volume_account_key = prompt_pass(
                    msg='Azure File storage account key: ')
            except NoTTYException:
                raise CLIError(
                    'Please specify --azure-file-volume-account-key in order to use Azure File volume.'
                )

        azure_file_volume = AzureFileVolume(
            share_name=azure_file_volume_share_name,
            storage_account_name=azure_file_volume_account_name,
            storage_account_key=azure_file_volume_account_key)

    return Volume(name=AZURE_FILE_VOLUME_NAME,
                  azure_file=azure_file_volume) if azure_file_volume else None
Ejemplo n.º 4
0
 def get_file_volume(self, mount_name, share_name,
                     storage_account_name, read_only=False):
     return Volume(name=mount_name,
                   azure_file=AzureFileVolume(share_name=share_name,
                                              storage_account_name=storage_account_name,
                                              read_only=read_only,
                                              storage_account_key=self.get_storagekey()))
Ejemplo n.º 5
0
Archivo: app.py Proyecto: yolocs/prompt
def create_container(name, image, pr_number, user_id, resource_group, port=None, location='westus'):
    from azure.mgmt.containerinstance.models import (ContainerGroup, Container, ContainerPort, Port, IpAddress,
                                                     ImageRegistryCredential, ResourceRequirements, ResourceRequests,
                                                     ContainerGroupNetworkProtocol, OperatingSystemTypes, EnvironmentVariable,
                                                     Volume, AzureFileVolume, VolumeMount)
    from random import randint
    import secrets
    pr_number = str(pr_number)
    if port is None:
        port = randint(1000, 65000)
    instance_token = secrets.token_urlsafe(256)
    environment_variables = [EnvironmentVariable('PR_NUM', pr_number),
                             EnvironmentVariable('PORT', port),
                             EnvironmentVariable('INSTANCE_TOKEN', instance_token)]
    tags = {'userId': user_id, 'prNumber': pr_number}
    container_resource_requests = ResourceRequests(memory_in_gb='1.5', cpu='1')
    container_resource_requirements = ResourceRequirements(requests=container_resource_requests)
    container = Container(name=name,
                          image=image,
                          resources=container_resource_requirements,
                          ports=[ContainerPort(port=port)],
                          environment_variables=environment_variables,
                          volume_mounts=[VolumeMount('volume1', '/cert', read_only=True)])
    cgroup_ip_address = IpAddress(ports=[Port(protocol=ContainerGroupNetworkProtocol.tcp, port=port)])
    cgroup_os_type = OperatingSystemTypes.linux
    afv = AzureFileVolume(SHARE_NAME, SHARE_STORAGE_ACCOUNT_NAME, read_only=True, storage_account_key=SHARE_STORAGE_ACCOUNT_KEY)
    cgroup = ContainerGroup(location=location,
                            containers=[container],
                            os_type=cgroup_os_type,
                            ip_address=cgroup_ip_address,
                            tags=tags,
                            volumes=[Volume('volume1', afv)])
    return get_aci_client().container_groups.create_or_update(resource_group, name, cgroup)
Ejemplo n.º 6
0
def _create_container_group(client, resource_group_name, name, location, image,
                            memory, cpu, volumes):
    # Start new containers
    # setup default values
    port = 80
    container_resource_requirements = None
    command = None
    environment_variables = None

    if volumes:
        az_volume_mount = []
        az_volumes = []
        for volume in volumes:
            az_volume_mount = az_volume_mount + [
                VolumeMount(name=str(volume['name']),
                            mount_path=volume['mount_path'])
            ]
            az_file = AzureFileVolume(
                share_name=str(volume['name']),
                storage_account_name=Variable.get("STORAGE_ACCOUNT_NAME"),
                storage_account_key=Variable.get("STORAGE_ACCOUNT_KEY_PASSWD"))

            az_volumes = az_volumes + [
                Volume(name=str(volume['name']), azure_file=az_file)
            ]

    # set memory and cpu
    container_resource_requests = ResourceRequests(memory_in_gb=memory,
                                                   cpu=cpu)
    container_resource_requirements = ResourceRequirements(
        requests=container_resource_requests)
    container = Container(name=name,
                          image=image,
                          resources=container_resource_requirements,
                          command=command,
                          ports=[ContainerPort(port=port)],
                          environment_variables=environment_variables,
                          volume_mounts=az_volume_mount)

    # defaults for container group
    cgroup_os_type = OperatingSystemTypes.linux
    cgroup_restart_policy = ContainerGroupRestartPolicy.never
    image_registry_credential = ImageRegistryCredential(
        server=Variable.get("CONTAINER_REGISTRY"),
        username=Variable.get("CONTAINER_REGISTRY_USER"),
        password=Variable.get("CONTAINER_REGISTRY_PASSWD"))

    cgroup = ContainerGroup(
        location=location,
        containers=[container],
        os_type=cgroup_os_type,
        image_registry_credentials=[image_registry_credential],
        restart_policy=cgroup_restart_policy,
        volumes=az_volumes)

    results = client.container_groups.create_or_update(resource_group_name,
                                                       name, cgroup)
    return (results)
Ejemplo n.º 7
0
 def get_file_volume(
     self, mount_name: str, share_name: str, storage_account_name: str, read_only: bool = False
 ) -> Volume:
     """Get Azure File Volume"""
     return Volume(
         name=mount_name,
         azure_file=AzureFileVolume(
             share_name=share_name,
             storage_account_name=storage_account_name,
             read_only=read_only,
             storage_account_key=self.get_storagekey(),
         ),
     )
Ejemplo n.º 8
0
 def prepare_azure_volumes(self, afs_volumes: list = []):
     volumes = []
     volume_mounts = []
     for afs in afs_volumes:
         assert afs['afs_name'] is not None
         assert afs['afs_key'] is not None
         assert afs['afs_share'] is not None
         assert afs['mount_path'] is not None
         assert afs['name'] is not None
         az_volume = AzureFileVolume(share_name=afs['afs_share'],
                                     storage_account_name=afs['afs_name'],
                                     storage_account_key=afs['afs_key'])
         volumes.append(Volume(name=afs['name'], azure_file=az_volume))
         volume_mounts.append(
             VolumeMount(name=afs['name'], mount_path=afs['mount_path']))
     return volumes, volume_mounts