Esempio n. 1
0
    def __init__(self, **kwargs):
        super(Computer, self).__init__()

        uuid = kwargs.pop('uuid', None)
        if uuid is not None:
            if kwargs:
                raise ValueError("If you pass a uuid, you cannot pass any "
                                 "further parameter")

            dbcomputer = DbComputer.query.filter_by(uuid=uuid).first()
            if not dbcomputer:
                raise NotExistent("No entry with UUID={} found".format(uuid))

            self._dbcomputer = dbcomputer

        else:
            if 'dbcomputer' in kwargs:
                dbcomputer = kwargs.pop('dbcomputer')
                if not (isinstance(dbcomputer, DbComputer)):
                    raise TypeError("dbcomputer must be of type DbComputer")
                self._dbcomputer = dbcomputer

                if kwargs:
                    raise ValueError("If you pass a dbcomputer parameter, "
                                     "you cannot pass any further parameter")
            else:
                self._dbcomputer = DbComputer()

            # Set all remaining parameters, stop if unknown
            self.set(**kwargs)
Esempio n. 2
0
 def set_computer(self, computer):
     if self._to_be_stored:
         computer = DbComputer.get_dbcomputer(computer)
         self.dbnode.dbcomputer = computer
     else:
         raise ModificationNotAllowed(
             "Node with uuid={} was already stored".format(self.uuid))
Esempio n. 3
0
    def can_run_on(self, computer):
        """
        Return True if this code can run on the given computer, False otherwise.

        Local codes can run on any machine; remote codes can run only on the machine
        on which they reside.

        TODO: add filters to mask the remote machines on which a local code can run.
        """
        if self.is_local():
            return True
        else:
            dbcomputer = computer
            if isinstance(dbcomputer, Computer):
                dbcomputer = dbcomputer.dbcomputer
            if not isinstance(dbcomputer, DbComputer):
                raise ValueError(
                    "computer must be either a Computer or DbComputer object")
            dbcomputer = DbComputer.get_dbcomputer(computer)
            return (dbcomputer.id == self.get_remote_computer().dbcomputer.id)
Esempio n. 4
0
 def _set_db_computer(self, computer):
     self.dbnode.dbcomputer = DbComputer.get_dbcomputer(computer)
Esempio n. 5
0
 def get(cls, computer):
     return cls(dbcomputer=DbComputer.get_dbcomputer(computer))
Esempio n. 6
0
 def __init__(self, backend, **kwargs):
     super(SqlaComputer, self).__init__(backend)
     self._dbmodel = utils.ModelWrapper(DbComputer(**kwargs))