Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Host table to manage remote hosts #29

Closed
utsengar opened this issue Aug 31, 2013 · 2 comments
Closed

Add Host table to manage remote hosts #29

utsengar opened this issue Aug 31, 2013 · 2 comments

Comments

@utsengar
Copy link

I have added "add remote host" form in the settings page for now.

I have 2 primary endpoints:

  1. add_host (will be called from settings page)
  2. add_host_to_task (will be called from job details)

Once the request comes in api.py's add_host what function should be invoked to add the host to dagobah_host table?

I am little confused with the way I should structure my code.
Should I create a new Host(object) class in core.py? And write a new function commit_host in base.py (which will endup in sqlite.py and mongo.py)?

If I do all that, I will end up writing a parallel Job object. But again, remote host info is completely isolated from the job info so does it make sense to keep these in two different classes.

DagobahHost model:

class DagobahHost(Base):
    __tablename__ = 'dagobah_host'

    id = Column(Integer, primary_key=True)
    task_id = Column(Integer, ForeignKey('dagobah_task.id'), index=True)
    name = Column(String(1000), nullable=False)
    username = Column(String(1000), nullable=False)
    password = Column(String(1000))
    key = Column(String(1000))

    def __init__(self, name, username):
        self.name = name
        self.username = username

    def __repr__(self):
        return "<SQLite:DagobahHost (%d)>" % self.id

    @property
    def json(self):
        return {'task_id': self.task_id,
                'name': self.name,
                'username': self.username,
                'password': self.password,
                'key': self.key}

    def update_from_dict(self, data):
        for key in ['task_id', 'name', 'username', 'password', 'key']:
            if key in data:
                setattr(self, key, data[key])

And in DagobahTask(Base):

    hosts = relationship('DagobahHost', backref='task')

What do you suggest? How will you structure your code?

@thieman
Copy link
Owner

thieman commented Aug 31, 2013

The Host class should live in the poorly-named components.py module.

The core Dagobah class should maintain its own list of Hosts, very similar to how it maintains a list of the Jobs it knows about. You should add a commit_host method to all of the backends, as well as making relevant changes to other methods like delete_dagobah (basically, do for hosts whatever the backend is doing for jobs). The Mongo backend should get a new collection to store the Hosts on (in addition to their place as an array on the main Dagobah collection). The SQLite backend will need to do its whole normalized thing, adding at least one additional table depending on how you want to structure the Hosts themselves.

Can you elaborate on what you meant by a parallel job object?

You're tackling a pretty big feature here and getting yourself into pretty much the entire code base, so let me know if you'd like me to help with anything. Thanks again.

@thieman
Copy link
Owner

thieman commented Aug 31, 2013

Also, let's try to keep discussion on the PR to the branch I've set up so we don't have to keep adding issues.

@thieman thieman closed this as completed Aug 31, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants