示例#1
0
    def select_latest_verified_vm_image_with_node_agent_sku(
            self,
            publisher='microsoft-azure-batch',
            offer='ubuntu-server-container',
            sku_starts_with='16-04'):
        """Select the latest verified image that Azure Batch supports given
        a publisher, offer and sku (starts with filter).
        :param str publisher: vm image publisher
        :param str offer: vm image offer
        :param str sku_starts_with: vm sku starts with filter
        :rtype: tuple
        :return: (node agent sku id to use, vm image ref to use)
        """
        # get verified vm image list and node agent sku ids from service
        from azure.batch import models as batchmodels

        options = batchmodels.AccountListSupportedImagesOptions(
            filter="verificationType eq 'verified'")
        images = self.batch_client.account.list_supported_images(
            account_list_supported_images_options=options)

        # pick the latest supported sku
        skus_to_use = [
            (image.node_agent_sku_id, image.image_reference)
            for image in images
            if image.image_reference.publisher.lower() == publisher.lower()
            and image.image_reference.offer.lower() == offer.lower()
            and image.image_reference.sku.startswith(sku_starts_with)
        ]

        # pick first
        agent_sku_id, image_ref_to_use = skus_to_use[0]
        return agent_sku_id, image_ref_to_use
示例#2
0
文件: batch.py 项目: pingzh/airflow
    def _get_latest_verified_image_vm_and_sku(
        self,
        publisher: Optional[str] = None,
        offer: Optional[str] = None,
        sku_starts_with: Optional[str] = None,
    ) -> tuple:
        """
        Get latest verified image vm and sku

        :param publisher: The publisher of the Azure Virtual Machines Marketplace Image.
            For example, Canonical or MicrosoftWindowsServer.
        :param offer: The offer type of the Azure Virtual Machines Marketplace Image.
            For example, UbuntuServer or WindowsServer.
        :param sku_starts_with: The start name of the sku to search
        """
        options = batch_models.AccountListSupportedImagesOptions(
            filter="verificationType eq 'verified'")
        images = self.connection.account.list_supported_images(
            account_list_supported_images_options=options)
        # pick the latest supported sku
        skus_to_use = [
            (image.node_agent_sku_id, image.image_reference)
            for image in images
            if image.image_reference.publisher.lower() == publisher
            and image.image_reference.offer.lower() == offer
            and image.image_reference.sku.startswith(sku_starts_with)
        ]

        # pick first
        agent_sku_id, image_ref_to_use = skus_to_use[0]
        return agent_sku_id, image_ref_to_use
def select_latest_verified_vm_image_with_node_agent_sku(
        batch_client, publisher, offer, sku_starts_with):
    """Select the latest verified image that Azure Batch supports given
    a publisher, offer and sku (starts with filter).

    :param batch_client: The batch client to use.
    :type batch_client: `batchserviceclient.BatchServiceClient`
    :param str publisher: vm image publisher
    :param str offer: vm image offer
    :param str sku_starts_with: vm sku starts with filter
    :rtype: tuple
    :return: (node agent sku id to use, vm image ref to use)
    """
    # get verified vm image list and node agent sku ids from service
    options = batchmodels.AccountListSupportedImagesOptions(
        filter="verificationType eq 'verified'")
    images = batch_client.account.list_supported_images(
        account_list_supported_images_options=options)

    # pick the latest supported sku
    skus_to_use = [
        (image.node_agent_sku_id, image.image_reference) for image in images
        if image.image_reference.publisher.lower() == publisher.lower()
        and image.image_reference.offer.lower() == offer.lower()
        and image.image_reference.sku.startswith(sku_starts_with)
    ]

    # pick first
    agent_sku_id, image_ref_to_use = skus_to_use[0]
    return (agent_sku_id, image_ref_to_use)