def _Create(self):
        """See base class."""
        if self.os_disk.disk_size:
            disk_size_args = ['--os-disk-size-gb', str(self.os_disk.disk_size)]
        else:
            disk_size_args = []

        tags = {}
        tags.update(self.vm_metadata)
        tags.update(util.GetResourceTags(self.resource_group.timeout_minutes))
        tag_args = ['--tags'] + util.FormatTags(tags)

        create_cmd = ([
            azure.AZURE_PATH, 'vm', 'create', '--location', self.location,
            '--image', self.image, '--size', self.machine_type,
            '--admin-username', self.user_name, '--storage-sku',
            self.os_disk.disk_type, '--name', self.name
        ] + disk_size_args + self.resource_group.args + self.nic.args +
                      tag_args)

        if self.availability_zone:
            create_cmd.extend(['--zone', self.availability_zone])

        # Resources in Availability Set are not allowed to be
        # deployed to particular hosts.
        if self.use_dedicated_host:
            create_cmd.extend([
                '--host-group', self.host.host_group, '--host', self.host.name
            ])

        if self.network.avail_set:
            create_cmd.extend(
                ['--availability-set', self.network.avail_set.name])

        if self.password:
            create_cmd.extend(['--admin-password', self.password])
        else:
            create_cmd.extend(['--ssh-key-value', self.ssh_public_key])

        # Uses a custom default because create for larger sizes sometimes times out.
        azure_vm_create_timeout = 600
        _, stderr, retcode = vm_util.IssueCommand(
            create_cmd,
            timeout=azure_vm_create_timeout,
            raise_on_failure=False)
        if retcode and 'Error Code: QuotaExceeded' in stderr:
            raise errors.Benchmarks.QuotaFailure(
                virtual_machine.QUOTA_EXCEEDED_MESSAGE + stderr)
        # TODO(buggay): raise host insufficient capacity error
        # if capacity is reached with user set num_vms value, fail benchmark
        if retcode and 'AllocationFailed' in stderr:
            raise errors.Benchmarks.InsufficientCapacityCloudFailure(stderr)
        if retcode:
            raise errors.Resource.CreationError(
                'Failed to create VM: %s return code: %s' % (stderr, retcode))
    def _Create(self):
        """See base class."""
        if self.os_disk.disk_size:
            disk_size_args = ['--os-disk-size-gb', str(self.os_disk.disk_size)]
        else:
            disk_size_args = []

        tags = {}
        tags.update(self.vm_metadata)
        tags.update(util.GetResourceTags(self.resource_group.timeout_minutes))
        tag_args = ['--tags'] + util.FormatTags(tags)

        create_cmd = ([
            azure.AZURE_PATH, 'vm', 'create', '--location', self.location,
            '--image', self.image, '--size', self.machine_type,
            '--admin-username', self.user_name, '--storage-sku',
            self.os_disk.disk_type, '--name', self.name
        ] + disk_size_args + self.resource_group.args + self.nic.args +
                      tag_args)

        if self.availability_zone:
            create_cmd.extend(['--zone', self.availability_zone])

        # Resources in Availability Set are not allowed to be
        # deployed to particular hosts.
        if self.use_dedicated_host:
            create_cmd.extend([
                '--host-group', self.host.host_group, '--host', self.host.name
            ])
            num_hosts = len(self.host_list)

        if self.network.placement_group:
            create_cmd.extend(self.network.placement_group.AddVmArgs())

        if self.low_priority:
            create_cmd.extend(['--priority', 'Spot'])

        if self.password:
            create_cmd.extend(['--admin-password', self.password])
        else:
            create_cmd.extend(['--ssh-key-value', self.ssh_public_key])

        # Uses a custom default because create has a very long tail.
        azure_vm_create_timeout = 1200
        _, stderr, retcode = vm_util.IssueCommand(
            create_cmd,
            timeout=azure_vm_create_timeout,
            raise_on_failure=False)
        if retcode and ('Error Code: QuotaExceeded' in stderr or re.search(
                r'exceeding approved \S+ \S+ quota', stderr)
                        or 'exceeding quota limit' in stderr):
            raise errors.Benchmarks.QuotaFailure(
                virtual_machine.QUOTA_EXCEEDED_MESSAGE + stderr)
        # TODO(buggay) refactor to share code with gcp_virtual_machine.py
        if (self.use_dedicated_host and retcode
                and 'AllocationFailed' in stderr):
            if self.num_vms_per_host:
                raise errors.Resource.CreationError(
                    'Failed to create host: %d vms of type %s per host exceeds '
                    'memory capacity limits of the host' %
                    (self.num_vms_per_host, self.machine_type))
            else:
                logging.warning(
                    'Creation failed due to insufficient host capacity. A new host will '
                    'be created and instance creation will be retried.')
                with self._lock:
                    if num_hosts == len(self.host_list):
                        new_host = AzureDedicatedHost(self.name, self.location,
                                                      self.resource_group,
                                                      self.host_series_sku,
                                                      self.availability_zone)
                        self.host_list.append(new_host)
                        new_host.Create()
                    self.host = self.host_list[-1]
                raise errors.Resource.RetryableCreationError()
        if (not self.use_dedicated_host and retcode
                and ('AllocationFailed' in stderr
                     or 'OverconstrainedZonalAllocationRequest' in stderr)):
            raise errors.Benchmarks.InsufficientCapacityCloudFailure(stderr)
        if retcode:
            raise errors.Resource.CreationError(
                'Failed to create VM: %s return code: %s' % (stderr, retcode))
    def _Create(self):
        """See base class."""
        if self.os_disk.disk_size:
            disk_size_args = ['--os-disk-size-gb', str(self.os_disk.disk_size)]
        else:
            disk_size_args = []

        tags = {}
        tags.update(self.vm_metadata)
        tags.update(util.GetResourceTags(self.resource_group.timeout_minutes))
        tag_args = ['--tags'] + util.FormatTags(tags)

        create_cmd = ([
            azure.AZURE_PATH, 'vm', 'create', '--location', self.region,
            '--image', self.image, '--size', self.machine_type,
            '--admin-username', self.user_name, '--storage-sku',
            self.os_disk.disk_type, '--name', self.name
        ] + disk_size_args + self.resource_group.args + self.nic.args +
                      tag_args)

        if self._RequiresUltraDisk():
            self.ultra_ssd_enabled = True
            create_cmd.extend(['--ultra-ssd-enabled'])

        if self.availability_zone:
            create_cmd.extend(['--zone', self.availability_zone])

        # Resources in Availability Set are not allowed to be
        # deployed to particular hosts.
        if self.use_dedicated_host:
            create_cmd.extend([
                '--host-group', self.host.host_group, '--host', self.host.name
            ])
            num_hosts = len(self.host_list)

        if self.network.placement_group:
            create_cmd.extend(self.network.placement_group.AddVmArgs())

        if self.low_priority:
            create_cmd.extend(['--priority', 'Spot'])

        if self.password:
            create_cmd.extend(['--admin-password', self.password])
        else:
            create_cmd.extend(['--ssh-key-value', self.ssh_public_key])

        # Uses a custom default because create has a very long tail.
        azure_vm_create_timeout = 1800
        _, stderr, retcode = vm_util.IssueCommand(
            create_cmd,
            timeout=azure_vm_create_timeout,
            raise_on_failure=False)
        if retcode:
            if 'quota' in stderr.lower():
                raise errors.Benchmarks.QuotaFailure(
                    virtual_machine.QUOTA_EXCEEDED_MESSAGE + stderr)
            elif re.search(
                    r'requested VM size \S+ is not available',
                    stderr) or re.search(
                        r'not available in location .+ for subscription',
                        stderr):
                raise errors.Benchmarks.UnsupportedConfigError(stderr)
            elif self.low_priority and 'OverconstrainedAllocationRequest' in stderr:
                raise errors.Benchmarks.InsufficientCapacityCloudFailure(
                    stderr)
        # TODO(buggay) refactor to share code with gcp_virtual_machine.py
        if (self.use_dedicated_host and retcode
                and 'AllocationFailed' in stderr):
            if self.num_vms_per_host:
                raise errors.Resource.CreationError(
                    'Failed to create host: %d vms of type %s per host exceeds '
                    'memory capacity limits of the host' %
                    (self.num_vms_per_host, self.machine_type))
            else:
                logging.warning(
                    'Creation failed due to insufficient host capacity. A new host will '
                    'be created and instance creation will be retried.')
                with self._lock:
                    if num_hosts == len(self.host_list):
                        new_host = AzureDedicatedHost(self.name, self.region,
                                                      self.resource_group,
                                                      self.host_series_sku,
                                                      self.availability_zone)
                        self.host_list.append(new_host)
                        new_host.Create()
                    self.host = self.host_list[-1]
                raise errors.Resource.RetryableCreationError()
        if (not self.use_dedicated_host and retcode
                and ('AllocationFailed' in stderr
                     or 'OverconstrainedZonalAllocationRequest' in stderr)):
            raise errors.Benchmarks.InsufficientCapacityCloudFailure(stderr)
        if retcode:
            if "Virtual Machine Scale Set with '<NULL>' security type." in stderr:
                raise errors.Resource.CreationError(
                    f'Failed to create VM: {self.machine_type} is likely a confidential'
                    ' machine, which PKB does not support at this time.\n\n'
                    f' Full error: {stderr} return code: {retcode}')
            if "cannot boot Hypervisor Generation '1'" in stderr:
                raise errors.Resource.CreationError(
                    f'Failed to create VM: {self.machine_type} is unable to support V1 '
                    'Hypervision. Please update _MACHINE_TYPES_ONLY_SUPPORT_GEN2_IMAGES'
                    ' in azure_virtual_machine.py.\n\n'
                    f' Full error: {stderr} return code: {retcode}')
            else:
                raise errors.Resource.CreationError(
                    'Failed to create VM: %s return code: %s' %
                    (stderr, retcode))