Package ganeti :: Package rapi :: Module rlib2
[hide private]
[frames] | no frames]

Module rlib2

source code

Remote API resource implementations.

PUT or POST?

According to RFC2616 the main difference between PUT and POST is that POST can create new resources but PUT can only create the resource the URI was pointing to on the PUT request.

In the context of this module POST on ``/2/instances`` to change an existing entity is legitimate, while PUT would not be. PUT creates a new entity (e.g. a new instance) with a name specified in the request.

Quoting from RFC2616, section 9.6:

 The fundamental difference between the POST and PUT requests is reflected in
 the different meaning of the Request-URI. The URI in a POST request
 identifies the resource that will handle the enclosed entity. That resource
 might be a data-accepting process, a gateway to some other protocol, or a
 separate entity that accepts annotations. In contrast, the URI in a PUT
 request identifies the entity enclosed with the request -- the user agent
 knows what URI is intended and the server MUST NOT attempt to apply the
 request to some other resource. If the server desires that the request be
 applied to a different URI, it MUST send a 301 (Moved Permanently) response;
 the user agent MAY then make its own decision regarding whether or not to
 redirect the request.

So when adding new methods, if they are operating on the URI entity itself, PUT should be prefered over POST.

Classes [hide private]
  R_root
/ resource.
  R_2
/2 resource.
  R_version
/version resource.
  R_2_info
/2/info resource.
  R_2_features
/2/features resource.
  R_2_os
/2/os resource.
  R_2_redist_config
/2/redistribute-config resource.
  R_2_cluster_modify
/2/modify resource.
  R_2_filters
/2/filters resource.
  R_2_filters_uuid
/2/filters/[filter_uuid] resource.
  R_2_jobs
/2/jobs resource.
  R_2_jobs_id
/2/jobs/[job_id] resource.
  R_2_jobs_id_wait
/2/jobs/[job_id]/wait resource.
  R_2_nodes
/2/nodes resource.
  R_2_nodes_name
/2/nodes/[node_name] resource.
  R_2_nodes_name_powercycle
/2/nodes/[node_name]/powercycle resource.
  R_2_nodes_name_role
/2/nodes/[node_name]/role resource.
  R_2_nodes_name_evacuate
/2/nodes/[node_name]/evacuate resource.
  R_2_nodes_name_migrate
/2/nodes/[node_name]/migrate resource.
  R_2_nodes_name_modify
/2/nodes/[node_name]/modify resource.
  R_2_nodes_name_storage
/2/nodes/[node_name]/storage resource.
  R_2_nodes_name_storage_modify
/2/nodes/[node_name]/storage/modify resource.
  R_2_nodes_name_storage_repair
/2/nodes/[node_name]/storage/repair resource.
  R_2_networks
/2/networks resource.
  R_2_networks_name
/2/networks/[network_name] resource.
  R_2_networks_name_connect
/2/networks/[network_name]/connect resource.
  R_2_networks_name_disconnect
/2/networks/[network_name]/disconnect resource.
  R_2_networks_name_modify
/2/networks/[network_name]/modify resource.
  R_2_groups
/2/groups resource.
  R_2_groups_name
/2/groups/[group_name] resource.
  R_2_groups_name_modify
/2/groups/[group_name]/modify resource.
  R_2_groups_name_rename
/2/groups/[group_name]/rename resource.
  R_2_groups_name_assign_nodes
/2/groups/[group_name]/assign-nodes resource.
  R_2_instances
/2/instances resource.
  R_2_instances_multi_alloc
/2/instances-multi-alloc resource.
  R_2_instances_name
/2/instances/[instance_name] resource.
  R_2_instances_name_info
/2/instances/[instance_name]/info resource.
  R_2_instances_name_reboot
/2/instances/[instance_name]/reboot resource.
  R_2_instances_name_startup
/2/instances/[instance_name]/startup resource.
  R_2_instances_name_shutdown
/2/instances/[instance_name]/shutdown resource.
  R_2_instances_name_reinstall
/2/instances/[instance_name]/reinstall resource.
  R_2_instances_name_replace_disks
/2/instances/[instance_name]/replace-disks resource.
  R_2_instances_name_activate_disks
/2/instances/[instance_name]/activate-disks resource.
  R_2_instances_name_deactivate_disks
/2/instances/[instance_name]/deactivate-disks resource.
  R_2_instances_name_recreate_disks
/2/instances/[instance_name]/recreate-disks resource.
  R_2_instances_name_prepare_export
/2/instances/[instance_name]/prepare-export resource.
  R_2_instances_name_export
/2/instances/[instance_name]/export resource.
  R_2_instances_name_migrate
/2/instances/[instance_name]/migrate resource.
  R_2_instances_name_failover
/2/instances/[instance_name]/failover resource.
  R_2_instances_name_rename
/2/instances/[instance_name]/rename resource.
  R_2_instances_name_modify
/2/instances/[instance_name]/modify resource.
  R_2_instances_name_disk_grow
/2/instances/[instance_name]/disk/[disk_index]/grow resource.
  R_2_instances_name_console
/2/instances/[instance_name]/console resource.
  R_2_query
/2/query/[resource] resource.
  R_2_query_fields
/2/query/[resource]/fields resource.
  _R_Tags
Quasiclass for tagging resources.
  R_2_instances_name_tags
/2/instances/[instance_name]/tags resource.
  R_2_nodes_name_tags
/2/nodes/[node_name]/tags resource.
  R_2_groups_name_tags
/2/groups/[group_name]/tags resource.
  R_2_networks_name_tags
/2/networks/[network_name]/tags resource.
  R_2_tags
/2/tags resource.
Functions [hide private]
 
_UpdateBeparams(inst)
Updates the beparams dict of inst to support the memory field.
source code
 
checkFilterParameters(data)
Checks and extracts filter rule parameters from a request body.
source code
 
_ConvertUsbDevices(data)
Convert in place the usb_devices string to the proper format.
source code
 
_ParseInstanceReinstallRequest(name, data)
Parses a request for reinstalling an instance.
source code
list of string
_GetQueryFields(args)
Tries to extract fields query parameter.
source code
list of string
_SplitQueryFields(fields)
Splits fields as given for a query request.
source code
Variables [hide private]
  _COMMON_FIELDS = ["ctime", "mtime", "uuid", "serial_no", "tags"]
  I_FIELDS = ["name", "admin_state", "os", "pnode", "snodes", "d...
  N_FIELDS = ["name", "offline", "master_candidate", "drained", ...
  NET_FIELDS = ["name", "network", "gateway", "network6", "gatew...
  G_FIELDS = ["alloc_policy", "name", "node_cnt", "node_list", "...
  FILTER_RULE_FIELDS = ["watermark", "priority", "predicates", "...
  J_FIELDS_BULK = ["id", "ops", "status", "summary", "opstatus",...
  J_FIELDS = J_FIELDS_BULK+ ["oplog", "opresult",]
  _NR_DRAINED = "drained"
  _NR_MASTER_CANDIDATE = "master-candidate"
  _NR_MASTER = "master"
  _NR_OFFLINE = "offline"
  _NR_REGULAR = "regular"
  _NR_MAP = {constants.NR_MASTER: _NR_MASTER, constants.NR_MCAND...
  _REQ_DATA_VERSION = "__version__"
  _INST_CREATE_REQV1 = "instance-create-reqv1"
  _INST_REINSTALL_REQV1 = "instance-reinstall-reqv1"
  _NODE_MIGRATE_REQV1 = "node-migrate-reqv1"
  _NODE_EVAC_RES1 = "node-evac-res1"
  ALL_FEATURES = compat.UniqueFrozenset([_INST_CREATE_REQV1, _IN...
  _WFJC_TIMEOUT = 10

Imports: opcodes, objects, http, constants, cli, rapi, ht, compat, baserlib


Function Details [hide private]

_UpdateBeparams(inst)

source code 

Updates the beparams dict of inst to support the memory field.

Parameters:
  • inst - Inst dict
Returns:
Updated inst dict

checkFilterParameters(data)

source code 

Checks and extracts filter rule parameters from a request body.

Returns:
the checked parameters: (priority, predicates, action).

_ConvertUsbDevices(data)

source code 

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.

_GetQueryFields(args)

source code 

Tries to extract fields query parameter.

Parameters:
  • args (dictionary)
Returns: list of string
Raises:

_SplitQueryFields(fields)

source code 

Splits fields as given for a query request.

Parameters:
  • fields (string)
Returns: list of string

Variables Details [hide private]

I_FIELDS

Value:
["name", "admin_state", "os", "pnode", "snodes", "disk_template", "nic\
.ips", "nic.macs", "nic.modes", "nic.uuids", "nic.names", "nic.links",\
 "nic.networks", "nic.networks.names", "nic.bridges", "network_port", \
"disk.sizes", "disk.spindles", "disk_usage", "disk.uuids", "disk.names\
", "beparams", "hvparams", "oper_state", "oper_ram", "oper_vcpus", "st\
atus", "custom_hvparams", "custom_beparams", "custom_nicparams",]+ _CO\
MMON_FIELDS

N_FIELDS

Value:
["name", "offline", "master_candidate", "drained", "dtotal", "dfree", \
"sptotal", "spfree", "mtotal", "mnode", "mfree", "pinst_cnt", "sinst_c\
nt", "ctotal", "cnos", "cnodes", "csockets", "pip", "sip", "role", "pi\
nst_list", "sinst_list", "master_capable", "vm_capable", "ndparams", "\
group.uuid",]+ _COMMON_FIELDS

NET_FIELDS

Value:
["name", "network", "gateway", "network6", "gateway6", "mac_prefix", "\
free_count", "reserved_count", "map", "group_list", "inst_list", "exte\
rnal_reservations",]+ _COMMON_FIELDS

G_FIELDS

Value:
["alloc_policy", "name", "node_cnt", "node_list", "ipolicy", "custom_i\
policy", "diskparams", "custom_diskparams", "ndparams", "custom_ndpara\
ms",]+ _COMMON_FIELDS

FILTER_RULE_FIELDS

Value:
["watermark", "priority", "predicates", "action", "reason_trail", "uui\
d",]

J_FIELDS_BULK

Value:
["id", "ops", "status", "summary", "opstatus", "received_ts", "start_t\
s", "end_ts",]

_NR_MAP

Value:
{constants.NR_MASTER: _NR_MASTER, constants.NR_MCANDIDATE: _NR_MASTER_\
CANDIDATE, constants.NR_DRAINED: _NR_DRAINED, constants.NR_OFFLINE: _N\
R_OFFLINE, constants.NR_REGULAR: _NR_REGULAR,}

ALL_FEATURES

Value:
compat.UniqueFrozenset([_INST_CREATE_REQV1, _INST_REINSTALL_REQV1, _NO\
DE_MIGRATE_REQV1, _NODE_EVAC_RES1,])