#
#
-# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Google Inc.
+# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
I_FIELDS = ["name", "admin_state", "os",
"pnode", "snodes",
"disk_template",
- "nic.ips", "nic.macs", "nic.modes",
- "nic.links", "nic.networks", "nic.bridges",
+ "nic.ips", "nic.macs", "nic.modes", "nic.uuids", "nic.names",
+ "nic.links", "nic.networks", "nic.networks.names", "nic.bridges",
"network_port",
- "disk.sizes", "disk_usage",
+ "disk.sizes", "disk.spindles", "disk_usage", "disk.uuids",
+ "disk.names",
"beparams", "hvparams",
"oper_state", "oper_ram", "oper_vcpus", "status",
"custom_hvparams", "custom_beparams", "custom_nicparams",
] + _COMMON_FIELDS
N_FIELDS = ["name", "offline", "master_candidate", "drained",
- "dtotal", "dfree",
+ "dtotal", "dfree", "sptotal", "spfree",
"mtotal", "mnode", "mfree",
"pinst_cnt", "sinst_cnt",
- "ctotal", "cnodes", "csockets",
+ "ctotal", "cnos", "cnodes", "csockets",
"pip", "sip", "role",
"pinst_list", "sinst_list",
"master_capable", "vm_capable",
NET_FIELDS = ["name", "network", "gateway",
"network6", "gateway6",
- "mac_prefix", "network_type",
+ "mac_prefix",
"free_count", "reserved_count",
"map", "group_list", "inst_list",
- "external_reservations", "tags",
- ]
+ "external_reservations",
+ ] + _COMMON_FIELDS
G_FIELDS = [
"alloc_policy",
# Feature string for node evacuation with LU-generated jobs
_NODE_EVAC_RES1 = "node-evac-res1"
-ALL_FEATURES = frozenset([
+ALL_FEATURES = compat.UniqueFrozenset([
_INST_CREATE_REQV1,
_INST_REINSTALL_REQV1,
_NODE_MIGRATE_REQV1,
# FIXME: For compatibility we update the beparams/memory field. Needs to be
-# removed in Ganeti 2.7
+# removed in Ganeti 2.8
def _UpdateBeparams(inst):
"""Updates the beparams dict of inst to support the memory field.
@return: a dictionary with jobs id and uri.
"""
- client = self.GetClient()
+ client = self.GetClient(query=True)
if self.useBulk():
bulkdata = client.QueryJobs(None, J_FIELDS_BULK)
"""
job_id = self.items[0]
- result = self.GetClient().QueryJobs([job_id, ], J_FIELDS)[0]
+ result = self.GetClient(query=True).QueryJobs([job_id, ], J_FIELDS)[0]
if result is None:
raise http.HttpNotFound()
return baserlib.MapFields(J_FIELDS, result)
"""Returns a list of all networks.
"""
- client = self.GetClient()
+ client = self.GetClient(query=True)
if self.useBulk():
bulkdata = client.QueryNetworks([], NET_FIELDS, False)
class R_2_networks_name(baserlib.OpcodeResource):
- """/2/network/[network_name] resource.
+ """/2/networks/[network_name] resource.
"""
DELETE_OPCODE = opcodes.OpNetworkRemove
"""
network_name = self.items[0]
- client = self.GetClient()
+ client = self.GetClient(query=True)
result = baserlib.HandleItemQueryErrors(client.QueryNetworks,
names=[network_name],
"dry_run": self.dryRun(),
})
+
class R_2_networks_name_connect(baserlib.OpcodeResource):
- """/2/network/[network_name]/connect.
+ """/2/networks/[network_name]/connect resource.
"""
PUT_OPCODE = opcodes.OpNetworkConnect
assert self.items
return (self.request_body, {
"network_name": self.items[0],
+ "dry_run": self.dryRun(),
})
+
class R_2_networks_name_disconnect(baserlib.OpcodeResource):
- """/2/network/[network_name]/disconnect.
+ """/2/networks/[network_name]/disconnect resource.
"""
PUT_OPCODE = opcodes.OpNetworkDisconnect
assert self.items
return (self.request_body, {
"network_name": self.items[0],
+ "dry_run": self.dryRun(),
})
+
+class R_2_networks_name_modify(baserlib.OpcodeResource):
+ """/2/networks/[network_name]/modify resource.
+
+ """
+ PUT_OPCODE = opcodes.OpNetworkSetParams
+
+ def GetPutOpInput(self):
+ """Changes some parameters of network.
+
+ """
+ assert self.items
+ return (self.request_body, {
+ "network_name": self.items[0],
+ })
+
+
class R_2_groups(baserlib.OpcodeResource):
"""/2/groups resource.
})
+def _ConvertUsbDevices(data):
+ """Convert in place the usb_devices string to the proper format.
+
+ In Ganeti 2.8.4 the separator for the usb_devices hvparam was changed from
+ comma to space because commas cannot be accepted on the command line
+ (they already act as the separator between different hvparams). RAPI
+ should be able to accept commas for backwards compatibility, but we want
+ it to also accept the new space separator. Therefore, we convert
+ spaces into commas here and keep the old parsing logic elsewhere.
+
+ """
+ try:
+ hvparams = data["hvparams"]
+ usb_devices = hvparams[constants.HV_USB_DEVICES]
+ hvparams[constants.HV_USB_DEVICES] = usb_devices.replace(" ", ",")
+ data["hvparams"] = hvparams
+ except KeyError:
+ #No usb_devices, no modification required
+ pass
+
+
class R_2_instances(baserlib.OpcodeResource):
"""/2/instances resource.
# Remove "__version__"
data.pop(_REQ_DATA_VERSION, None)
+ _ConvertUsbDevices(data)
+
return (data, {
"dry_run": self.dryRun(),
})
raise http.HttpBadRequest("Request is missing required 'instances' field"
" in body")
- op_id = {
- "OP_ID": self.POST_OPCODE.OP_ID, # pylint: disable=E1101
- }
+ # Unlike most other RAPI calls, this one is composed of individual opcodes,
+ # and we have to do the filling ourselves
+ OPCODE_RENAME = {
+ "os": "os_type",
+ "name": "instance_name",
+ }
+
body = objects.FillDict(self.request_body, {
- "instances": [objects.FillDict(inst, op_id)
- for inst in self.request_body["instances"]],
+ "instances": [
+ baserlib.FillOpcode(opcodes.OpInstanceCreate, inst, {},
+ rename=OPCODE_RENAME)
+ for inst in self.request_body["instances"]
+ ],
})
return (body, {
"""Changes parameters of an instance.
"""
- return (self.request_body, {
+ data = self.request_body.copy()
+ _ConvertUsbDevices(data)
+
+ return (data, {
"instance_name": self.items[0],
})
if kind in (constants.TAG_INSTANCE,
constants.TAG_NODEGROUP,
- constants.TAG_NODE):
+ constants.TAG_NODE,
+ constants.TAG_NETWORK):
if not self.name:
raise http.HttpBadRequest("Missing name on tag request")
ssc = ssconf.SimpleStore()
tags = ssc.GetClusterTags()
+ else:
+ raise http.HttpBadRequest("Unhandled tag type!")
+
return list(tags)
def GetPutOpInput(self):
TAG_LEVEL = constants.TAG_NODEGROUP
+class R_2_networks_name_tags(_R_Tags):
+ """ /2/networks/[network_name]/tags resource.
+
+ Manages per-network tags.
+
+ """
+ TAG_LEVEL = constants.TAG_NETWORK
+
+
class R_2_tags(_R_Tags):
""" /2/tags resource.