-
Notifications
You must be signed in to change notification settings - Fork 48
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
(QENG-2636) Host snapshots #117
Conversation
How many snapshots can a VM have at one time? |
result[params[:hostname]] = {} | ||
|
||
o = [('a'..'z'), ('0'..'9')].map(&:to_a).flatten | ||
result[params[:hostname]]['snapshot'] = o[rand(25)] + (0...31).map { o[rand(o.length)] }.join |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There isn't a random name method available?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There isn't a random name method available?
Not currently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would definitely say this pair of lines is a candidate for extracting to a method with an intention-revealing name.
def random_snapshot_name
o = [('a'..'z'), ('0'..'9')].map(&:to_a).flatten
o[rand(25)] + (0...31).map { o[rand(o.length)] }.join
end
# ...
post "#{api_prefix}/vm/:hostname/snapshot/?" do
content_type :json
status 404
result = { 'ok' => false }
hostname = params[:hostname] = hostname_shorten(params[:hostname], config['domain'])
if backend.exists("vmpooler__vm__#{hostname}")
result[hostname] = {}
result[hostname]['snapshot'] = random_snapshot_name
backend.sadd('vmpooler__tasks__snapshot', hostname + ':' + result[hostname]['snapshot'])
status 202
result['ok'] = true
end
JSON.pretty_generate(result)
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the usefulness of a create_a_random_string_of_N_characters
method. Currenlty both pool_manager
and api/v1
have randomization code in them, and unfortunately there isn't currently a helper library which is shared throughout the app. I can certainly refactor some code to accomplish this, but am unsure if it's out of the scope of the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would ticket the creation of the method and work on it separately. It is out-of-scope of this PR, IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, defer for separate work.
No limit defined by either vmpooler or vSphere. |
end | ||
end | ||
|
||
def _create_vm_snapshot(vm, snapshot_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method should do some scrutiny of snapshot_name
. Or is that left to CreateSnapshot_Task
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What sort of scrutiny do you have in mind? As-is the only method calling create_vm_snapshot
is the API, which is generating the snapshot_name
var right before calling this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly a check that it is not nil
or empty?
.
Random Question, will you have to be auth'ed to use snap shotting? |
That's actually something I started thinking about yesterday. This PR doesn't require auth at the moment, but as snapshotting is a relatively "expensive" vSphere task, I think it probably should. |
This is ready for re-review. Addressed applicable comments above and included an additional commit to support requiring authentication tokens when using snapshots. |
I've deployed this branch to |
Some UX things I haven't figured out how to solve yet:
|
@@ -413,6 +413,11 @@ def need_token! | |||
result[params[:hostname]]['tags'] ||= {} | |||
result[params[:hostname]]['tags'][$1] = rdata[key] | |||
end | |||
|
|||
if key.match('^snapshot\:(.+?)$') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be an elsif
for the above if
.
This PR introduces host (VM) snapshotting support. Example workflow: