Revision 973d7867
b/lib/cmdlib.py | ||
---|---|---|
4101 | 4101 |
self.ip = getattr(self.op, "ip", None) |
4102 | 4102 |
self.mac = getattr(self.op, "mac", None) |
4103 | 4103 |
self.bridge = getattr(self.op, "bridge", None) |
4104 |
if [self.mem, self.vcpus, self.ip, self.bridge, self.mac].count(None) == 5: |
|
4104 |
self.kernel_path = getattr(self.op, "kernel_path", None) |
|
4105 |
self.initrd_path = getattr(self.op, "initrd_path", None) |
|
4106 |
all_parms = [self.mem, self.vcpus, self.ip, self.bridge, self.mac, |
|
4107 |
self.kernel_path, self.initrd_path] |
|
4108 |
if all_parms.count(None) == len(all_parms): |
|
4105 | 4109 |
raise errors.OpPrereqError("No changes submitted") |
4106 | 4110 |
if self.mem is not None: |
4107 | 4111 |
try: |
... | ... | |
4130 | 4134 |
if not utils.IsValidMac(self.mac): |
4131 | 4135 |
raise errors.OpPrereqError('Invalid MAC address %s' % self.mac) |
4132 | 4136 |
|
4137 |
if self.kernel_path is not None: |
|
4138 |
self.do_kernel_path = True |
|
4139 |
if self.kernel_path == constants.VALUE_NONE: |
|
4140 |
raise errors.OpPrereqError("Can't set instance to no kernel") |
|
4141 |
|
|
4142 |
if self.kernel_path != constants.VALUE_DEFAULT: |
|
4143 |
if not os.path.isabs(self.kernel_path): |
|
4144 |
raise errors.OpPrereError("The kernel path must be an absolute" |
|
4145 |
" filename") |
|
4146 |
|
|
4147 |
if self.initrd_path is not None: |
|
4148 |
self.do_initrd_path = True |
|
4149 |
if self.initrd_path not in (constants.VALUE_NONE, |
|
4150 |
constants.VALUE_DEFAULT): |
|
4151 |
if not os.path.isabs(self.kernel_path): |
|
4152 |
raise errors.OpPrereError("The initrd path must be an absolute" |
|
4153 |
" filename") |
|
4154 |
|
|
4133 | 4155 |
instance = self.cfg.GetInstanceInfo( |
4134 | 4156 |
self.cfg.ExpandInstanceName(self.op.instance_name)) |
4135 | 4157 |
if instance is None: |
... | ... | |
4161 | 4183 |
if self.mac: |
4162 | 4184 |
instance.nics[0].mac = self.mac |
4163 | 4185 |
result.append(("mac", self.mac)) |
4186 |
if self.do_kernel_path: |
|
4187 |
instance.kernel_path = self.kernel_path |
|
4188 |
result.append(("kernel_path", self.kernel_path)) |
|
4189 |
if self.do_initrd_path: |
|
4190 |
instance.initrd_path = self.initrd_path |
|
4191 |
result.append(("initrd_path", self.initrd_path)) |
|
4164 | 4192 |
|
4165 | 4193 |
self.cfg.AddInstance(instance) |
4166 | 4194 |
|
b/lib/constants.py | ||
---|---|---|
60 | 60 |
XEN_KERNEL = _autoconf.XEN_KERNEL |
61 | 61 |
XEN_INITRD = _autoconf.XEN_INITRD |
62 | 62 |
|
63 |
VALUE_DEFAULT = "default" |
|
64 |
VALUE_NONE = "none" |
|
65 |
|
|
63 | 66 |
# hooks-related constants |
64 | 67 |
HOOKS_BASE_DIR = _autoconf.SYSCONFDIR + "/ganeti/hooks" |
65 | 68 |
HOOKS_PHASE_PRE = "pre" |
b/lib/opcodes.py | ||
---|---|---|
260 | 260 |
class OpSetInstanceParms(OpCode): |
261 | 261 |
"""Change the parameters of an instance.""" |
262 | 262 |
OP_ID = "OP_INSTANCE_SET_PARMS" |
263 |
__slots__ = ["instance_name", "mem", "vcpus", "ip", "bridge", "mac"] |
|
263 |
__slots__ = [ |
|
264 |
"instance_name", "mem", "vcpus", "ip", "bridge", "mac", |
|
265 |
"kernel_path", "initrd_path", |
|
266 |
] |
|
264 | 267 |
|
265 | 268 |
|
266 | 269 |
# OS opcodes |
b/scripts/gnt-instance | ||
---|---|---|
134 | 134 |
return choice |
135 | 135 |
|
136 | 136 |
|
137 |
def _TransformPath(user_input): |
|
138 |
"""Transform a user path into a canonical value. |
|
139 |
|
|
140 |
This function transforms the a path passed as textual information |
|
141 |
into the constants that the LU code expects. |
|
142 |
|
|
143 |
""" |
|
144 |
if user_input: |
|
145 |
if user_input.lower() == "default": |
|
146 |
result_path = constants.VALUE_DEFAULT |
|
147 |
elif user_input.lower() == "none": |
|
148 |
result_path = constants.VALUE_NONE |
|
149 |
else: |
|
150 |
if not os.path.isabs(user_input): |
|
151 |
raise errors.OpPrereqError("Path '%s' is not an absolute filename" % |
|
152 |
user_input) |
|
153 |
result_path = user_input |
|
154 |
else: |
|
155 |
result_path = constants.VALUE_DEFAULT |
|
156 |
|
|
157 |
return result_path |
|
158 |
|
|
159 |
|
|
137 | 160 |
def ListInstances(opts, args): |
138 | 161 |
"""List instances and their properties. |
139 | 162 |
|
... | ... | |
627 | 650 |
mac - the new MAC address of the instance |
628 | 651 |
|
629 | 652 |
""" |
630 |
if not (opts.mem or opts.vcpus or opts.ip or opts.bridge or opts.mac): |
|
653 |
if not (opts.mem or opts.vcpus or opts.ip or opts.bridge or opts.mac or |
|
654 |
opts.kernel_path or opts.initrd_path): |
|
631 | 655 |
logger.ToStdout("Please give at least one of the parameters.") |
632 | 656 |
return 1 |
633 | 657 |
|
658 |
kernel_path = _TransformPath(opts.kernel_path) |
|
659 |
initrd_path = _TransformPath(opts.initrd_path) |
|
660 |
|
|
634 | 661 |
op = opcodes.OpSetInstanceParms(instance_name=args[0], mem=opts.mem, |
635 | 662 |
vcpus=opts.vcpus, ip=opts.ip, |
636 |
bridge=opts.bridge, mac=opts.mac) |
|
663 |
bridge=opts.bridge, mac=opts.mac, |
|
664 |
kernel_path=opts.kernel_path, |
|
665 |
initrd_path=opts.initrd_path) |
|
637 | 666 |
result = SubmitOpCode(op) |
638 | 667 |
|
639 | 668 |
if result: |
... | ... | |
815 | 844 |
make_option("--mac", dest="mac", |
816 | 845 |
help="MAC address", default=None, |
817 | 846 |
type="string", metavar="<MACADDRESS>"), |
847 |
make_option("--kernel", dest="kernel_path", |
|
848 |
help="Path to the instances' kernel (or" |
|
849 |
" 'default')", default=None, |
|
850 |
type="string", metavar="<FILENAME>"), |
|
851 |
make_option("--initrd", dest="initrd_path", |
|
852 |
help="Path to the instances' initrd (or 'none', or" |
|
853 |
" 'default')", default=None, |
|
854 |
type="string", metavar="<FILENAME>"), |
|
818 | 855 |
], |
819 | 856 |
"<instance>", "Alters the parameters of an instance"), |
820 | 857 |
'shutdown': (ShutdownInstance, ARGS_ANY, |
Also available in: Unified diff