Revision a76f0c4a scripts/gnt-instance
b/scripts/gnt-instance | ||
---|---|---|
176 | 176 |
return result_path |
177 | 177 |
|
178 | 178 |
|
179 |
def _EnsureInstancesExist(client, names): |
|
180 |
"""Check for and ensure the given instance names exist. |
|
181 |
|
|
182 |
This function will raise an OpPrereqError in case they don't |
|
183 |
exist. Otherwise it will exit cleanly. |
|
184 |
|
|
185 |
@type client: L{luxi.Client} |
|
186 |
@param client: the client to use for the query |
|
187 |
@type names: list |
|
188 |
@param names: the list of instance names to query |
|
189 |
@raise errors.OpPrereqError: in case any instance is missing |
|
190 |
|
|
191 |
""" |
|
192 |
# TODO: change LUQueryInstances to that it actually returns None |
|
193 |
# instead of raising an exception, or devise a better mechanism |
|
194 |
result = client.QueryInstances(names, ["name"]) |
|
195 |
for orig_name, row in zip(names, result): |
|
196 |
if row[0] is None: |
|
197 |
raise errors.OpPrereqError("Instance '%s' does not exist" % orig_name) |
|
198 |
|
|
199 |
|
|
179 | 200 |
def ListInstances(opts, args): |
180 | 201 |
"""List instances and their properties. |
181 | 202 |
|
... | ... | |
559 | 580 |
""" |
560 | 581 |
instance_name = args[0] |
561 | 582 |
force = opts.force |
583 |
cl = GetClient() |
|
562 | 584 |
|
563 | 585 |
if not force: |
586 |
_EnsureInstancesExist(cl, [instance_name]) |
|
587 |
|
|
564 | 588 |
usertext = ("This will remove the volumes of the instance %s" |
565 | 589 |
" (including mirrors), thus removing all the data" |
566 | 590 |
" of the instance. Continue?") % instance_name |
... | ... | |
569 | 593 |
|
570 | 594 |
op = opcodes.OpRemoveInstance(instance_name=instance_name, |
571 | 595 |
ignore_failures=opts.ignore_failures) |
572 |
SubmitOrSend(op, opts) |
|
596 |
SubmitOrSend(op, opts, cl=cl)
|
|
573 | 597 |
return 0 |
574 | 598 |
|
575 | 599 |
|
... | ... | |
811 | 835 |
@return: the desired exit code |
812 | 836 |
|
813 | 837 |
""" |
838 |
cl = GetClient() |
|
814 | 839 |
instance_name = args[0] |
815 | 840 |
force = opts.force |
816 | 841 |
|
817 | 842 |
if not force: |
843 |
_EnsureInstancesExist(cl, [instance_name]) |
|
844 |
|
|
818 | 845 |
usertext = ("Failover will happen to image %s." |
819 | 846 |
" This requires a shutdown of the instance. Continue?" % |
820 | 847 |
(instance_name,)) |
... | ... | |
823 | 850 |
|
824 | 851 |
op = opcodes.OpFailoverInstance(instance_name=instance_name, |
825 | 852 |
ignore_consistency=opts.ignore_consistency) |
826 |
SubmitOrSend(op, opts) |
|
853 |
SubmitOrSend(op, opts, cl=cl)
|
|
827 | 854 |
return 0 |
828 | 855 |
|
829 | 856 |
|
... | ... | |
839 | 866 |
@return: the desired exit code |
840 | 867 |
|
841 | 868 |
""" |
869 |
cl = GetClient() |
|
842 | 870 |
instance_name = args[0] |
843 | 871 |
force = opts.force |
844 | 872 |
|
845 | 873 |
if not force: |
874 |
_EnsureInstancesExist(cl, [instance_name]) |
|
875 |
|
|
846 | 876 |
if opts.cleanup: |
847 | 877 |
usertext = ("Instance %s will be recovered from a failed migration." |
848 | 878 |
" Note that the migration procedure (including cleanup)" % |
... | ... | |
858 | 888 |
|
859 | 889 |
op = opcodes.OpMigrateInstance(instance_name=instance_name, live=opts.live, |
860 | 890 |
cleanup=opts.cleanup) |
861 |
SubmitOpCode(op) |
|
891 |
SubmitOpCode(op, cl=cl)
|
|
862 | 892 |
return 0 |
863 | 893 |
|
864 | 894 |
|
Also available in: Unified diff