ytti / oxidized-web

Web UI + RESTful API for Oxidized
118 stars 72 forks source link

'/node/next/${NODE_NAME}' returns no OID #266

Closed max-dw-i closed 2 months ago

max-dw-i commented 2 months ago

Currently the end-point /node/next/${NODE_NAME} returns nothing (it redirects to /node). It would be very handy to have some metadata in a response (oid, at least). Having an oid, we could call /node/version/view to check if the backup was created at all and link the /node/next/${NODE_NAME} call to the actual 'backup' record from /node/version. Would it be possible to implement such a thing?

robertcheramy commented 2 months ago

/node/next/${NODE_NAME} only queues the node to get its configuration reloaded. It returns before the configuration has been reloaded, so this is not possible to return the git oid at this time. /node/next/${NODE_NAME}.json returns "ok", which only means the job has been queued. You could use /node/version.json?node_full=${NODE_NAME} and/or /node/show/${NODE_NAME}.json

max-dw-i commented 2 months ago

The problem is that all these methods does not help to link a /node/next/${NODE_NAME} call with a /node/version.json?node_full=${NODE_NAME} response. Here is an example of a use case. A user makes a configuration backup and want to add some kind of comment to this backup (idk, Changed the default gateway to 1.2.3.4). Since /node/next/${NODE_NAME} does not return any ID (backup ID, queue job ID, etc.), we cannot link the comment and the made backup. Getting the last made backup OID is not reliable. What if another user decided to make a backup of the same node at the same time. Maybe some kind of queue job ID can be generated when /node/next/${NODE_NAME} is called and the same job ID can be added into /node/version.json?node_full=${NODE_NAME} response?

ytti commented 2 months ago

When you say 'add some kind of commit to this backup', what do you mean? Where is this comment stored? We can pass commit author and commit message in 'next', so that after the configuration is next picked up, the commit is made as given user and given message.

max-dw-i commented 2 months ago

When you say 'add some kind of commit to this backup', what do you mean? Where is this comment stored?

Any external storage, does not matter basically. MongoDB, let's say.

We can pass commit author and commit message in 'next', so that after the configuration is next picked up, the commit is made as given user and given message.

Could you give a link to the docs where it's described, please? I could not find it. A commit message could be the solution. But again what if we'd like to link some other metadata to a backup (not only a text comment). Of course we could shove everything into commit messages and parse them when we need it. Though this solution is a bit smelly I think.

ytti commented 2 months ago

Not sure if there is documentation, but there is example of it being used. Here if user passed commit message to junos, that commit message is re-emitted to oxdized github backend, as well as users name, so git history will show who made the change and if they added message to it.

max-dw-i commented 2 months ago

I might've misunderstood you. When you said

We can pass commit author and commit message in 'next'

I thought you meant that there are some query parameter for the method /node/next/${NODE_NAME} that allows to pass a commit message. For example, /node/next/${NODE_NAME}?commit_msg=Changed_default_gateway.

ytti commented 2 months ago

Yes, that's what's happening in the example shown.

robertcheramy commented 2 months ago

That's not a very good documentation, but you can have a look at the unit test: https://github.com/ytti/oxidized-web/blob/c5e37387b6452ca4ff061f691859c7b0946019f8/spec/node_spec.rb#L69 https://github.com/ytti/oxidized-web/blob/c5e37387b6452ca4ff061f691859c7b0946019f8/spec/node_spec.rb#L84

You must make a HTTP PUT with the attributes for the commit as json.

I was wondering, if there is a use-case for this, now I know - Yes, there is ;-)

max-dw-i commented 1 month ago

I finally had time to check this solution out. Everything works.

P.S. For the people who may stumble on this issue. I make PUT requests to /node/next/${NODE}.json. The keys that can be used in the request body:

{
    user: 'me',
    email: 'me@mail.com',
    msg: 'MESSAGE',
    from: 'unused variable!',
}

Thank you for the help.