-from PLC.Faults import *
-from PLC.Method import Method
-from PLC.Parameter import Parameter, Mixed
-from PLC.Nodes import Node, Nodes
-from PLC.NodeNetworks import NodeNetwork, NodeNetworks
-from PLC.Auth import PasswordAuth
+from PLC.Methods.AddNodeNetwork import AddNodeNetwork
-class AdmAddNodeNetwork(Method):
+class AdmAddNodeNetwork(AddNodeNetwork):
"""
- Adds a new network for a node. Any values specified in
- optional_vals are used, otherwise defaults are used. Acceptable
- values for method are dhcp, static, proxy, tap, and
- ipmi. Acceptable value for type is ipv4. If type is static, ip,
- gateway, network, broadcast, netmask, and dns1 must all be
- specified in optional_vals. If type is dhcp, these parameters,
- even if specified, are ignored.
-
- PIs and techs may only add networks to their own nodes. Admins may
- add networks to any node.
-
- Returns the new nodenetwork_id (> 0) if successful, faults otherwise.
+ Deprecated. See AddNodeNetwork.
"""
- roles = ['admin', 'pi', 'tech']
-
- can_update = lambda (field, value): field in \
- ['ip', 'mac', 'gateway', 'network', 'broadcast', 'netmask',
- 'dns1', 'dns2', 'hostname', 'bwlimit', 'is_primary']
- update_fields = dict(filter(can_update, NodeNetwork.fields.items()))
-
- accepts = [
- PasswordAuth(),
- Node.fields['node_id'],
- NodeNetwork.fields['method'],
- NodeNetwork.fields['type'],
- update_fields
- ]
-
- returns = Parameter(int, 'New nodenetwork_id (> 0) if successful')
-
- def call(self, auth, node_id, method, type, optional_vals = {}):
- if filter(lambda field: field not in self.update_fields, optional_vals):
- raise PLCInvalidArgument, "Invalid fields specified"
-
- # Check if node exists
- nodes = Nodes(self.api, [node_id]).values()
- if not nodes:
- raise PLCInvalidArgument, "No such node"
- node = nodes[0]
-
- # Authenticated function
- assert self.caller is not None
-
- # If we are not an admin, make sure that the caller is a
- # member of the site where the node exists.
- if 'admin' not in self.caller['roles']:
- if node['site_id'] not in self.caller['site_ids']:
- raise PLCPermissionDenied, "Not allowed to add node network for specified node"
-
- # Add node network
- nodenetwork = NodeNetwork(self.api, optional_vals)
- nodenetwork['node_id'] = node_id
- nodenetwork['method'] = method
- nodenetwork['type'] = type
- nodenetwork.sync()
-
- return nodenetwork['nodenetwork_id']
+ status = "deprecated"
-from PLC.Faults import *
-from PLC.Method import Method
-from PLC.Parameter import Parameter, Mixed
-from PLC.NodeGroups import NodeGroup, NodeGroups
-from PLC.Nodes import Node, Nodes
-from PLC.Auth import PasswordAuth
+from PLC.Methods.AddNodeToNodeGroup import AddNodeToNodeGroup
-class AdmAddNodeToNodeGroup(Method):
+class AdmAddNodeToNodeGroup(AddNodeToNodeGroup):
"""
- Add a node to the specified node group. If the node is
- already a member of the nodegroup, no errors are returned.
-
- Returns 1 if successful, faults otherwise.
+ Deprecated. See AddNodeToNodeGroup.
"""
- roles = ['admin']
-
- accepts = [
- PasswordAuth(),
- Mixed(NodeGroup.fields['nodegroup_id'],
- NodeGroup.fields['name']),
- Mixed(Node.fields['node_id'],
- Node.fields['hostname'])
- ]
-
- returns = Parameter(int, '1 if successful')
-
- def call(self, auth, nodegroup_id_or_name, node_id_or_hostname):
- # Get node info
- nodes = Nodes(self.api, [node_id_or_hostname])
- if not nodes:
- raise PLCInvalidArgument, "No such node"
- node = nodes.values()[0]
-
- # Get nodegroup info
- nodegroups = NodeGroups(self.api, [nodegroup_id_or_name])
- if not nodegroups:
- raise PLCInvalidArgument, "No such nodegroup"
-
- nodegroup = nodegroups.values()[0]
-
- # add node to nodegroup
- if node['node_id'] not in nodegroup['node_ids']:
- nodegroup.add_node(node)
-
- return 1
+ status = "deprecated"
-from PLC.Method import Method
-from PLC.Parameter import Parameter, Mixed
-from PLC.Auth import PasswordAuth
+from PLC.Methods.AuthCheck import AuthCheck
-class AdmAuthCheck(Method):
+class AdmAuthCheck(AuthCheck):
"""
- Returns 1 if the user authenticated successfully, faults
- otherwise.
+ Deprecated. See AuthCheck.
"""
- roles = ['admin', 'pi', 'user', 'tech']
- accepts = [PasswordAuth()]
- returns = Parameter(int, '1 if successful')
-
- def call(self, auth):
- return 1
+ status = "deprecated"
-from PLC.Faults import *
-from PLC.Method import Method
-from PLC.Parameter import Parameter, Mixed
-from PLC.Auth import PasswordAuth
-from PLC.Nodes import Node, Nodes
-from PLC.NodeNetworks import NodeNetwork, NodeNetworks
+from PLC.Methods.DeleteNodeNetwork import DeleteNodeNetwork
-class AdmDeleteNodeNetwork(Method):
+class AdmDeleteNodeNetwork(DeleteNodeNetwork):
"""
- Delete an existing Node Network. Nodenetwork_id must be associated to
- node_id and not be associated with a different node.
-
- Admins may delete any node network. PIs and techs can only delete
- nodenetworks for thier nodes.
-
- Returns 1 if successful, faults otherwise.
+ Deprecated. See DeleteNodeNetwork.
"""
- roles = ['admin', 'pi', 'tech']
-
- accepts = [
- PasswordAuth(),
- Mixed(Node.fields['node_id'],
- Node.fields['hostname']),
- Mixed(NodeNetwork.fields['nodenetwork_id'],
- NodeNetwork.fields['hostname'])
- ]
-
- returns = Parameter(int, '1 if successful')
-
- def call(self, auth, node_id_or_hostname, nodenetwork_id_or_hostname):
- # Get node network information
- nodenetworks = NodeNetworks(self.api, [nodenetwork_id_or_hostname]).values()
- if not nodenetworks:
- raise PLCInvalidArgument, "No such node network"
- nodenetwork = nodenetworks[0]
-
- # Get node information
- nodes = Nodes(self.api, [node_id_or_hostname]).values()
- if not nodes:
- raise PLCInvalidArgument, "No such node"
- node = nodes[0]
-
- # Check if node network is associated with specified node
- if node['node_id'] != nodenetwork['node_id'] or \
- nodenetwork['nodenetwork_id'] not in node['nodenetwork_ids']:
- raise PLCInvalidArgument, "Node network not associated with node"
-
- # Authenticated functino
- assert self.caller is not None
-
- # If we are not an admin, make sure that the caller is a
- # member of the site at which the node is located.
- if 'admin' not in self.caller['roles']:
- if node['site_id'] not in self.caller['site_ids']:
- raise PLCPermissionDenied, "Not allowed to delete this node network"
-
- nodenetwork.delete()
-
- return 1
+ status = "deprecated"
-from PLC.Faults import *
-from PLC.Method import Method
-from PLC.Parameter import Parameter, Mixed
-from PLC.NodeNetworks import NodeNetwork, NodeNetworks
-from PLC.Nodes import Node, Nodes
-from PLC.Auth import PasswordAuth
+from PLC.Methods.GetNodeNetworks import GetNodeNetworks
-class AdmGetAllNodeNetworks(Method):
+class AdmGetAllNodeNetworks(GetNodeNetworks):
"""
- Returns all the networks this node is connected to, as an array of
- structs.
+ Deprecated. See GetNodeNetworks.
"""
- roles = ['admin', 'pi', 'user', 'tech']
-
- accepts = [
- PasswordAuth(),
- Mixed(Node.fields['node_id'],
- Node.fields['hostname'])
- ]
-
- returns = [NodeNetwork.fields]
-
- def call(self, auth, node_id_or_hostname):
- # Authenticated function
- assert self.caller is not None
-
- # Get node information
- nodes = Nodes(self.api, [node_id_or_hostname]).values()
- if not nodes:
- raise PLCInvalidArgument, "No such node"
- node = nodes[0]
-
- # Get node networks for this node
- if node['nodenetwork_ids']:
- nodenetworks = NodeNetworks(self.api, node['nodenetwork_ids']).values()
- else:
- nodenetworks = []
-
- # Filter out undesired or None fields (XML-RPC cannot marshal
- # None) and turn each node into a real dict.
- valid_return_fields_only = lambda (key, value): value is not None
- nodenetworks = [dict(filter(valid_return_fields_only, nodenetwork.items())) \
- for nodenetwork in nodenetworks]
-
- return nodenetworks
+ status = "deprecated"
class AdmGetNodeGroupNodes(Method):
"""
+ Deprecated. See GetNodeGroups.
+
Returns a list of node_ids for the node group specified.
"""
+ status = "deprecated"
+
roles = ['admin', 'pi', 'user', 'tech']
accepts = [
-from PLC.Faults import *
-from PLC.Method import Method
-from PLC.Parameter import Parameter, Mixed
-from PLC.Auth import PasswordAuth
-from PLC.NodeGroups import NodeGroup, NodeGroups
+from PLC.Methods.GetNodeGroups import GetNodeGroups
-class AdmGetNodeGroups(Method):
+class AdmGetNodeGroups(GetNodeGroups):
"""
- Returns an array of structs containing details about all node
- groups. If nodegroup_id_or_name_list is specified, only the
- specified node groups will be queried.
+ Deprecated. See GetNodeGroups.
"""
- roles = ['admin', 'pi', 'user', 'tech']
-
- accepts = [
- PasswordAuth(),
- [Mixed(NodeGroup.fields['nodegroup_id'],
- NodeGroup.fields['name'])]
- ]
-
- returns = [NodeGroup.fields]
-
- def call(self, auth, nodegroup_id_or_name_list = None):
- # Get node group details
- nodegroups = NodeGroups(self.api, nodegroup_id_or_name_list).values()
-
- # Filter out undesired or None fields (XML-RPC cannot marshal
- # None) and turn each nodegroup into a real dict.
- valid_return_fields_only = lambda (key, value): value is not None
- nodegroups = [dict(filter(valid_return_fields_only, nodegroup.items())) \
- for nodegroup in nodegroups]
-
- return nodegroups
+ status = "deprecated"
-import os
+from PLC.Methods.GetNodes import GetNodes
-from PLC.Faults import *
-from PLC.Method import Method
-from PLC.Parameter import Parameter, Mixed
-from PLC.Nodes import Node, Nodes
-from PLC.Auth import PasswordAuth
-
-class AdmGetNodes(Method):
+class AdmGetNodes(GetNodes):
"""
- Return an array of dictionaries containing details about the
- specified nodes.
-
- If return_fields is specified, only the specified fields will be
- returned. Only admins may retrieve certain fields. Otherwise, the
- default set of fields returned is:
-
+ Deprecated. See GetNodes.
"""
- roles = ['admin', 'pi', 'user', 'tech']
-
- accepts = [
- PasswordAuth(),
- [Mixed(Node.fields['node_id'],
- Node.fields['hostname'])],
- Parameter([str], 'List of fields to return')
- ]
-
- returns = [Node.fields]
-
- def __init__(self, *args, **kwds):
- Method.__init__(self, *args, **kwds)
- # Update documentation with list of default fields returned
- self.__doc__ += os.linesep.join(Node.fields.keys())
-
- def call(self, auth, node_id_or_hostname_list = None, return_fields = None):
- # Authenticated function
- assert self.caller is not None
-
- valid_fields = Node.fields.keys()
-
- # Remove admin only fields
- if 'admin' not in self.caller['roles']:
- for key in ['boot_nonce', 'key', 'session', 'root_person_ids']:
- valid_fields.remove(key)
-
- # Make sure that only valid fields are specified
- if return_fields is None:
- return_fields = valid_fields
- elif filter(lambda field: field not in valid_fields, return_fields):
- raise PLCInvalidArgument, "Invalid return field specified"
-
- # Get node information
- nodes = Nodes(self.api, node_id_or_hostname_list).values()
-
- # Filter out undesired or None fields (XML-RPC cannot marshal
- # None) and turn each node into a real dict.
- valid_return_fields_only = lambda (key, value): \
- key in return_fields and value is not None
- nodes = [dict(filter(valid_return_fields_only, node.items())) \
- for node in nodes]
-
- return nodes
+ status = "deprecated"
class AdmGetSiteNodes(Method):
"""
+ Deprecated. See GetSites.
+
Return a dictionary containing a list of node_ids for each of the
sites specified.
details about themselves and others at their sites.
"""
+ status = "deprecated"
+
roles = ['admin', 'pi', 'user', 'tech']
accepts = [
class AdmGetSitePersons(Method):
"""
+ Deprecated. See GetSites.
+
Return a list of person_ids for the site specified.
PIs may only retrieve the person_ids of accounts at their
site. Admins may retrieve the person_ids of accounts at any site.
"""
+ status = "deprecated"
+
roles = ['admin', 'pi']
accepts = [
-import os
+from PLC.Methods.GetSites import GetSites
-from PLC.Method import Method
-from PLC.Parameter import Parameter, Mixed
-from PLC.Auth import PasswordAuth
-from PLC.Sites import Site, Sites
-
-class AdmGetSites(Method):
+class AdmGetSites(GetSites):
"""
- Return an array of structs containing details about all sites. If
- site_id_list is specified, only the specified sites will be
- queried.
-
- If return_fields is specified, only the specified fields will be
- returned, if set. Otherwise, the default set of fields returned is:
-
+ Deprecated. See GetSites.
"""
- roles = ['admin', 'pi', 'user', 'tech']
-
- accepts = [
- PasswordAuth(),
- [Mixed(Site.fields['site_id'],
- Site.fields['login_base'])],
- Parameter([str], 'List of fields to return')
- ]
-
- returns = [Site.fields]
-
- def __init__(self, *args, **kwds):
- Method.__init__(self, *args, **kwds)
- # Update documentation with list of default fields returned
- self.__doc__ += os.linesep.join(Site.fields.keys())
-
- def call(self, auth, site_id_or_login_base_list = None, return_fields = None):
- # Make sure that only valid fields are specified
- if return_fields is None:
- return_fields = Site.fields
- elif filter(lambda field: field not in Site.fields, return_fields):
- raise PLCInvalidArgument, "Invalid return field specified"
-
- # Get site information
- sites = Sites(self.api, site_id_or_login_base_list)
-
- # Filter out undesired or None fields (XML-RPC cannot marshal
- # None) and turn each site into a real dict.
- valid_return_fields_only = lambda (key, value): \
- key in return_fields and value is not None
- sites = [dict(filter(valid_return_fields_only, site.items())) \
- for site in sites.values()]
-
- return sites
+ status = "deprecated"
-from PLC.Faults import *
-from PLC.Method import Method
-from PLC.Parameter import Parameter, Mixed
-from PLC.NodeGroups import NodeGroup, NodeGroups
-from PLC.Nodes import Node, Nodes
-from PLC.Auth import PasswordAuth
+from PLC.Methods.DeleteNodeFromNodeGroup import DeleteNodeFromNodeGroup
-class AdmRemoveNodeFromNodeGroup(Method):
+class AdmRemoveNodeFromNodeGroup(DeleteNodeFromNodeGroup):
"""
- Removes a node from the specified node group.
-
- Returns 1 if successful, faults otherwise.
+ Deprecated. See DeleteNodeFromNodeGroup.
"""
- roles = ['admin']
-
- accepts = [
- PasswordAuth(),
- Mixed(NodeGroup.fields['nodegroup_id'],
- NodeGroup.fields['name']),
- Mixed(Node.fields['node_id'],
- Node.fields['hostname'])
- ]
-
- returns = Parameter(int, '1 if successful')
-
- def call(self, auth, nodegroup_id_or_name, node_id_or_hostname):
- # Get node info
- nodes = Nodes(self.api, [node_id_or_hostname])
- if not nodes:
- raise PLCInvalidArgument, "No such node"
-
- node = nodes.values()[0]
-
- # Get nodegroup info
- nodegroups = NodeGroups(self.api, [nodegroup_id_or_name])
- if not nodegroups:
- raise PLCInvalidArgument, "No such nodegroup"
-
- nodegroup = nodegroups.values()[0]
-
- # Remove node from nodegroup
- if node['node_id'] in nodegroup['node_ids']:
- nodegroup.remove_node(node)
-
- return 1
+ status = "deprecated"
+from PLC.Methods.UpdateNodeNetwork import UpdateNodeNetwork
-from PLC.Faults import *
-from PLC.Method import Method
-from PLC.Parameter import Parameter, Mixed
-from PLC.Nodes import Node, Nodes
-from PLC.NodeNetworks import NodeNetwork, NodeNetworks
-from PLC.Auth import PasswordAuth
-
-class AdmUpdateNodeNetwork(Method):
+class AdmUpdateNodeNetwork(UpdateNodeNetwork):
"""
- Updates an existing node network. Any values specified in update_fields
- are used, otherwise defaults are used. Acceptable values for method are
- dhcp and static. If type is static, the parameter update_fields must
- be present and ip, gateway, network, broadcast, netmask, and dns1 must
- all be specified. If type is dhcp, these parameters, even if
- specified, are ignored.
-
- PIs and techs may only update networks associated with their own
- nodes. Admins may update any node network.
-
- Returns 1 if successful, faults otherwise.
+ Deprecated. See UpdateNodeNetwork.
"""
- roles = ['admin', 'pi', 'tech']
-
- can_update = lambda (field, value): field not in \
- ['nodenetwork_id']
- update_fields = dict(filter(can_update, NodeNetwork.fields.items()))
-
- accepts = [
- PasswordAuth(),
- Mixed(NodeNetwork.fields['nodenetwork_id'],
- NodeNetwork.fields['hostname']),
- update_fields
- ]
-
- returns = Parameter(int, '1 if successful')
-
- def call(self, auth, nodenetwork_id_or_hostname, update_fields):
- # Check for invalid fields
- if filter(lambda field: field not in self.update_fields, update_fields):
- raise PLCInvalidArgument, "Invalid fields specified"
-
- # XML-RPC cannot marshal None, so we need special values to
- # represent "unset".
- for key, value in update_fields.iteritems():
- if value == -1 or value == "null":
- if key in ['method', 'type', 'mac', 'ip', 'bwlimit']:
- raise PLCInvalidArgument, "%s cannot be unset" % key
- update_fields[key] = None
-
- # Get node network information
- nodenetworks = NodeNetworks(self.api, [nodenetwork_id_or_hostname]).values()
- if not nodenetworks:
- raise PLCInvalidArgument, "No such node network"
-
- nodenetwork = nodenetworks[0]
-
- # Authenticated function
- assert self.caller is not None
-
- # If we are not an admin, make sure that the caller is a
- # member of the site where the node exists.
- if 'admin' not in self.caller['roles']:
- nodes = Nodes(self.api, [nodenetwork['node_id']]).values()
- if not nodes:
- raise PLCPermissionDenied, "Node network is not associated with a node"
- node = nodes[0]
- if node['site_id'] not in self.caller['site_ids']:
- raise PLCPermissionDenied, "Not allowed to update node network"
-
- # Update node network
- nodenetwork.update(update_fields)
- nodenetwork.sync()
-
- return 1
+ status = "deprecated"