Esempio n. 1
0
File: cli.py Progetto: nictuku/nwu
    def cmd_view(self, computer_id, detail=None):
        """View an specific info from the specified computer
        """
        if not detail:
            show_help()

        computer = Computer.get_by(id=computer_id)
        
        if not computer:
            print >> sys.stderr, "Specified computer not found in the database."
            sys.exit(1)
 
        details_map = {
            'packages' : 'current_packages',
            'update-candidates' : 'update_candidates',
            'repositories' : 'repositories',
            'tasks' : 'tasks'
            }

        try:
            read_table = getattr(computer, details_map[detail])
        except:
            show_help()

        output = "Reading %s from computer %s" % (detail, repr(computer))
        for i in read_table:
            # FIXME: define __repr__ in each db table class
            # and use some formatting feature like:
            #    fill = 45 - len(package.name)
            #    fill_blank = " " * fill
            #    print package.name + fill_blank +  package.version

            output += repr(i)
        return output
Esempio n. 2
0
File: cli.py Progetto: nictuku/nwu
 def __set_task(self, computer, task_type, *details):
     output = ''
     if len(details) == 0:
         show_help()
     computer = Computer.get_by(id=computer_id)
     details = " ".join(details)
     output += "Found %s in the database. Requesting %s of %s" % \
         (repr(computer), task_type, details)
     Tasks(computer=computer, action=task_type, details=details)
     session.flush()
     return output
Esempio n. 3
0
File: agent.py Progetto: nictuku/nwu
    def create_computer(self, account, remote_host, hostname, os_name,
                        os_version):
        """Create computer in database (and link it to the account of the
        creator).

        Returns the computer id.
        """
        # XXX: Add logging.

        if not type(hostname) == str or not type(os_name) == str \
                or not type(os_version) == str:
            raise InvalidParamsFault('create_computer')

        if account.computer:
            raise NotPossibleFault('Account already associated with a computer'
                                   'record.')

        c = Computer(hostname=hostname, os_name=os_name, os_version=os_version)
        c.save()
        c.flush()

        return c.oid
Esempio n. 4
0
    def test_install(self):
        # we need objects from the other tests    
        objectstore.flush()
        target_pkgs = ['install_a', 'install_b']
        CLI.cmd_forceinstall(1, *target_pkgs)
        assert RPC.get_tasks([UNIQ, TOKEN]) == [('forceinstall', 
            'install_a install_b')]
        assert CLI.cmd_list() == '1\tmoinmoin\tLinux\n'
        assert CLI.cmd_view(1, 'packages') == \
'Reading packages from computer <Computer moinmoin(1)>' 
        m = Computer.get_by(id=1)
        installed = CurrentPackages(computer=m, name='gcc', version='1.1')
        installed = CurrentPackages(computer=m, name='znes', version='4.1')
        objectstore.flush()
        # this just a dumb debug. 
        # FIXME: use a proper __repr__ on the CurrPackages class
        log.debug(CLI.cmd_view(1, 'packages'))