Beispiel #1
0
 def ImportKeyfile(self):
     """Imports the public keyfile to AWS."""
     with self._lock:
         if self.region in self.imported_keyfile_set:
             return
         cat_cmd = ['cat', vm_util.GetPublicKeyPath()]
         keyfile, _ = vm_util.IssueRetryableCommand(cat_cmd)
         import_cmd = util.AWS_PREFIX + [
             'ec2',
             '--region=%s' % self.region, 'import-key-pair',
             '--key-name=%s' % 'perfkit-key-%s' % FLAGS.run_uri,
             '--public-key-material=%s' % keyfile
         ]
         util.IssueRetryableCommand(import_cmd)
         self.imported_keyfile_set.add(self.region)
         if self.region in self.deleted_keyfile_set:
             self.deleted_keyfile_set.remove(self.region)
 def ImportKeyfile(cls, region):
   """Imports the public keyfile to AWS."""
   with cls._lock:
     if _GetKeyfileSetKey(region) in cls.imported_keyfile_set:
       return
     cat_cmd = ['cat',
                vm_util.GetPublicKeyPath()]
     keyfile, _ = vm_util.IssueRetryableCommand(cat_cmd)
     import_cmd = util.AWS_PREFIX + [
         'ec2', '--region=%s' % region,
         'import-key-pair',
         '--key-name=%s' % cls.GetKeyNameForRun(),
         '--public-key-material=%s' % keyfile]
     util.IssueRetryableCommand(import_cmd)
     cls.imported_keyfile_set.add(_GetKeyfileSetKey(region))
     if _GetKeyfileSetKey(region) in cls.deleted_keyfile_set:
       cls.deleted_keyfile_set.remove(_GetKeyfileSetKey(region))
