def _IsReady(self): """Returns True if the cluster is ready.""" vm_util.IssueCommand([ azure.AZURE_PATH, 'acs', 'kubernetes', 'get-credentials', '--name', self.name, '--file', FLAGS.kubeconfig, '--ssh-key-file', vm_util.GetPrivateKeyPath(), ] + self.resource_group.args, suppress_warning=True) version_cmd = [ FLAGS.kubectl, '--kubeconfig', FLAGS.kubeconfig, 'version' ] _, _, retcode = vm_util.IssueCommand(version_cmd, suppress_warning=True) if retcode: return False # POD creation will fail until the default service account in created. get_cmd = [ FLAGS.kubectl, '--kubeconfig', FLAGS.kubeconfig, 'get', 'serviceAccounts' ] stdout, _, _ = vm_util.IssueCommand(get_cmd) return 'default' in stdout
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.zone = vm_spec.zone self.machine_type = vm_spec.machine_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.network = None self.firewall = None
def __init__(self, vm_spec, network, firewall): """Initialize BaseVirtualMachine class. Args: vm_spec: virtual_machine.BaseVirtualMachineSpec object of the vm. network: network.BaseNetwork object corresponding to the VM. firewall: network.BaseFirewall object corresponding to 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.project = vm_spec.project self.zone = vm_spec.zone self.machine_type = vm_spec.machine_type self.image = vm_spec.image 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.network = network self.firewall = firewall
def __init__(self, vm_spec): """Initialize BaseVirtualMachine class. Args: vm_spec: virtual_machine.BaseVirtualMachineSpec object of the vm. """ super(BaseVirtualMachine, self).__init__() 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_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 # Cached values self._reachable = {} self._total_memory_kb = None self._num_cpus = None
def AuthenticateVm(self): """Authenticate a remote machine to access all peers.""" if not self.is_static and not self.has_private_key: self.RemoteHostCopy(vm_util.GetPrivateKeyPath(), REMOTE_KEY_PATH) self.RemoteCommand( 'echo "Host *\n StrictHostKeyChecking no\n" > ~/.ssh/config') self.has_private_key = True
def _PostCreate(self): """Get cluster info.""" if not FLAGS.kubeconfig: FLAGS.kubeconfig = vm_util.PrependTempDir('kubeconfig') vm_util.IssueRetryableCommand([ azure.AZURE_PATH, 'acs', 'kubernetes', 'get-credentials', '--name', self.name, '--file', FLAGS.kubeconfig, '--ssh-key-file', vm_util.GetPrivateKeyPath(), ] + self.resource_group.args)
def AuthenticateVm(self): """Authenticate a remote machine to access all peers.""" if not self.is_static and not self.has_private_key: self.RemoteHostCopy(vm_util.GetPrivateKeyPath(), REMOTE_KEY_PATH) with vm_util.NamedTemporaryFile() as tf: tf.write('Host *\n') tf.write(' StrictHostKeyChecking no\n') tf.close() self.PushFile(tf.name, '~/.ssh/config') self.has_private_key = True
def _CreateRiasKey(self): """Creates a ibmcloud key from the generated ssh key.""" logging.info('Creating rias key') with open(vm_util.GetPublicKeyPath(), 'r') as keyfile: pubkey = keyfile.read() logging.info('ssh private key file: %s, public key file: %s', \ vm_util.GetPrivateKeyPath(), vm_util.GetPublicKeyPath()) cmd = ibm.IbmAPICommand(self) cmd.flags['name'] = self.prefix + str(flags.FLAGS.run_uri) + 'key' cmd.flags['pubkey'] = pubkey return cmd.CreateKey()
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 _PostCreate(self): """Retrieve generic VM info and then retrieve the VM's password.""" super(WindowsAwsVirtualMachine, self)._PostCreate() # Get the decoded password data. decoded_password_data = self._GetDecodedPasswordData() # Write the encrypted data to a file, and use openssl to # decrypt the password. with vm_util.NamedTemporaryFile() as tf: tf.write(decoded_password_data) tf.close() decrypt_cmd = [ 'openssl', 'rsautl', '-decrypt', '-in', tf.name, '-inkey', vm_util.GetPrivateKeyPath() ] password, _ = vm_util.IssueRetryableCommand(decrypt_cmd) self.password = password
def AuthenticateVm(self): """Authenticate a remote machine to access all peers.""" self.RemoteHostCopy(vm_util.GetPrivateKeyPath(), REMOTE_KEY_PATH) self.has_private_key = True
def PreparePrivateKey(vm): if not vm.has_private_key: vm.PushFile(vm_util.GetPrivateKeyPath(), virtual_machine.REMOTE_KEY_PATH) vm.has_private_key = True
def AuthenticateVm(self): """Authenticate a remote machine to access all peers.""" self.PushFile(vm_util.GetPrivateKeyPath(), REMOTE_KEY_PATH)