def CreateScratchDisk(self, disk_spec): """Create a VM's scratch disk. Args: disk_spec: virtual_machine.BaseDiskSpec object of the disk. Raises: CreationError: If an SMB disk is listed but the SMB service not created. """ disks = [] for _ in xrange(disk_spec.num_striped_disks): if disk_spec.disk_type == disk.SMB: data_disk = self._GetSmbService().CreateSmbDisk() disks.append(data_disk) continue if disk_spec.disk_type == disk.LOCAL: # Local disk numbers start at 1 (0 is the system disk). disk_number = self.local_disk_counter + 1 self.local_disk_counter += 1 if self.local_disk_counter > self.max_local_disks: raise errors.Error('Not enough local disks.') else: # Remote disk numbers start at 1 + max_local disks (0 is the system disk # and local disks occupy [1, max_local_disks]). disk_number = self.remote_disk_counter + 1 + self.max_local_disks self.remote_disk_counter += 1 lun = next(self._lun_counter) data_disk = azure_disk.AzureDisk(disk_spec, self.name, self.machine_type, self.storage_account, lun) data_disk.disk_number = disk_number disks.append(data_disk) self._CreateScratchDiskFromDisks(disk_spec, disks)
def CreateScratchDisk(self, disk_spec): """Create a VM's scratch disk. Args: disk_spec: virtual_machine.BaseDiskSpec object of the disk. """ disks = [] for disk_idx in xrange(disk_spec.num_striped_disks): data_disk = azure_disk.AzureDisk(disk_spec, self.name, self.machine_type, self.storage_account, disk_idx) if disk_spec.disk_type == disk.LOCAL: # Local disk numbers start at 1 (0 is the system disk). data_disk.disk_number = self.local_disk_counter + 1 self.local_disk_counter += 1 if self.local_disk_counter > self.max_local_disks: raise errors.Error('Not enough local disks.') else: # Remote disk numbers start at 1 + max_local disks (0 is the system disk # and local disks occupy [1, max_local_disks]). data_disk.disk_number = (self.remote_disk_counter + 1 + self.max_local_disks) self.remote_disk_counter += 1 disks.append(data_disk) self._CreateScratchDiskFromDisks(disk_spec, disks)
def __init__(self, vm_spec): """Initialize an Azure virtual machine. Args: vm_spec: virtual_machine.BaseVmSpec object of the vm. """ super(AzureVirtualMachine, self).__init__(vm_spec) self.network = azure_network.AzureNetwork.GetNetwork(self) self.firewall = azure_network.AzureFirewall.GetFirewall() self.max_local_disks = NUM_LOCAL_VOLUMES.get(self.machine_type) or 1 self._lun_counter = itertools.count() self._deleted = False self.resource_group = azure_network.GetResourceGroup() self.public_ip = AzurePublicIPAddress(self.zone, self.name + '-public-ip') self.nic = AzureNIC(self.network.subnet, self.name + '-nic', self.public_ip.name, vm_spec.accelerated_networking) self.storage_account = self.network.storage_account self.image = vm_spec.image or self.IMAGE_URN disk_spec = disk.BaseDiskSpec('azure_os_disk') self.os_disk = azure_disk.AzureDisk(disk_spec, self.name, self.machine_type, self.storage_account, None, is_image=True)
def __init__(self, vm_spec): """Initialize an Azure virtual machine. Args: vm_spec: virtual_machine.BaseVirtualMachineSpec object of the vm. """ super(AzureVirtualMachine, self).__init__(vm_spec) self.network = azure_network.AzureNetwork.GetNetwork(self) self.firewall = azure_network.AzureFirewall.GetFirewall() self.max_local_disks = 1 self.resource_group = azure_network.GetResourceGroup() self.public_ip = AzurePublicIPAddress(self.zone, self.name + '-public-ip') self.nic = AzureNIC(self.network.subnet, self.name + '-nic') self.storage_account = self.network.storage_account self.image = vm_spec.image or self.IMAGE_URN disk_spec = disk.BaseDiskSpec('azure_os_disk') self.os_disk = azure_disk.AzureDisk(disk_spec, self.name, self.machine_type, self.storage_account, None, is_image=True)
def __init__(self, vm_spec): """Initialize an Azure virtual machine. Args: vm_spec: virtual_machine.BaseVmSpec object of the vm. """ super(AzureVirtualMachine, self).__init__(vm_spec) # PKB zone can be either a region or a region with an availability zone. # Format for Azure availability zone support is "region-availability_zone" # Example: eastus2-1 is Azure region eastus2 with availability zone 1. self.region = util.GetRegionFromZone(self.zone) self.availability_zone = util.GetAvailabilityZoneFromZone(self.zone) self.use_dedicated_host = vm_spec.use_dedicated_host self.num_vms_per_host = vm_spec.num_vms_per_host self.network = azure_network.AzureNetwork.GetNetwork(self) self.firewall = azure_network.AzureFirewall.GetFirewall() self.max_local_disks = NUM_LOCAL_VOLUMES.get(self.machine_type) or 1 self._lun_counter = itertools.count() self._deleted = False self.resource_group = azure_network.GetResourceGroup() self.public_ip = AzurePublicIPAddress(self.region, self.availability_zone, self.name + '-public-ip') self.nic = AzureNIC(self.network.subnet, self.name + '-nic', self.public_ip.name, vm_spec.accelerated_networking, self.network.nsg) self.storage_account = self.network.storage_account if vm_spec.image: self.image = vm_spec.image elif self.machine_type in _MACHINE_TYPES_ONLY_SUPPORT_GEN2_IMAGES: if hasattr(type(self), 'GEN2_IMAGE_URN'): self.image = type(self).GEN2_IMAGE_URN else: raise errors.Benchmarks.UnsupportedConfigError( 'No Azure gen2 image.') else: self.image = type(self).IMAGE_URN self.host = None if self.use_dedicated_host: self.host_series_sku = _GetSkuType(self.machine_type) self.host_list = None self.low_priority = vm_spec.low_priority self.low_priority_status_code = None self.spot_early_termination = False self.ultra_ssd_enabled = False disk_spec = disk.BaseDiskSpec('azure_os_disk') disk_spec.disk_type = (vm_spec.boot_disk_type or self.storage_account.storage_type) if vm_spec.boot_disk_size: disk_spec.disk_size = vm_spec.boot_disk_size self.os_disk = azure_disk.AzureDisk(disk_spec, self, None, is_image=True)
def setUp(self): super(AzureDiskGetDevicePathTest, self).setUp() # Patch the __init__ method for simplicity. with mock.patch.object(azure_disk.AzureDisk, '__init__', lambda self: None): self.disk = azure_disk.AzureDisk() self.disk.disk_type = 'NOT_LOCAL' self.disk.machine_type = 'fake'
def __init__(self, vm_spec): """Initialize an Azure virtual machine. Args: vm_spec: virtual_machine.BaseVmSpec object of the vm. """ super(AzureVirtualMachine, self).__init__(vm_spec) # PKB zone can be either a location or a location with an availability zone. # Format for Azure availability zone support is "location-availability_zone" # Example: eastus2-1 is Azure location eastus2 with availability zone 1. self.location = util.GetLocationFromZone(self.zone) self.availability_zone = util.GetAvailabilityZoneFromZone(self.zone) self.use_dedicated_host = vm_spec.use_dedicated_host # TODO(buggay): implement num_vms_per_host functionality self.num_vms_per_host = vm_spec.num_vms_per_host if self.num_vms_per_host: raise NotImplementedError( 'Num vms per host for Azure is not supported.') self.network = azure_network.AzureNetwork.GetNetwork(self) self.firewall = azure_network.AzureFirewall.GetFirewall() self.max_local_disks = NUM_LOCAL_VOLUMES.get(self.machine_type) or 1 self._lun_counter = itertools.count() self._deleted = False self.resource_group = azure_network.GetResourceGroup() self.public_ip = AzurePublicIPAddress(self.location, self.availability_zone, self.name + '-public-ip') self.nic = AzureNIC(self.network.subnet, self.name + '-nic', self.public_ip.name, vm_spec.accelerated_networking) self.storage_account = self.network.storage_account self.image = vm_spec.image or self.IMAGE_URN self.host = None if self.use_dedicated_host: self.host_series_sku = _GetSkuType(self.machine_type) self.host_list = None disk_spec = disk.BaseDiskSpec('azure_os_disk') disk_spec.disk_type = (vm_spec.boot_disk_type or self.storage_account.storage_type) if vm_spec.boot_disk_size: disk_spec.disk_size = vm_spec.boot_disk_size self.os_disk = azure_disk.AzureDisk(disk_spec, self.name, self.machine_type, self.storage_account, None, is_image=True)
def __init__(self, vm_spec): """Initialize a Azure virtual machine. Args: vm_spec: virtual_machine.BaseVirtualMachineSpec object of the vm. """ super(AzureVirtualMachine, self).__init__(vm_spec) self.network = azure_network.AzureNetwork.GetNetwork(self) self.firewall = azure_network.AzureFirewall.GetFirewall() self.service = AzureService(self.name, self.network.affinity_group.name) disk_spec = disk.BaseDiskSpec('azure_os_disk') self.os_disk = azure_disk.AzureDisk(disk_spec, self.name, self.machine_type) self.max_local_disks = 1