def CreateVirtualMachine(self, zone): """Create a vm in zone. Args: zone: The zone in which the vm will be created. If zone is None, the VM class's DEFAULT_ZONE will be used instead. Returns: A vm object. """ vm = static_virtual_machine.StaticVirtualMachine.GetStaticVirtualMachine() if vm: return vm vm_classes = CLASSES[self.cloud][VIRTUAL_MACHINE] if FLAGS.os_type not in vm_classes: raise errors.Error( 'VMs of type %s" are not currently supported on cloud "%s".' % (FLAGS.os_type, self.cloud)) vm_class = vm_classes[FLAGS.os_type] vm_spec = virtual_machine.BaseVirtualMachineSpec( self.project, zone, self.machine_type, self.image) vm_class.SetVmSpecDefaults(vm_spec) return vm_class(vm_spec)
def CreateVirtualMachineFromNodeSection(self, node_section, node_name): """Create a VirtualMachine object from NodeSection. Args: node_section: A dictionary of (option name, option value) pairs. node_name: The name of node. """ zone = node_section['zone'] if 'zone' in node_section else self.zones[0] if zone not in self.zones: self.zones.append(zone) if node_section['image'] not in self.image: self.image.append(node_section['image']) if node_section['vm_type'] not in self.machine_type: self.machine_type.append(node_section['vm_type']) if zone not in self.networks: network_class = CLASSES[self.cloud][NETWORK] self.networks[zone] = network_class(zone) vm_spec = virtual_machine.BaseVirtualMachineSpec( self.project, zone, node_section['vm_type'], node_section['image'], self.networks[zone]) vm_class = CLASSES[self.cloud][VIRTUAL_MACHINE] vms = [vm_class(vm_spec) for _ in range(int(node_section['count']))] self.vms.extend(vms) self.vm_dict[node_name].extend(vms) # Create disk spec. for option in node_section: if option.startswith(ini_constants.OPTION_PD_PREFIX): # Create disk spec. disk_size, disk_type, mnt_point = node_section[option].split( ':') disk_size = int(disk_size) disk_spec = disk.BaseDiskSpec(disk_size, disk_type, mnt_point) for vm in vms: vm.disk_specs.append(disk_spec)
def setUp(self): self.p = mock.patch('perfkitbenchmarker.vm_util.IssueRetryableCommand') self.p.start() self.vm = aws_virtual_machine.AwsVirtualMachine( virtual_machine.BaseVirtualMachineSpec(None, 'us-east-1a', 'c3.large', None, None)) self.vm.id = 'i-foo' path = os.path.join(os.path.dirname(__file__), 'data', 'aws-describe-instance.json') with open(path) as f: self.response = f.read()
def testPreemptibleVMFlag(self): with mock.patch(vm_util.__name__ + '.IssueCommand') as issue_command, \ mock.patch('__builtin__.open'), \ mock.patch(vm_util.__name__ + '.NamedTemporaryFile'), \ mock.patch(gce_virtual_machine.__name__ + '.FLAGS') as gvm_flags: gvm_flags.gce_preemptible_vms = True gvm_flags.gcloud_scopes = None vm_spec = virtual_machine.BaseVirtualMachineSpec( 'proj', 'zone', 'n1-standard-1', 'image') vm = gce_virtual_machine.GceVirtualMachine(vm_spec) vm._Create() self.assertEquals(issue_command.call_count, 1) self.assertIn('--preemptible', issue_command.call_args[0][0])
def setUp(self): for module in ('perfkitbenchmarker.virtual_machine', 'perfkitbenchmarker.vm_util', 'perfkitbenchmarker.aws.aws_network'): p = mock.patch('{0}.FLAGS'.format(module)) mock_flags = p.start() mock_flags.run_uri = 'aaaaaa' self.addCleanup(p.stop) p = mock.patch('perfkitbenchmarker.aws.util.IssueRetryableCommand') p.start() self.addCleanup(p.stop) self.vm = aws_virtual_machine.AwsVirtualMachine( virtual_machine.BaseVirtualMachineSpec(None, 'us-east-1a', 'c3.large', None)) self.vm.id = 'i-foo' path = os.path.join(os.path.dirname(__file__), 'data', 'aws-describe-instance.json') with open(path) as f: self.response = f.read()
def __init__(self, ip_address, user_name, keyfile_path=None, internal_ip=None, zone=None, local_disks=None, scratch_disk_mountpoints=None, ssh_port=22, install_packages=True, password=None): """Initialize a static virtual machine. Args: ip_address: The ip address of the vm. user_name: The username of the vm that the keyfile corresponds to. keyfile_path: The absolute path of the private keyfile for the vm. internal_ip: The internal ip address of the vm. zone: The zone of the VM. local_disks: A list of the paths of local disks on the VM. scratch_disk_mountpoints: A list of scratch disk mountpoints. ssh_port: The port number to use for SSH and SCP commands. install_packages: If false, no packages will be installed. This is useful if benchmark dependencies have already been installed. """ vm_spec = virtual_machine.BaseVirtualMachineSpec( None, None, None, None) super(StaticVirtualMachine, self).__init__(vm_spec, None, None) self.ip_address = ip_address self.internal_ip = internal_ip self.zone = zone or ('Static - %s@%s' % (user_name, ip_address)) self.user_name = user_name self.ssh_port = ssh_port self.ssh_private_key = keyfile_path self.local_disks = local_disks or [] self.scratch_disk_mountpoints = scratch_disk_mountpoints or [] self.install_packages = install_packages self.password = password
def CreateVirtualMachine(self, opt_zone=None): """Create a vm in zone. Args: opt_zone: The zone in which the vm will be created. If not provided, FLAGS.zone or the revelant zone from DEFAULT will be used. Returns: A vm object. """ vm = static_virtual_machine.StaticVirtualMachine.GetStaticVirtualMachine( ) if vm: return vm vm_class = CLASSES[self.cloud][VIRTUAL_MACHINE][FLAGS.os_type] zone = opt_zone or self.zones[0] if zone not in self.networks: network_class = CLASSES[self.cloud][NETWORK] self.networks[zone] = network_class(zone) self.vm_spec = virtual_machine.BaseVirtualMachineSpec( self.project, zone, self.machine_type, self.image, self.networks[zone]) return vm_class(self.vm_spec)
def __init__(self, ip_address, user_name, keyfile_path, internal_ip=None, zone=None, local_disks=None, scratch_disk_mountpoints=None): """Initialize a static virtual machine. Args: ip_address: The ip address of the vm. user_name: The username of the vm that the keyfile corresponds to. keyfile_path: The absolute path of the private keyfile for the vm. internal_ip: The internal ip address of the vm. zone: The zone of the VM. local_disks: A list of the paths of local disks on the VM. scratch_disk_mountpoints: A list of scratch disk mountpoints. """ vm_spec = virtual_machine.BaseVirtualMachineSpec( None, None, None, None, None) super(StaticVirtualMachine, self).__init__(vm_spec) self.ip_address = ip_address self.internal_ip = internal_ip self.zone = zone or ('Static - %s@%s' % (user_name, ip_address)) self.user_name = user_name self.ssh_private_key = keyfile_path self.local_disks = local_disks or [] self.scratch_disk_mountpoints = scratch_disk_mountpoints or []
def CreateVirtualMachine(self, zone): """Create a vm in zone. Args: zone: The zone in which the vm will be created. If zone is None, the VM class's DEFAULT_ZONE will be used instead. Returns: A vm object. """ vm = static_virtual_machine.StaticVirtualMachine.GetStaticVirtualMachine() if vm: return vm vm_classes = CLASSES[self.cloud][VIRTUAL_MACHINE] if FLAGS.os_type not in vm_classes: raise errors.Error( 'VMs of type %s" are not currently supported on cloud "%s".' % (FLAGS.os_type, self.cloud)) vm_class = vm_classes[FLAGS.os_type] vm_spec = virtual_machine.BaseVirtualMachineSpec( self.project, zone, self.machine_type, self.image) vm_class.SetVmSpecDefaults(vm_spec) if NETWORK in CLASSES[self.cloud]: net_class = CLASSES[self.cloud][NETWORK] network = net_class.GetNetwork(vm_spec.zone, self.networks) else: network = None if FIREWALL in CLASSES[self.cloud]: firewall_class = CLASSES[self.cloud][FIREWALL] firewall = firewall_class.GetFirewall(self.firewalls) else: firewall = None return vm_class(vm_spec, network, firewall)
def _CreateVm(self): vm_spec = virtual_machine.BaseVirtualMachineSpec( None, 'zone', None, 'image', None) return aws_virtual_machine.AwsVirtualMachine(vm_spec)
def _CreateVm(self): vm_spec = virtual_machine.BaseVirtualMachineSpec( None, None, None, None, None) return gce_virtual_machine.GceVirtualMachine(vm_spec)
def _CreateVm(self): network = azure_network.AzureNetwork(None) vm_spec = virtual_machine.BaseVirtualMachineSpec( None, None, None, None, network) return azure_virtual_machine.AzureVirtualMachine(vm_spec)
def _CreateVm(self): vm_spec = virtual_machine.BaseVirtualMachineSpec( None, None, None, None) return azure_virtual_machine.DebianBasedAzureVirtualMachine(vm_spec)
def _CreateVm(self): vm_spec = virtual_machine.BaseVirtualMachineSpec( None, None, None, None) net = azure_network.AzureNetwork('zone') return azure_virtual_machine.DebianBasedAzureVirtualMachine( vm_spec, net, None)