Beispiel #3
0
    def __init__(self, vm_spec):
        """Initialize BaseVirtualMachine class.

    Args:
      vm_spec: virtual_machine.BaseVirtualMachineSpec object of the vm.
    """
        super(BaseVirtualMachine, self).__init__()
        with self._instance_counter_lock:
            self.instance_number = self._instance_counter
            self.name = 'pkb-%s-%d' % (FLAGS.run_uri, self.instance_number)
            BaseVirtualMachine._instance_counter += 1
        self.disable_interrupt_moderation = vm_spec.disable_interrupt_moderation
        self.disable_rss = vm_spec.disable_rss
        self.zone = vm_spec.zone
        self.cidr = vm_spec.cidr
        self.machine_type = vm_spec.machine_type
        self.gpu_count = vm_spec.gpu_count
        self.gpu_type = vm_spec.gpu_type
        self.image = vm_spec.image
        self.install_packages = vm_spec.install_packages
        self.ip_address = None
        self.internal_ip = None
        self.user_name = DEFAULT_USERNAME
        self.password = None
        self.ssh_public_key = vm_util.GetPublicKeyPath()
        self.ssh_private_key = vm_util.GetPrivateKeyPath()
        self.disk_specs = []
        self.scratch_disks = []
        self.max_local_disks = 0
        self.local_disk_counter = 0
        self.remote_disk_counter = 0
        self.background_cpu_threads = vm_spec.background_cpu_threads
        self.background_network_mbits_per_sec = (
            vm_spec.background_network_mbits_per_sec)
        self.background_network_ip_type = vm_spec.background_network_ip_type
        self.use_dedicated_host = None
        self.num_vms_per_host = None

        self.network = None
        self.firewall = None
        self.tcp_congestion_control = None
        self.numa_node_count = None
        self.num_disable_cpus = None
        self.capacity_reservation_id = None
        self.vm_metadata = dict(
            item.split(':', 1) for item in vm_spec.vm_metadata)
  def _Create(self):
    """Creates the AKS cluster."""
    cmd = [
        azure.AZURE_PATH, 'aks', 'create',
        '--name', self.name,
        '--node-vm-size', self.vm_config.machine_type,
        '--node-count', str(self.num_nodes),
        '--location', self.location,
        '--dns-name-prefix', 'pkb' + FLAGS.run_uri,
        '--ssh-key-value', vm_util.GetPublicKeyPath(),
        '--service-principal', self.service_principal.app_id,
        # TODO(pclay): avoid logging client secret
        '--client-secret', self.service_principal.password,
        # TODO(pclay): Consider adding
        # --kubernetes-version=FLAGS.container_cluster_version.
    ] + self.resource_group.args
    if self.vm_config.os_disk and self.vm_config.os_disk.disk_size:
      cmd += ['--node-osdisk-size', str(self.vm_config.os_disk.disk_size)]

    vm_util.IssueCommand(cmd, timeout=1800)
 def _Create(self):
     """Creates the ACS cluster."""
     vm_util.IssueCommand([
         azure.AZURE_PATH,
         'acs',
         'create',
         '--name',
         self.name,
         '--agent-vm-size',
         self.machine_type,
         '--agent-count',
         str(self.num_nodes),
         '--location',
         self.zone,
         '--orchestrator-type',
         'Kubernetes',
         '--dns-prefix',
         'pkb' + FLAGS.run_uri,
         '--ssh-key-value',
         vm_util.GetPublicKeyPath(),
     ] + self.resource_group.args)
    def _BuildAppBody(self):
        """
    Builds JSON which will be passed as a body of POST request to Marathon
    API in order to create App.
    """
        cat_cmd = ['cat', vm_util.GetPublicKeyPath()]
        key_file, _ = vm_util.IssueRetryableCommand(cat_cmd)
        cmd = "/bin/mkdir /root/.ssh; echo '%s' >> /root/.ssh/authorized_keys; " \
              "/usr/sbin/sshd -D" % key_file
        body = {
            'id': self.name,
            'mem': self.memory_mb,
            'cpus': self.cpus,
            'cmd': cmd,
            'container': {
                'type': 'DOCKER',
                'docker': {
                    'image':
                    self.image,
                    'network':
                    'BRIDGE',
                    'portMappings': [{
                        'containerPort': 22,
                        'hostPort': 0,
                        'protocol': 'tcp'
                    }],
                    'privileged':
                    self.privileged,
                    'parameters': [{
                        'key': 'hostname',
                        'value': self.name
                    }]
                }
            }
        }

        for scratch_disk in self.scratch_disks:
            scratch_disk.AttachVolumeInfo(body['container'])

        return json.dumps(body)
Beispiel #7
0
    def __init__(self, vm_spec):
        """Initialize BaseVirtualMachine class.

    Args:
      vm_spec: virtual_machine.BaseVirtualMachineSpec object of the vm.
    """
        super(BaseVirtualMachine, self).__init__()
        with self._instance_counter_lock:
            self.name = 'perfkit-%s-%d' % (FLAGS.run_uri,
                                           self._instance_counter)
            BaseVirtualMachine._instance_counter += 1
        self.create_time = None
        self.bootable_time = None
        self.project = vm_spec.project
        self.zone = vm_spec.zone
        self.machine_type = vm_spec.machine_type
        self.image = vm_spec.image
        self.network = vm_spec.network
        self.ip_address = None
        self.internal_ip = None
        self.user_name = None
        self.ssh_port = DEFAULT_SSH_PORT
        self.ssh_public_key = None
        self.ssh_private_key = None
        self.has_private_key = False
        self.user_name = DEFAULT_USERNAME
        self.ssh_public_key = vm_util.GetPublicKeyPath()
        self.ssh_private_key = vm_util.GetPrivateKeyPath()
        self.num_scratch_disks = 0
        self.disk_specs = []
        self.scratch_disks = []
        self.hostname = None
        self.max_local_disks = 0

        # Cached values
        self._reachable = {}
        self._total_memory_kb = None
        self._num_cpus = None
 def GetPublicKey(cls):
   cat_cmd = ['cat',
              vm_util.GetPublicKeyPath()]
   keyfile, _ = vm_util.IssueRetryableCommand(cat_cmd)
   return keyfile.strip()