def get_vm_size_completion_list(cmd, prefix, namespace, **kwargs): # pylint: disable=unused-argument try: location = namespace.location except AttributeError: location = get_one_of_subscription_locations(cmd.cli_ctx) result = get_vm_sizes(cmd.cli_ctx, location) return [r.name for r in result]
def get_vm_size_completion_list(prefix, action, parsed_args, **kwargs): # pylint: disable=unused-argument try: location = parsed_args.location except AttributeError: location = get_one_of_subscription_locations() result = get_vm_sizes(location) return [r.name for r in result]
def load_images_thru_services(publisher, offer, sku, location): from concurrent.futures import ThreadPoolExecutor, as_completed all_images = [] client = _compute_client_factory() if location is None: location = get_one_of_subscription_locations() def _load_images_from_publisher(publisher): offers = client.virtual_machine_images.list_offers(location, publisher) if offer: offers = [o for o in offers if _partial_matched(offer, o.name)] for o in offers: skus = client.virtual_machine_images.list_skus(location, publisher, o.name) if sku: skus = [s for s in skus if _partial_matched(sku, s.name)] for s in skus: images = client.virtual_machine_images.list(location, publisher, o.name, s.name) for i in images: all_images.append({"publisher": publisher, "offer": o.name, "sku": s.name, "version": i.name}) publishers = client.virtual_machine_images.list_publishers(location) if publisher: publishers = [p for p in publishers if _partial_matched(publisher, p.name)] publisher_num = len(publishers) if publisher_num > 1: with ThreadPoolExecutor(max_workers=40) as executor: tasks = [executor.submit(_load_images_from_publisher, p.name) for p in publishers] for t in as_completed(tasks): t.result() # don't use the result but expose exceptions from the threads elif publisher_num == 1: _load_images_from_publisher(publishers[0].name) return all_images
def get_vm_size_completion_list(prefix, action, parsed_args, **kwargs): # pylint: disable=unused-argument try: location = parsed_args.location except AttributeError: location = get_one_of_subscription_locations() result = get_vm_sizes(location) return [r.name for r in result]
def load_images_thru_services(cli_ctx, publisher, offer, sku, location): from concurrent.futures import ThreadPoolExecutor, as_completed all_images = [] client = _compute_client_factory(cli_ctx) if location is None: location = get_one_of_subscription_locations(cli_ctx) def _load_images_from_publisher(publisher): from msrestazure.azure_exceptions import CloudError try: offers = client.virtual_machine_images.list_offers( location, publisher) except CloudError as e: logger.warning(str(e)) return if offer: offers = [o for o in offers if _matched(offer, o.name)] for o in offers: try: skus = client.virtual_machine_images.list_skus( location, publisher, o.name) except CloudError as e: logger.warning(str(e)) continue if sku: skus = [s for s in skus if _matched(sku, s.name)] for s in skus: try: images = client.virtual_machine_images.list( location, publisher, o.name, s.name) except CloudError as e: logger.warning(str(e)) continue for i in images: all_images.append({ 'publisher': publisher, 'offer': o.name, 'sku': s.name, 'version': i.name }) publishers = client.virtual_machine_images.list_publishers(location) if publisher: publishers = [p for p in publishers if _matched(publisher, p.name)] publisher_num = len(publishers) if publisher_num > 1: with ThreadPoolExecutor(max_workers=_get_thread_count()) as executor: tasks = [ executor.submit(_load_images_from_publisher, p.name) for p in publishers ] for t in as_completed(tasks): t.result( ) # don't use the result but expose exceptions from the threads elif publisher_num == 1: _load_images_from_publisher(publishers[0].name) return all_images
def get_vm_run_command_completion_list(prefix, action, parsed_args, **kwargs): # pylint: disable=unused-argument from ._client_factory import _compute_client_factory try: location = parsed_args.location except AttributeError: location = get_one_of_subscription_locations() result = _compute_client_factory().virtual_machine_run_commands.list(location) return [r.id for r in result]
def get_vm_run_command_completion_list(prefix, action, parsed_args, **kwargs): # pylint: disable=unused-argument from ._client_factory import _compute_client_factory try: location = parsed_args.location except AttributeError: location = get_one_of_subscription_locations() result = _compute_client_factory().virtual_machine_run_commands.list(location) return [r.id for r in result]
def get_vm_size_completion_list(cmd, prefix, namespace, **kwargs): # pylint: disable=unused-argument """Return the intersection of the VM sizes allowed by the ACS SDK with those returned by the Compute Service.""" try: location = namespace.location except AttributeError: # TODO: try the resource group's default location before falling back to this location = get_one_of_subscription_locations(cmd.cli_ctx) result = get_vm_sizes(cmd.cli_ctx, location) return sorted(set(r.name for r in result) & set(c.value for c in ContainerServiceVMSizeTypes))
def get_vm_run_command_completion_list(cmd, prefix, namespace): # pylint: disable=unused-argument from ._client_factory import _compute_client_factory try: location = namespace.location except AttributeError: location = get_one_of_subscription_locations(cmd.cli_ctx) result = _compute_client_factory( cmd.cli_ctx).virtual_machine_run_commands.list(location) return [r.id for r in result]
def load_extension_images_thru_services(cli_ctx, publisher, name, version, location, show_latest=False, partial_match=True): from concurrent.futures import ThreadPoolExecutor, as_completed from distutils.version import LooseVersion # pylint: disable=no-name-in-module,import-error all_images = [] client = _compute_client_factory(cli_ctx) if location is None: location = get_one_of_subscription_locations(cli_ctx) def _load_extension_images_from_publisher(publisher): from msrestazure.azure_exceptions import CloudError try: types = client.virtual_machine_extension_images.list_types(location, publisher) except CloudError: # PIR image publishers might not have any extension images, exception could raise types = [] if name: types = [t for t in types if _matched(name, t.name, partial_match)] for t in types: versions = client.virtual_machine_extension_images.list_versions(location, publisher, t.name) if version: versions = [v for v in versions if _matched(version, v.name, partial_match)] if show_latest: # pylint: disable=no-member versions.sort(key=lambda v: LooseVersion(v.name), reverse=True) try: all_images.append({ 'publisher': publisher, 'name': t.name, 'version': versions[0].name}) except IndexError: pass # if no versions for this type continue to next type. else: for v in versions: all_images.append({ 'publisher': publisher, 'name': t.name, 'version': v.name}) publishers = client.virtual_machine_images.list_publishers(location) if publisher: publishers = [p for p in publishers if _matched(publisher, p.name, partial_match)] publisher_num = len(publishers) if publisher_num > 1: with ThreadPoolExecutor(max_workers=_get_thread_count()) as executor: tasks = [executor.submit(_load_extension_images_from_publisher, p.name) for p in publishers] for t in as_completed(tasks): t.result() # don't use the result but expose exceptions from the threads elif publisher_num == 1: _load_extension_images_from_publisher(publishers[0].name) return all_images
def load_extension_images_thru_services(cli_ctx, publisher, name, version, location, show_latest=False, partial_match=True): from concurrent.futures import ThreadPoolExecutor, as_completed from distutils.version import LooseVersion # pylint: disable=no-name-in-module,import-error all_images = [] client = _compute_client_factory(cli_ctx) if location is None: location = get_one_of_subscription_locations(cli_ctx) def _load_extension_images_from_publisher(publisher): from msrestazure.azure_exceptions import CloudError try: types = client.virtual_machine_extension_images.list_types(location, publisher) except CloudError: # PIR image publishers might not have any extension images, exception could raise types = [] if name: types = [t for t in types if _matched(name, t.name, partial_match)] for t in types: versions = client.virtual_machine_extension_images.list_versions(location, publisher, t.name) if version: versions = [v for v in versions if _matched(version, v.name, partial_match)] if show_latest: # pylint: disable=no-member versions.sort(key=lambda v: LooseVersion(v.name), reverse=True) all_images.append({ 'publisher': publisher, 'name': t.name, 'version': versions[0].name}) else: for v in versions: all_images.append({ 'publisher': publisher, 'name': t.name, 'version': v.name}) publishers = client.virtual_machine_images.list_publishers(location) if publisher: publishers = [p for p in publishers if _matched(publisher, p.name, partial_match)] publisher_num = len(publishers) if publisher_num > 1: with ThreadPoolExecutor(max_workers=_get_thread_count()) as executor: tasks = [executor.submit(_load_extension_images_from_publisher, p.name) for p in publishers] for t in as_completed(tasks): t.result() # don't use the result but expose exceptions from the threads elif publisher_num == 1: _load_extension_images_from_publisher(publishers[0].name) return all_images
def _get_location(cli_ctx, namespace): """ Return an Azure location by using an explicit `--location` argument, then by `--resource-group`, and finally by the subscription if neither argument was provided. """ location = None if getattr(namespace, 'location', None): location = namespace.location elif getattr(namespace, 'resource_group_name', None): location = _get_location_from_resource_group(cli_ctx, namespace.resource_group_name) if not location: location = get_one_of_subscription_locations(cli_ctx) return location
def _get_location(cli_ctx, namespace): """ Return an Azure location by using an explicit `--location` argument, then by `--resource-group`, and finally by the subscription if neither argument was provided. """ location = None if getattr(namespace, 'location', None): location = namespace.location elif getattr(namespace, 'resource_group_name', None): location = _get_location_from_resource_group(cli_ctx, namespace.resource_group_name) if not location: location = get_one_of_subscription_locations(cli_ctx) return location
def load_extension_images_thru_services(publisher, name, version, location, show_latest=False): from concurrent.futures import ThreadPoolExecutor, as_completed ##pylint: disable=no-name-in-module,import-error from distutils.version import LooseVersion all_images = [] client = _compute_client_factory() if location is None: location = get_one_of_subscription_locations() def _load_extension_images_from_publisher(publisher): types = client.virtual_machine_extension_images.list_types(location, publisher) if name: types = [t for t in types if _partial_matched(name, t.name)] for t in types: versions = client.virtual_machine_extension_images.list_versions(location, publisher, t.name) if version: versions = [v for v in versions if _partial_matched(version, v.name)] if show_latest: # pylint: disable=no-member versions.sort(key=lambda v: LooseVersion(v.name), reverse=True) all_images.append({"publisher": publisher, "name": t.name, "version": versions[0].name}) else: for v in versions: all_images.append({"publisher": publisher, "name": t.name, "version": v.name}) publishers = client.virtual_machine_images.list_publishers(location) if publisher: publishers = [p for p in publishers if _partial_matched(publisher, p.name)] publisher_num = len(publishers) if publisher_num > 1: with ThreadPoolExecutor(max_workers=40) as executor: tasks = [executor.submit(_load_extension_images_from_publisher, p.name) for p in publishers] for t in as_completed(tasks): t.result() # don't use the result but expose exceptions from the threads elif publisher_num == 1: _load_extension_images_from_publisher(publishers[0].name) return all_images
def _get_location(cli_ctx, namespace): """ Return an Azure location by using an explicit `--location` argument, then by `--resource-group`, and finally by the subscription if neither argument was provided. """ from azure.core.exceptions import HttpResponseError from azure.cli.core.commands.parameters import get_one_of_subscription_locations location = None if getattr(namespace, 'location', None): location = namespace.location elif getattr(namespace, 'resource_group_name', None): try: location = _get_location_from_resource_group(cli_ctx, namespace.resource_group_name) except HttpResponseError as err: from argcomplete import warn warn('Warning: {}'.format(err.message)) if not location: location = get_one_of_subscription_locations(cli_ctx) return location
def get_vm_size_completion_list(cmd, prefix, namespace): # pylint: disable=unused-argument location = namespace.location if not location: location = get_one_of_subscription_locations(cmd.cli_ctx) result = get_vm_sizes(cmd.cli_ctx, location) return [r.name for r in result]
def load_extension_images_thru_services(publisher, name, version, location, show_latest=False): from concurrent.futures import ThreadPoolExecutor, as_completed # pylint: disable=no-name-in-module,import-error from distutils.version import LooseVersion all_images = [] client = _compute_client_factory() if location is None: location = get_one_of_subscription_locations() def _load_extension_images_from_publisher(publisher): types = client.virtual_machine_extension_images.list_types( location, publisher) if name: types = [t for t in types if _partial_matched(name, t.name)] for t in types: versions = client.virtual_machine_extension_images.list_versions( location, publisher, t.name) if version: versions = [ v for v in versions if _partial_matched(version, v.name) ] if show_latest: # pylint: disable=no-member versions.sort(key=lambda v: LooseVersion(v.name), reverse=True) all_images.append({ 'publisher': publisher, 'name': t.name, 'version': versions[0].name }) else: for v in versions: all_images.append({ 'publisher': publisher, 'name': t.name, 'version': v.name }) publishers = client.virtual_machine_images.list_publishers(location) if publisher: publishers = [ p for p in publishers if _partial_matched(publisher, p.name) ] publisher_num = len(publishers) if publisher_num > 1: with ThreadPoolExecutor(max_workers=40) as executor: tasks = [ executor.submit(_load_extension_images_from_publisher, p.name) for p in publishers ] for t in as_completed(tasks): t.result( ) # don't use the result but expose exceptions from the threads elif publisher_num == 1: _load_extension_images_from_publisher(publishers[0].name) return all_images
def load_images_thru_services(cli_ctx, publisher, offer, sku, location, edge_zone): from concurrent.futures import ThreadPoolExecutor, as_completed all_images = [] client = _compute_client_factory(cli_ctx) if location is None: location = get_one_of_subscription_locations(cli_ctx) def _load_images_from_publisher(publisher): from azure.core.exceptions import ResourceNotFoundError try: if edge_zone is not None: offers = edge_zone_client.list_offers(location, edge_zone, publisher) else: offers = client.virtual_machine_images.list_offers( location, publisher) except ResourceNotFoundError as e: logger.warning(str(e)) return if offer: offers = [o for o in offers if _matched(offer, o.name)] for o in offers: try: if edge_zone is not None: skus = edge_zone_client.list_skus(location, edge_zone, publisher, o.name) else: skus = client.virtual_machine_images.list_skus( location, publisher, o.name) except ResourceNotFoundError as e: logger.warning(str(e)) continue if sku: skus = [s for s in skus if _matched(sku, s.name)] for s in skus: try: if edge_zone is not None: images = edge_zone_client.list(location, edge_zone, publisher, o.name, s.name) else: images = client.virtual_machine_images.list( location, publisher, o.name, s.name) except ResourceNotFoundError as e: logger.warning(str(e)) continue for i in images: image_info = { 'publisher': publisher, 'offer': o.name, 'sku': s.name, 'version': i.name } if edge_zone is not None: image_info['edge_zone'] = edge_zone all_images.append(image_info) if edge_zone is not None: from azure.cli.core.commands.client_factory import get_mgmt_service_client from azure.cli.core.profiles import ResourceType edge_zone_client = get_mgmt_service_client( cli_ctx, ResourceType.MGMT_COMPUTE).virtual_machine_images_edge_zone publishers = edge_zone_client.list_publishers(location, edge_zone) else: publishers = client.virtual_machine_images.list_publishers(location) if publisher: publishers = [p for p in publishers if _matched(publisher, p.name)] publisher_num = len(publishers) if publisher_num > 1: with ThreadPoolExecutor(max_workers=_get_thread_count()) as executor: tasks = [ executor.submit(_load_images_from_publisher, p.name) for p in publishers ] for t in as_completed(tasks): t.result( ) # don't use the result but expose exceptions from the threads elif publisher_num == 1: _load_images_from_publisher(publishers[0].name) return all_images