Example #1
0
 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
Example #2
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, []
Example #3
0
    def __init__(self):
        'Top-level object'
        PinshCmd.PinshCmd.__init__(self, "user")
        self.help_text = "user\tcommands for managing users"
        self.cmd_owner = 1
        self.children = []
        self.auth = ENABLE
        self.user_field = ConfigField(data_type=USER)
        self.children = [self.user_field]

        delete = PinshCmd.PinshCmd("delete", "delete\tdelete this user (can't be yourself)")
        edit = PinshCmd.PinshCmd("edit", "edit\tedit the configuration for this user")
        set_password = PinshCmd.PinshCmd("set-password", "set-password\tset the password for this user")
        self.user_field.children = [delete, edit, set_password]
Example #4
0
    def __init__(self):
        'Top-level object'
        PinshCmd.PinshCmd.__init__(self, "package")
        self.help_text = "package\tcommands that operate on a given package"
        self.cmd_owner = 1
        self.children = []
        self.auth = ENABLE
        self.package_field = ConfigField(data_type=PACKAGE)
        self.children = [self.package_field]

        build = PinshCmd.PinshCmd("build", "build a package from source control")
        edit = PinshCmd.PinshCmd("edit", "edit the configuration for this package")
        show = PinshCmd.PinshCmd("show", "display the configuration for this package")
        self.package_field.children = [build, edit, show]
Example #5
0
class User(PinshCmd.PinshCmd):
    "Command-line object for modifying administrative users"

    def __init__(self):
        'Top-level object'
        PinshCmd.PinshCmd.__init__(self, "user")
        self.help_text = "user\tcommands for managing users"
        self.cmd_owner = 1
        self.children = []
        self.auth = ENABLE
        self.user_field = ConfigField(data_type=USER)
        self.children = [self.user_field]

        delete = PinshCmd.PinshCmd("delete", "delete\tdelete this user (can't be yourself)")
        edit = PinshCmd.PinshCmd("edit", "edit\tedit the configuration for this user")
        set_password = PinshCmd.PinshCmd("set-password", "set-password\tset the password for this user")
        self.user_field.children = [delete, edit, set_password]

    def check_user_name(self, command_line):
        "look in command line for valid user name, assuming field 1"
        possible_user_names = self.user_field.preferred_names(command_line, 1)
        user_name = possible_user_names[0]
        if command_line.no_flag:
            raise CommandError("NO cannot be used here")
        if len(possible_user_names) == 0:
            raise CommandError("Unknown user name: %s" % command_line[2])
        if len(possible_user_names) > 1:
            raise CommandError("Ambiguous user name: %s" % command_line[2])
        return user_name

    def cmd(self, command_line):
        """
        command_line -- all of the keywords passed in the command string, parsed
        """
        status = OK
        output = []

        if len(command_line) < 2:
            raise CommandError("Incomplete command.")
        user_name = self.check_user_name(command_line)
        if len(command_line) == 2:
            system_state.push_prompt(["user", user_name])
        else:
            command = command_line[2].lower()

            if command == "edit":
                status, output = Edit.User().cmd(["edit", "user", user_name], 0)

            elif command == "set-password":
                password = libUi.pwd_input("password for %s: " % user_name)
                try:
                    status, output = system_state.cnm_connector.set_password(user_name, password)
                except MachineTraceback, m_err:
                    libUi.process_traceback(m_err)
                    status = FAIL

            elif command == "delete":
                if system_state.username == user_name:
                    status = FAIL
                    output = ["Cannot delete your own user object."]
                else:
                    prompt = 'Delete user "%s" -- are you sure' % user_name
                    if libUi.ask_yes_no(prompt, libUi.NO) == libUi.NO:
                        status = FAIL
                        output = ["Aborted"]
                    try:
                        return system_state.cnm_connector.delete_user(user_name)
                    except MachineTraceback, m_err:
                        libUi.process_traceback(m_err)
                        status = FAIL
Example #6
0
class Package(PinshCmd.PinshCmd):
    '''
       bomsh# package TestPackage build
       [OK, ['install OK: TestPackageType4-7', 'verify OK: TestPackageType4-7', 'Finished installing']]
    '''

    def __init__(self):
        'Top-level object'
        PinshCmd.PinshCmd.__init__(self, "package")
        self.help_text = "package\tcommands that operate on a given package"
        self.cmd_owner = 1
        self.children = []
        self.auth = ENABLE
        self.package_field = ConfigField(data_type=PACKAGE)
        self.children = [self.package_field]

        build = PinshCmd.PinshCmd("build", "build a package from source control")
        edit = PinshCmd.PinshCmd("edit", "edit the configuration for this package")
        show = PinshCmd.PinshCmd("show", "display the configuration for this package")
        self.package_field.children = [build, edit, show]

    def check_package_name(self, command_line):
        """Get a real package name from the command_line, assuming the
        package name is the second field"""
        possible_package_names = self.package_field.preferred_names(command_line, 1)
        package_name = possible_package_names[0]
        if command_line.no_flag:
            raise CommandError("NO cannot be used here")
        if len(possible_package_names) == 0:
            raise CommandError("Unknown package name: %s" % command_line[2])
        if len(possible_package_names) > 1:
            raise CommandError("Ambiguous package name: %s" % command_line[2])
        return package_name

    def cmd(self, command_line):
        """
        command_line -- all of the keywords passed in the command string, parsed
        """
        if len(command_line) < 2:
            raise CommandError("Incomplete command.")
        package_name = self.check_package_name(command_line)
        if len(command_line) == 2:
            system_state.push_prompt(["package", package_name])
            return OK, []

        command = command_line[2].lower()

        if command == "show":
            return Show.Package().cmd(["show", "package", package_name], 0)

        if command == "edit":
            return Edit.Package().cmd(["edit", "package", package_name], 0)

        if command == "build":
            svn_password = ''
            svn_user = libUi.get_default("svn user", '')
            if svn_user:
                svn_password = libUi.pwd_input("svn password: ")
            try:
                cnm = system_state.cnm_connector
                return cnm.package_build_job(package_name, svn_user,
                                             svn_password, command_line.bg_flag)
            except MachineTraceback, m_err:
                libUi.process_traceback(m_err)
                return FAIL, []