Esempio n. 1
0
 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)
Esempio n. 2
0
 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)
Esempio n. 3
0
 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)
Esempio n. 4
0
 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'
         addr = self.dns_name
         if self.instance.vpc_id:
             addr = self.private_ip_address
         ssh_cmd = static.SSH_TEMPLATE % dict(opts=sshopts, user=user,
                                              host=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)
Esempio n. 5
0
 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()
Esempio n. 6
0
 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()