def enable_boot_diagnostics(resource_group_name, vm_name, storage): '''Enable boot diagnostics :param storage:a storage account name or a uri like https://your_stoage_account_name.blob.core.windows.net/ ''' vm = _vm_get(resource_group_name, vm_name) if urlparse(storage).scheme: storage_uri = storage else: storage_mgmt_client = _get_storage_management_client() storage_accounts = storage_mgmt_client.storage_accounts.list() storage_account = next((a for a in list(storage_accounts) if a.name.lower() == storage.lower()), None) if storage_account is None: raise CLIError('{} does\'t exist.'.format(storage)) storage_uri = storage_account.primary_endpoints.blob if (vm.diagnostics_profile and vm.diagnostics_profile.boot_diagnostics and vm.diagnostics_profile.boot_diagnostics.enabled and vm.diagnostics_profile.boot_diagnostics.storage_uri and vm.diagnostics_profile.boot_diagnostics.storage_uri.lower() == storage_uri.lower()): return from azure.mgmt.compute.models import DiagnosticsProfile, BootDiagnostics boot_diag = BootDiagnostics(True, storage_uri) if vm.diagnostics_profile is None: vm.diagnostics_profile = DiagnosticsProfile(boot_diag) else: vm.diagnostics_profile.boot_diagnostics = boot_diag # Issue: https://github.com/Azure/autorest/issues/934 vm.resources = None _vm_set(vm, ExtensionUpdateLongRunningOperation('enabling boot diagnostics', 'done'))
def _create_vm(self, compute_management_client, region, group_name, vm_name, hardware_profile, network_profile, os_profile, storage_profile, cancellation_context, tags, vm_plan=None): """Create and deploy Azure VM from the given parameters :param compute_management_client: azure.mgmt.compute.compute_management_client.ComputeManagementClient :param region: (str) Azure region :param group_name: (str) resource group name (reservation id) :param vm_name: (str) Azure VM resource name :param hardware_profile: azure.mgmt.compute.models.HardwareProfile instance :param network_profile: azure.mgmt.compute.models.NetworkProfile instance :param os_profile: azure.mgmt.compute.models.OSProfile instance :param storage_profile: azure.mgmt.compute.models.StorageProfile instance :param cancellation_context cloudshell.shell.core.driver_context.CancellationContext instance :param tags: azure tags :rtype: azure.mgmt.compute.models.VirtualMachine """ virtual_machine = VirtualMachine( location=region, tags=tags, os_profile=os_profile, hardware_profile=hardware_profile, network_profile=network_profile, storage_profile=storage_profile, diagnostics_profile=DiagnosticsProfile( boot_diagnostics=BootDiagnostics(enabled=False)), plan=vm_plan) operation_poller = compute_management_client.virtual_machines.create_or_update( group_name, vm_name, virtual_machine) return self.task_waiter_service.wait_for_task( operation_poller=operation_poller, cancellation_context=cancellation_context)