Revision d50b3059
b/lib/rapi/baserlib.py | ||
---|---|---|
122 | 122 |
return items_details |
123 | 123 |
|
124 | 124 |
|
125 |
def MakeParamsDict(opts, params): |
|
126 |
""" Makes params dictionary out of a option set. |
|
127 |
|
|
128 |
This function returns a dictionary needed for hv or be parameters. But only |
|
129 |
those fields which provided in the option set. Takes parameters frozensets |
|
130 |
from constants. |
|
131 |
|
|
132 |
@type opts: dict |
|
133 |
@param opts: selected options |
|
134 |
@type params: frozenset |
|
135 |
@param params: subset of options |
|
136 |
@rtype: dict |
|
137 |
@return: dictionary of options, filtered by given subset. |
|
138 |
|
|
139 |
""" |
|
140 |
result = {} |
|
141 |
|
|
142 |
for p in params: |
|
143 |
try: |
|
144 |
value = opts[p] |
|
145 |
except KeyError: |
|
146 |
continue |
|
147 |
result[p] = value |
|
148 |
|
|
149 |
return result |
|
150 |
|
|
151 |
|
|
125 | 152 |
class R_Generic(object): |
126 | 153 |
"""Generic class for resources. |
127 | 154 |
|
b/lib/rapi/rlib1.py | ||
---|---|---|
285 | 285 |
|
286 | 286 |
return job_id |
287 | 287 |
|
288 |
def POST(self): |
|
289 |
"""Modify an instance. |
|
290 |
|
|
291 |
""" |
|
292 |
instance_name = self.items[0] |
|
293 |
opts = {} |
|
294 |
|
|
295 |
for key in self.queryargs: |
|
296 |
opts[key] = self.queryargs[key][0] |
|
297 |
|
|
298 |
beparams = baserlib.MakeParamsDict(opts, constants.BES_PARAMETERS) |
|
299 |
hvparams = baserlib.MakeParamsDict(opts, constants.HVS_PARAMETERS) |
|
300 |
|
|
301 |
op = ganeti.opcodes.OpSetInstanceParams( |
|
302 |
instance_name=instance_name, |
|
303 |
ip=opts.get('ip', None), |
|
304 |
bridge=opts.get('bridge', None), |
|
305 |
mac=opts.get('mac', None), |
|
306 |
hvparams=hvparams, |
|
307 |
beparams=beparams, |
|
308 |
force=opts.get('force', None)) |
|
309 |
|
|
310 |
job_id = ganeti.cli.SendJob([op]) |
|
311 |
|
|
312 |
return job_id |
|
313 |
|
|
288 | 314 |
|
289 | 315 |
class R_instances_name_tags(baserlib.R_Generic): |
290 | 316 |
"""/instances/[instance_name]/tags resource. |
b/lib/rapi/rlib2.py | ||
---|---|---|
205 | 205 |
""" |
206 | 206 |
opts = self.req.request_post_data |
207 | 207 |
|
208 |
# beparams |
|
209 |
mem = opts.get('mem', None) |
|
210 |
vcpus = opts.get('vcpus', None) |
|
211 |
auto_balance = opts.get('auto_balance', None) |
|
212 |
|
|
213 |
beparams = {} |
|
214 |
|
|
215 |
for key, const in [(mem, constants.BE_MEMORY), |
|
216 |
(vcpus, constants.BE_VCPUS), |
|
217 |
(auto_balance, constants.BE_AUTO_BALANCE)]: |
|
218 |
if key is not None: |
|
219 |
beparams[const] = key |
|
208 |
beparams = baserlib.MakeParamsDict(opts, constants.BES_PARAMETERS) |
|
209 |
hvparams = baserlib.MakeParamsDict(opts, constants.HVS_PARAMETERS) |
|
220 | 210 |
|
221 | 211 |
op = ganeti.opcodes.OpCreateInstance( |
222 | 212 |
instance_name=opts.get('name'), |
... | ... | |
234 | 224 |
wait_for_sync=opts.get('wait_for_sync', True), |
235 | 225 |
mac=opts.get('mac', 'auto'), |
236 | 226 |
hypervisor=opts.get('hypervisor', None), |
237 |
hvparams=opts.get('hvparams', {}),
|
|
227 |
hvparams=hvparams,
|
|
238 | 228 |
beparams=beparams, |
239 | 229 |
iallocator=opts.get('iallocator', None), |
240 | 230 |
file_storage_dir=opts.get('file_storage_dir', None), |
Also available in: Unified diff