def shell(self, user=None): """ Attempts to launch an interactive shell by first trying the system's ssh client. If the system does not have the ssh command it falls back to a pure-python ssh shell. """ if self.update() != 'running': try: alias = self.alias except exception.BaseException: alias = None label = 'instance' if alias == "master": label = "master" elif alias: label = "node" instance_id = alias or self.id raise exception.InstanceNotRunning(instance_id, self.state, label=label) user = user or self.user if utils.has_required(['ssh']): log.debug("using system's ssh client") ssh_cmd = static.SSH_TEMPLATE % (self.key_location, user, self.dns_name) log.debug("ssh_cmd: %s" % ssh_cmd) os.system(ssh_cmd) else: log.debug("using pure-python ssh client") self.ssh.interactive_shell(user=user)
def shell(self, user=None, forward_x11=False, forward_agent=False, pseudo_tty=False, command=None): """ Attempts to launch an interactive shell by first trying the system's ssh client. If the system does not have the ssh command it falls back to a pure-python ssh shell. """ if self.update() != 'running': try: alias = self.alias except exception.BaseException: alias = None label = 'instance' if alias == "master": label = "master" alias = "node" elif alias: label = "node" instance_id = alias or self.id raise exception.InstanceNotRunning(instance_id, self.state, label=label) user = user or self.user if utils.has_required(['ssh']): log.debug("Using native OpenSSH client") sshopts = '-i %s' % self.key_location if forward_x11: sshopts += ' -Y' if forward_agent: sshopts += ' -A' if pseudo_tty: sshopts += ' -t' ssh_cmd = static.SSH_TEMPLATE % dict( opts=sshopts, user=user, host=self.addr) if command: command = "'source /etc/profile && %s'" % command ssh_cmd = ' '.join([ssh_cmd, command]) log.debug("ssh_cmd: %s" % ssh_cmd) return subprocess.call(ssh_cmd, shell=True) else: log.debug("Using Pure-Python SSH client") if forward_x11: log.warn("X11 Forwarding not available in Python SSH client") if forward_agent: log.warn("Authentication agent forwarding not available in " + "Python SSH client") if pseudo_tty: log.warn("Pseudo-tty allocation is not available in " + "Python SSH client") if command: orig_user = self.ssh.get_current_user() self.ssh.switch_user(user) self.ssh.execute(command, silent=False) self.ssh.switch_user(orig_user) return self.ssh.get_last_status() self.ssh.interactive_shell(user=user)
def _validate_host_instance(self, instance, zone): if instance.state not in ['pending', 'running']: raise exception.InstanceNotRunning(instance.id) if instance.placement != zone: raise exception.ValidationError( "specified host instance %s is not in zone %s" % (instance.id, zone)) return True
def __init__(self, easy_ec2, instance_id, key_location, description=None, kernel_id=None, ramdisk_id=None): self.ec2 = easy_ec2 self.host = self.ec2.get_instance(instance_id) if self.host.state != 'running': raise exception.InstanceNotRunning(self.host.id, self.host.state, self.host.dns_name) self.host_ssh = ssh.SSHClient(self.host.dns_name, username='******', private_key=key_location) self.description = description self.kernel_id = kernel_id or self.host.kernel self.ramdisk_id = ramdisk_id or self.host.ramdisk
def shell(self, user=None): """ Attempts to launch an interactive shell by first trying the system's ssh client. If the system does not have the ssh command it falls back to a pure-python ssh shell. """ if self.state != 'running': label = 'instance' if self.alias == "master": label = "master node" elif self.alias: label = "node '%s'" % self.alias raise exception.InstanceNotRunning(self.id, self.state, label=label) if utils.has_required(['ssh']): log.debug("using system's ssh client") user = user or self.user os.system(static.SSH_TEMPLATE % (self.key_location, user, self.dns_name)) else: log.debug("using pure-python ssh client") self.ssh.interactive_shell()