-
Notifications
You must be signed in to change notification settings - Fork 294
CA-209401: add static-vdis detach feature for HA #2731
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
Changes from all commits
0196985
cf3791a
f94daf3
5667bef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -197,6 +197,20 @@ def call_backend_attach(driver, config): | |
| path = xmlrpc[0][0] | ||
| return path | ||
|
|
||
| def call_backend_detach(driver, config): | ||
| params = xmlrpclib.loads(config)[0][0] | ||
| params['command'] = 'vdi_detach_from_config' | ||
| config = xmlrpclib.dumps(tuple([params]), params['command']) | ||
| xml = doexec([ driver, config ]) | ||
| if xml[0] <> 0: | ||
| raise Exception("SM_BACKEND_FAILURE(%d, %s, %s)" % xml) | ||
| xmlrpc = xmlrpclib.loads(xml[1]) | ||
| try: | ||
| res = xmlrpc[0][0]['params'] | ||
| except: | ||
| res = xmlrpc[0][0] | ||
| return res | ||
|
|
||
| def attach(vdi_uuid): | ||
| found = False | ||
| for existing in list(): | ||
|
|
@@ -230,13 +244,40 @@ def attach(vdi_uuid): | |
| return d + "/disk" | ||
| if not found: | ||
| raise Exception("Disk configuration not found") | ||
|
|
||
| def detach(vdi_uuid): | ||
| found = False | ||
| for existing in list(): | ||
| if existing['vdi-uuid'] == vdi_uuid: | ||
| if not (existing.has_key('disk')): | ||
| return | ||
| found = True | ||
| d = main_dir + "/" + existing['id'] | ||
| if not (os.path.exists(d + "/sr-uri")): | ||
| # SMAPIv1 | ||
| config = read_whole_file(d + "/config") | ||
| driver = read_whole_file(d + "/driver") | ||
| call_backend_detach(driver, config) | ||
| else: | ||
| volume_plugin = read_whole_file(d + "/volume-plugin") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency, I think these should be either called
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's to be consistent with those already used in the "attach" method above. We'd better keep it this way, or we can change them both together as code refactoring practice later on. |
||
| vol_key = read_whole_file(d + "/volume-key") | ||
| vol_uri = read_whole_file(d + "/volume-uri") | ||
| scheme = urlparse.urlparse(vol_uri).scheme | ||
| call_datapath_plugin(scheme, "Datapath.deactivate", [ vol_uri, "0" ]) | ||
| call_datapath_plugin(scheme, "Datapath.detach", [ vol_uri, "0" ]) | ||
| os.unlink(d + "/disk") | ||
| return | ||
| if not found: | ||
| raise Exception("Disk configuration not found") | ||
|
|
||
|
|
||
| def usage(): | ||
| print "Usage:" | ||
| print " %s list -- print a list of VDIs which will be attached on host boot" % sys.argv[0] | ||
| print " %s add <uuid> <reason> -- make the VDI <uuid> available on host boot" % sys.argv[0] | ||
| print " %s del <uuid> -- cease making the VDI <uuid> available on host boot" % sys.argv[0] | ||
| print " %s attach <uuid> -- attach the VDI immediately" % sys.argv[0] | ||
| print " %s detach <uuid> -- detach the VDI immediately" % sys.argv[0] | ||
| sys.exit(1) | ||
|
|
||
| if __name__ == "__main__": | ||
|
|
@@ -260,6 +301,8 @@ if __name__ == "__main__": | |
| elif sys.argv[1] == "attach" and len(sys.argv) == 3: | ||
| path = attach(sys.argv[2]) | ||
| print path | ||
| elif sys.argv[1] == "detach" and len(sys.argv) == 3: | ||
| detach(sys.argv[2]) | ||
| else: | ||
| usage() | ||
|
|
||
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 is
echo $"..."doing different fromecho "..."? I'm not familiar with this. It is also used above.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.
No idea, just inherited from above, and it seems quite pervasive in init.d scripts.
Did a little bit search around, it seems related to i18n (http://wiki.bash-hackers.org/syntax/quoting, search for i18n on the page).
Anyway, it seems no harm to keep it this way.