def _use_gallery_image(cli_ctx, namespace): """ Retrieve gallery image from lab and update namespace """ from azure.mgmt.devtestlabs.models import GalleryImageReference gallery_image_operation = get_devtestlabs_management_client( cli_ctx, None).gallery_images odata_filter = ODATA_NAME_FILTER.format(namespace.image) gallery_images = list( gallery_image_operation.list(namespace.resource_group_name, namespace.lab_name, filter=odata_filter)) if not gallery_images: err = "Unable to find image name '{}' in the '{}' lab Gallery.".format( namespace.image, namespace.lab_name) raise CLIError(err) if len(gallery_images) > 1: err = "Found more than 1 image with name '{}'. Please pick one from {}" raise CLIError( err.format(namespace.image, [x.name for x in gallery_images])) namespace.gallery_image_reference = \ GalleryImageReference(offer=gallery_images[0].image_reference.offer, publisher=gallery_images[0].image_reference.publisher, os_type=gallery_images[0].image_reference.os_type, sku=gallery_images[0].image_reference.sku, version=gallery_images[0].image_reference.version) namespace.os_type = gallery_images[0].image_reference.os_type
def _validate_image_argument(cli_ctx, namespace, formula=None): """ Update namespace for image based on image or formula """ from azure.mgmt.devtestlabs.models import GalleryImageReference if formula and formula.formula_content: if formula.formula_content.gallery_image_reference: gallery_image_reference = formula.formula_content.gallery_image_reference namespace.gallery_image_reference = \ GalleryImageReference(offer=gallery_image_reference.offer, publisher=gallery_image_reference.publisher, os_type=gallery_image_reference.os_type, sku=gallery_image_reference.sku, version=gallery_image_reference.version) namespace.os_type = gallery_image_reference.os_type return if formula.formula_content.custom_image_id: # Custom image id from the formula is in the form of "customimages/{name}" namespace.image = formula.formula_content.custom_image_id.split( '/')[-1] namespace.image_type = 'custom' if namespace.image_type == 'gallery': _use_gallery_image(cli_ctx, namespace) elif namespace.image_type == 'custom': _use_custom_image(cli_ctx, namespace) else: raise CLIError( "incorrect value for image-type: '{}'. Allowed values: gallery or custom" .format(namespace.image_type))
def get_image(self, image_id): url_params = azure_helpers.parse_url(IMAGE_RESOURCE_ID, image_id) if self.is_gallery_image(image_id): return GalleryImageReference(publisher=url_params['publisher'], offer=url_params['offer'], sku=url_params['sku'], version=url_params['version']) else: name = url_params.get(IMAGE_NAME, "") return self.compute_client.images.get(self.resource_group, name)
NETWORK_NAME = 'virtualNetworkName' NETWORK_INTERFACE_NAME = 'networkInterfaceName' PUBLIC_IP_NAME = 'publicIpAddressName' ROUTER_NAME = 'routerName' SNAPSHOT_NAME = 'snapshotName' SUBNET_NAME = 'subnetName' VM_NAME = 'vmName' VM_FIREWALL_NAME = 'networkSecurityGroupName' VM_FIREWALL_RULE_NAME = 'securityRuleName' VOLUME_NAME = 'diskName' # Listing possible somewhat through: # azure.mgmt.devtestlabs.operations.GalleryImageOperations gallery_image_references = \ [GalleryImageReference(publisher='Canonical', offer='UbuntuServer', sku='16.04.0-LTS', version='latest'), GalleryImageReference(publisher='Canonical', offer='UbuntuServer', sku='14.04.5-LTS', version='latest'), GalleryImageReference(publisher='OpenLogic', offer='CentOS', sku='7.5', version='latest'), GalleryImageReference(publisher='OpenLogic', offer='CentOS', sku='6.9', version='latest'), GalleryImageReference(publisher='MicrosoftWindowsServer', offer='WindowsServer',