+ else:
+ data = self.request_body
+
+ op = baserlib.FillOpcode(opcodes.OpNodeMigrate, data, {
+ "node_name": node_name,
+ })
+
+ return baserlib.SubmitJob([op])
+
+
+class R_2_nodes_name_modify(baserlib.R_Generic):
+ """/2/nodes/[node_name]/modify resource.
+
+ """
+ def POST(self):
+ """Changes parameters of a node.
+
+ @return: a job id
+
+ """
+ baserlib.CheckType(self.request_body, dict, "Body contents")
+
+ op = baserlib.FillOpcode(opcodes.OpNodeSetParams, self.request_body, {
+ "node_name": self.items[0],
+ })
+
+ return baserlib.SubmitJob([op])
+
+
+class R_2_nodes_name_storage(baserlib.R_Generic):
+ """/2/nodes/[node_name]/storage resource.
+
+ """
+ # LUNodeQueryStorage acquires locks, hence restricting access to GET
+ GET_ACCESS = [rapi.RAPI_ACCESS_WRITE]
+
+ def GET(self):
+ node_name = self.items[0]
+
+ storage_type = self._checkStringVariable("storage_type", None)
+ if not storage_type:
+ raise http.HttpBadRequest("Missing the required 'storage_type'"
+ " parameter")
+
+ output_fields = self._checkStringVariable("output_fields", None)
+ if not output_fields:
+ raise http.HttpBadRequest("Missing the required 'output_fields'"
+ " parameter")
+
+ op = opcodes.OpNodeQueryStorage(nodes=[node_name],
+ storage_type=storage_type,
+ output_fields=output_fields.split(","))
+ return baserlib.SubmitJob([op])
+
+
+class R_2_nodes_name_storage_modify(baserlib.R_Generic):
+ """/2/nodes/[node_name]/storage/modify resource.
+
+ """
+ def PUT(self):
+ node_name = self.items[0]
+
+ storage_type = self._checkStringVariable("storage_type", None)
+ if not storage_type:
+ raise http.HttpBadRequest("Missing the required 'storage_type'"
+ " parameter")
+
+ name = self._checkStringVariable("name", None)
+ if not name:
+ raise http.HttpBadRequest("Missing the required 'name'"
+ " parameter")
+
+ changes = {}
+
+ if "allocatable" in self.queryargs:
+ changes[constants.SF_ALLOCATABLE] = \
+ bool(self._checkIntVariable("allocatable", default=1))
+
+ op = opcodes.OpNodeModifyStorage(node_name=node_name,
+ storage_type=storage_type,
+ name=name,
+ changes=changes)
+ return baserlib.SubmitJob([op])
+
+
+class R_2_nodes_name_storage_repair(baserlib.R_Generic):
+ """/2/nodes/[node_name]/storage/repair resource.
+
+ """
+ def PUT(self):
+ node_name = self.items[0]
+
+ storage_type = self._checkStringVariable("storage_type", None)
+ if not storage_type:
+ raise http.HttpBadRequest("Missing the required 'storage_type'"
+ " parameter")
+
+ name = self._checkStringVariable("name", None)
+ if not name:
+ raise http.HttpBadRequest("Missing the required 'name'"
+ " parameter")
+
+ op = opcodes.OpRepairNodeStorage(node_name=node_name,
+ storage_type=storage_type,
+ name=name)
+ return baserlib.SubmitJob([op])
+
+
+def _ParseCreateGroupRequest(data, dry_run):
+ """Parses a request for creating a node group.
+
+ @rtype: L{opcodes.OpGroupAdd}
+ @return: Group creation opcode
+
+ """
+ override = {
+ "dry_run": dry_run,
+ }
+
+ rename = {
+ "name": "group_name",
+ }
+
+ return baserlib.FillOpcode(opcodes.OpGroupAdd, data, override,
+ rename=rename)
+
+
+class R_2_groups(baserlib.R_Generic):
+ """/2/groups resource.
+
+ """
+ def GET(self):
+ """Returns a list of all node groups.
+
+ """
+ client = baserlib.GetClient()
+
+ if self.useBulk():
+ bulkdata = client.QueryGroups([], G_FIELDS, False)
+ return baserlib.MapBulkFields(bulkdata, G_FIELDS)
+ else:
+ data = client.QueryGroups([], ["name"], False)
+ groupnames = [row[0] for row in data]
+ return baserlib.BuildUriList(groupnames, "/2/groups/%s",
+ uri_fields=("name", "uri"))
+
+ def POST(self):
+ """Create a node group.
+
+ @return: a job id
+
+ """
+ baserlib.CheckType(self.request_body, dict, "Body contents")
+ op = _ParseCreateGroupRequest(self.request_body, self.dryRun())
+ return baserlib.SubmitJob([op])
+
+
+class R_2_groups_name(baserlib.R_Generic):
+ """/2/groups/[group_name] resource.
+
+ """
+ def GET(self):
+ """Send information about a node group.
+
+ """
+ group_name = self.items[0]
+ client = baserlib.GetClient()
+
+ result = baserlib.HandleItemQueryErrors(client.QueryGroups,
+ names=[group_name], fields=G_FIELDS,
+ use_locking=self.useLocking())
+
+ return baserlib.MapFields(G_FIELDS, result[0])
+
+ def DELETE(self):
+ """Delete a node group.
+
+ """
+ op = opcodes.OpGroupRemove(group_name=self.items[0],
+ dry_run=bool(self.dryRun()))
+
+ return baserlib.SubmitJob([op])
+
+
+def _ParseModifyGroupRequest(name, data):
+ """Parses a request for modifying a node group.
+
+ @rtype: L{opcodes.OpGroupSetParams}
+ @return: Group modify opcode
+
+ """
+ return baserlib.FillOpcode(opcodes.OpGroupSetParams, data, {
+ "group_name": name,
+ })
+
+
+class R_2_groups_name_modify(baserlib.R_Generic):
+ """/2/groups/[group_name]/modify resource.
+
+ """
+ def PUT(self):
+ """Changes some parameters of node group.
+
+ @return: a job id
+
+ """
+ baserlib.CheckType(self.request_body, dict, "Body contents")
+
+ op = _ParseModifyGroupRequest(self.items[0], self.request_body)
+
+ return baserlib.SubmitJob([op])
+
+
+def _ParseRenameGroupRequest(name, data, dry_run):
+ """Parses a request for renaming a node group.
+
+ @type name: string
+ @param name: name of the node group to rename
+ @type data: dict
+ @param data: the body received by the rename request
+ @type dry_run: bool
+ @param dry_run: whether to perform a dry run
+
+ @rtype: L{opcodes.OpGroupRename}
+ @return: Node group rename opcode
+
+ """
+ return baserlib.FillOpcode(opcodes.OpGroupRename, data, {
+ "group_name": name,
+ "dry_run": dry_run,
+ })
+
+
+class R_2_groups_name_rename(baserlib.R_Generic):
+ """/2/groups/[group_name]/rename resource.
+
+ """
+ def PUT(self):
+ """Changes the name of a node group.
+
+ @return: a job id
+
+ """
+ baserlib.CheckType(self.request_body, dict, "Body contents")
+ op = _ParseRenameGroupRequest(self.items[0], self.request_body,
+ self.dryRun())
+ return baserlib.SubmitJob([op])
+
+
+class R_2_groups_name_assign_nodes(baserlib.R_Generic):
+ """/2/groups/[group_name]/assign-nodes resource.
+
+ """
+ def PUT(self):
+ """Assigns nodes to a group.
+
+ @return: a job id
+
+ """
+ op = baserlib.FillOpcode(opcodes.OpGroupAssignNodes, self.request_body, {
+ "group_name": self.items[0],
+ "dry_run": self.dryRun(),
+ "force": self.useForce(),
+ })
+
+ return baserlib.SubmitJob([op])
+
+
+def _ParseInstanceCreateRequestVersion1(data, dry_run):
+ """Parses an instance creation request version 1.
+
+ @rtype: L{opcodes.OpInstanceCreate}
+ @return: Instance creation opcode
+
+ """
+ override = {
+ "dry_run": dry_run,
+ }
+
+ rename = {
+ "os": "os_type",
+ "name": "instance_name",
+ }
+
+ return baserlib.FillOpcode(opcodes.OpInstanceCreate, data, override,
+ rename=rename)
+
+
+class R_2_instances(baserlib.R_Generic):
+ """/2/instances resource.
+
+ """
+ def GET(self):
+ """Returns a list of all available instances.
+
+ """
+ client = baserlib.GetClient()