Beispiel #1
0
class Ssh(PinshCmd.PinshCmd):
    "Provides the ability to SSH to a machine directly"

    def __init__(self):
        PinshCmd.PinshCmd.__init__(self, "ssh")
        self.help_text = "ssh\tssh to another host"
        self.config_field = ConfigField(data_type=MACHINE)
        self.children = [self.config_field]
        self.cmd_owner = 1
        self.log_command = True

    def cmd(self, command_line):
        "PinshCmd interface when someone hits return"
        if command_line.no_flag:
            return FAIL, []
        if len(command_line) < 2:
            return FAIL, ["Incomplete command."]
        #host_name = command_line[1]

        current_dict = self.config_field.get_specific_data(command_line, 1)
        ip_address = current_dict.get("ip_address")
        default_user = current_dict.get("default_user")

        if not default_user or not ip_address:
            msg  = ["ip_address and default_user are required in the system"]
            msg += ["configuration in order to access this host."]
            return FAIL, msg
        else:
            os.system('%s %s@%s'%(SSH, default_user, ip_address))
        return OK, []