from PLC.Auth import PasswordAuth
from PLC.Sites import Site, Sites
+can_update = lambda (field, value): field in \
+ ['line1', 'line2', 'line3',
+ 'city', 'state', 'postalcode', 'country']
+
class AddAddress(Method):
"""
Adds a new address to a site. Fields specified in
roles = ['admin', 'pi']
- can_update = lambda (field, value): field in \
- ['line1', 'line2', 'line3',
- 'city', 'state', 'postalcode', 'country']
update_fields = dict(filter(can_update, Address.fields.items()))
accepts = [
returns = Parameter(int, 'New address_id (> 0) if successful')
def call(self, auth, site_id_or_login_base, address_fields = {}):
- if filter(lambda field: field not in self.update_fields, address_fields):
- raise PLCInvalidArgument, "Invalid field specified"
+ address_fields = dict(filter(can_update, address_fields.items()))
# Get associated site details
sites = Sites(self.api, [site_id_or_login_base]).values()
from PLC.AddressTypes import AddressType, AddressTypes
from PLC.Auth import PasswordAuth
+can_update = lambda (field, value): field in ['description']
+
class AddAddressType(Method):
"""
Adds a new address type. Fields specified in address_type_fields
roles = ['admin']
- can_update = lambda (field, value): field in ['description']
update_fields = dict(filter(can_update, AddressType.fields.items()))
accepts = [
returns = Parameter(int, 'New address_type_id (> 0) if successful')
def call(self, auth, name, address_type_fields = {}):
+ address_type_fields = dict(filter(can_update, address_type_fields.items()))
address_type = AddressType(self.api, address_type_fields)
address_type['name'] = name
address_type.sync()
from PLC.Attributes import Attribute, Attributes
from PLC.Auth import PasswordAuth
+can_update = lambda (field, value): field in \
+ ['description', 'min_role_id']
+
class AddAttribute(Method):
"""
- Adds a new type of attribute. Any fields specified in optional_vals
- are used, otherwise defaults are used.
+ Adds a new type of attribute. Any fields specified in
+ attribute_fields are used, otherwise defaults are used.
Returns the new attribute_id (> 0) if successful, faults otherwise.
"""
roles = ['admin']
- can_update = lambda (field, value): field in \
- ['description', 'min_role_id']
update_fields = dict(filter(can_update, Attribute.fields.items()))
accepts = [
returns = Parameter(int, 'New attribute_id (> 0) if successful')
- def call(self, auth, name, optional_vals = {}):
- if filter(lambda field: field not in self.update_fields, optional_vals):
- raise PLCInvalidArgument, "Invalid field specified"
-
- attribute = Attribute(self.api, optional_vals)
+ def call(self, auth, name, attribute_fields = {}):
+ attribute_fields = dict(filter(can_update, attribute_fields.items()))
+ attribute = Attribute(self.api, attribute_fields)
attribute['name'] = name
attribute.sync()
from PLC.Sites import Site, Sites
from PLC.Auth import PasswordAuth
+can_update = lambda (field, value): field in \
+ ['boot_state', 'model', 'version']
+
class AddNode(Method):
"""
- Adds a new node. Any values specified in optional_vals are used,
+ Adds a new node. Any values specified in node_fields are used,
otherwise defaults are used.
PIs and techs may only add nodes to their own sites. Admins may
roles = ['admin', 'pi', 'tech']
- can_update = lambda (field, value): field in \
- ['boot_state', 'model', 'version']
update_fields = dict(filter(can_update, Node.fields.items()))
accepts = [
returns = Parameter(int, 'New node_id (> 0) if successful')
- def call(self, auth, site_id_or_login_base, hostname, optional_vals = {}):
- if filter(lambda field: field not in self.update_fields, optional_vals):
- raise PLCInvalidArgument, "Invalid fields specified"
-
+ def call(self, auth, site_id_or_login_base, hostname, node_fields = {}):
+ node_fields = dict(filter(can_update, node_fields.items()))
+
# Get site information
sites = Sites(self.api, [site_id_or_login_base])
if not sites:
else:
assert self.caller['person_id'] in site['person_ids']
- node = Node(self.api, optional_vals)
+ node = Node(self.api, node_fields)
node['hostname'] = hostname
node['site_id'] = site['site_id']
node.sync()
from PLC.NodeNetworks import NodeNetwork, NodeNetworks
from PLC.Auth import PasswordAuth
+can_update = lambda (field, value): field in \
+ ['ip', 'mac', 'gateway', 'network', 'broadcast', 'netmask',
+ 'dns1', 'dns2', 'hostname', 'bwlimit', 'is_primary']
+
class AddNodeNetwork(Method):
"""
Adds a new network for a node. Any values specified in
- optional_vals are used, otherwise defaults are used. Acceptable
+ nodenetwork_fields 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,
+ specified in nodenetwork_fields. If type is dhcp, these parameters,
even if specified, are ignored.
PIs and techs may only add networks to their own nodes. ins may
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 = [
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"
+ def call(self, auth, node_id, method, type, nodenetwork_fields = {}):
+ nodenetwork_fields = dict(filter(can_update, nodenetwork_fields.items()))
# Check if node exists
nodes = Nodes(self.api, [node_id]).values()
raise PLCPermissionDenied, "Not allowed to add node network for specified node"
# Add node network
- nodenetwork = NodeNetwork(self.api, optional_vals)
+ nodenetwork = NodeNetwork(self.api, nodenetwork_fields)
nodenetwork['node_id'] = node_id
nodenetwork['method'] = method
nodenetwork['type'] = type
from PLC.Auth import PasswordAuth
from PLC.Sites import Site, Sites
+can_update = lambda (field, value): field in \
+ ['hostname', 'ip', 'protocol',
+ 'username', 'password',
+ 'model', 'notes']
+
class AddPCU(Method):
"""
Adds a new power control unit (PCU) to the specified site. Any
- fields specified in optional_vals are used, otherwise defaults are
+ fields specified in pcu_fields are used, otherwise defaults are
used.
PIs and technical contacts may only add PCUs to their own sites.
roles = ['admin', 'pi', 'tech']
- can_update = lambda (field, value): field in \
- ['hostname', 'ip', 'protocol',
- 'username', 'password',
- 'model', 'notes']
update_fields = dict(filter(can_update, PCU.fields.items()))
accepts = [
returns = Parameter(int, 'New pcu_id (> 0) if successful')
- def call(self, auth, site_id_or_login_base, optional_vals = {}):
- if filter(lambda field: field not in self.update_fields, optional_vals):
- raise PLCInvalidArgument, "Invalid field specified"
+ def call(self, auth, site_id_or_login_base, pcu_fields = {}):
+ pcu_fields = dict(filter(can_update, pcu_fields.items()))
# Get associated site details
sites = Sites(self.api, [site_id_or_login_base]).values()
if site['site_id'] not in self.caller['site_ids']:
raise PLCPermissionDenied, "Not allowed to add a PCU to that site"
- pcu = PCU(self.api, optional_vals)
+ pcu = PCU(self.api, pcu_fields)
pcu['site_id'] = site['site_id']
pcu.sync()
from PLC.Sites import Site, Sites
from PLC.Auth import PasswordAuth
+can_update = lambda (field, value): field in \
+ ['is_public', 'latitude', 'longitude', 'url',
+ 'organization_id', 'ext_consortium_id']
+
class AddSite(Method):
"""
Adds a new site, and creates a node group for that site. Any
roles = ['admin']
- can_update = lambda (field, value): field in \
- ['is_public', 'latitude', 'longitude', 'url',
- 'organization_id', 'ext_consortium_id']
update_fields = dict(filter(can_update, Site.fields.items()))
accepts = [
returns = Parameter(int, 'New site_id (> 0) if successful')
- def call(self, auth, name, abbreviated_name, login_base, optional_vals = {}):
- if filter(lambda field: field not in self.update_fields, optional_vals):
- raise PLCInvalidArgument, "Invalid field specified"
-
- site = Site(self.api, optional_vals)
+ def call(self, auth, name, abbreviated_name, login_base, site_fields = {}):
+ site_fields = dict(filter(can_update, site_fields.items()))
+ site = Site(self.api, site_fields)
site['name'] = name
site['abbreviated_name'] = abbreviated_name
site['login_base'] = login_base
from PLC.Addresses import Address, Addresses
from PLC.Auth import PasswordAuth
+can_update = lambda (field, value): field in \
+ ['line1', 'line2', 'line3',
+ 'city', 'state', 'postalcode', 'country']
+
class UpdateAddress(Method):
"""
Updates the parameters of an existing address with the values in
roles = ['admin', 'pi']
- can_update = lambda (field, value): field in \
- ['line1', 'line2', 'line3',
- 'city', 'state', 'postalcode', 'country']
update_fields = dict(filter(can_update, Address.fields.items()))
accepts = [
returns = Parameter(int, '1 if successful')
def call(self, auth, address_id, address_fields):
- if filter(lambda field: field not in self.update_fields, address_fields):
- raise PLCInvalidArgument, "Invalid field specified"
+ address_fields = dict(filter(can_update, address_fields.items()))
# Get associated address details
addresses = Addresses(self.api, [address_id]).values()
from PLC.AddressTypes import AddressType, AddressTypes
from PLC.Auth import PasswordAuth
+can_update = lambda (field, value): field in ['name', 'description']
+
class UpdateAddressType(Method):
"""
Updates the parameters of an existing address type with the values
roles = ['admin']
- can_update = lambda (field, value): field in ['name', 'description']
update_fields = dict(filter(can_update, AddressType.fields.items()))
accepts = [
returns = Parameter(int, '1 if successful')
def call(self, auth, address_type_id_or_name, address_type_fields):
- if filter(lambda field: field not in self.update_fields, address_type_fields):
- raise PLCInvalidArgument, "Invalid field specified"
+ address_type_fields = dict(filter(can_update, address_type_fields.items()))
address_types = AddressTypes(self.api, [address_type_id_or_name]).values()
if not address_types:
from PLC.Keys import Key, Keys
from PLC.Auth import PasswordAuth
+can_update = lambda (field, value): field in \
+ ['key_type', 'key']
+
class UpdateKey(Method):
"""
Updates the parameters of an existing key with the values in
roles = ['admin', 'pi', 'tech', 'user']
- can_update = lambda (field, value): field in \
- ['key_type', 'key']
update_fields = dict(filter(can_update, Key.fields.items()))
accepts = [
returns = Parameter(int, '1 if successful')
def call(self, auth, key_id, key_fields):
- # Make sure only valid fields are specified
- if filter(lambda field: field not in self.update_fields, key_fields):
- raise PLCInvalidArgument, "Invalid field specified"
+ key_fields = dict(filter(can_update, key_fields.items()))
# Get key information
keys = Keys(self.api, [key_id]).values()
from PLC.Nodes import Node, Nodes
from PLC.Auth import PasswordAuth
+can_update = lambda (field, value): field in \
+ ['hostname', 'boot_state', 'model', 'version']
+
class UpdateNode(Method):
"""
- Updates a node. Only the fields specified in update_fields are
+ Updates a node. Only the fields specified in node_fields are
updated, all other fields are left untouched.
To remove a value without setting a new one in its place (for
roles = ['admin', 'pi', 'tech']
- can_update = lambda (field, value): field in \
- ['hostname', 'boot_state', 'model', 'version']
update_fields = dict(filter(can_update, Node.fields.items()))
accepts = [
returns = Parameter(int, '1 if successful')
- def call(self, auth, node_id_or_hostname, update_fields):
- if filter(lambda field: field not in self.update_fields, update_fields):
- raise PLCInvalidArgument, "Invalid field specified"
+ def call(self, auth, node_id_or_hostname, node_fields):
+ node_fields = dict(filter(can_update, node_fields.items()))
# Get account information
nodes = Nodes(self.api, [node_id_or_hostname])
if node['site_id'] not in self.caller['site_ids']:
raise PLCPermissionDenied, "Not allowed to delete nodes from specified site"
- node.update(update_fields)
+ node.update(node_fields)
node.sync()
return 1
-
from PLC.Faults import *
from PLC.Method import Method
from PLC.Parameter import Parameter, Mixed
from PLC.NodeNetworks import NodeNetwork, NodeNetworks
from PLC.Auth import PasswordAuth
+can_update = lambda (field, value): field not in \
+ ['nodenetwork_id']
+
class UpdateNodeNetwork(Method):
"""
Updates an existing node network. Any values specified in update_fields
roles = ['admin', 'pi', 'tech']
- can_update = lambda (field, value): field not in \
- ['nodenetwork_id']
update_fields = dict(filter(can_update, NodeNetwork.fields.items()))
accepts = [
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"
+ def call(self, auth, nodenetwork_id_or_hostname, nodenetwork_fields):
+ nodenetwork_fields = dict(filter(can_update, nodenetwork_fields.items()))
# Get node network information
nodenetworks = NodeNetworks(self.api, [nodenetwork_id_or_hostname]).values()
raise PLCPermissionDenied, "Not allowed to update node network"
# Update node network
- nodenetwork.update(update_fields)
+ nodenetwork.update(nodenetwork_fields)
nodenetwork.sync()
return 1
from PLC.PCUs import PCU, PCUs
from PLC.Auth import PasswordAuth
+can_update = lambda (field, value): field not in \
+ ['pcu_id', 'site_id']
+
class UpdatePCU(Method):
"""
Updates the parameters of an existing PCU with the values in
roles = ['admin', 'pi', 'tech']
- can_update = lambda (field, value): field not in \
- ['pcu_id', 'site_id']
update_fields = dict(filter(can_update, PCU.fields.items()))
accepts = [
returns = Parameter(int, '1 if successful')
def call(self, auth, pcu_id, pcu_fields):
- # Make sure only valid fields are specified
- if filter(lambda field: field not in self.update_fields, pcu_fields):
- raise PLCInvalidArgument, "Invalid field specified"
+ pcu_fields = dict(filter(can_update, pcu_fields.items()))
# Get associated PCU details
pcus = PCUs(self.api, [pcu_id]).values()
from PLC.Sites import Site, Sites
from PLC.Auth import PasswordAuth
+can_update = lambda (field, value): field in \
+ ['name', 'abbreviated_name',
+ 'is_public', 'latitude', 'longitude', 'url',
+ 'max_slices', 'max_slivers']
+
class UpdateSite(Method):
"""
Updates a site. Only the fields specified in update_fields are
roles = ['admin', 'pi']
- can_update = lambda (field, value): field in \
- ['name', 'abbreviated_name',
- 'is_public', 'latitude', 'longitude', 'url',
- 'max_slices', 'max_slivers']
update_fields = dict(filter(can_update, Site.fields.items()))
accepts = [
returns = Parameter(int, '1 if successful')
- def call(self, auth, site_id_or_login_base, update_fields):
- # Check for invalid fields
- if filter(lambda field: field not in self.update_fields, update_fields):
- raise PLCInvalidArgument, "Invalid field specified"
+ def call(self, auth, site_id_or_login_base, site_fields):
+ site_fields = dict(filter(can_update, site_fields.items()))
# Get site information
sites = Sites(self.api, [site_id_or_login_base])
if site['site_id'] not in self.caller['site_ids']:
raise PLCPermissionDenied, "Not allowed to modify specified site"
- if 'max_slices' or 'max_slivers' in update_fields:
+ if 'max_slices' or 'max_slivers' in site_fields:
raise PLCInvalidArgument, "Only admins can update max_slices and max_slivers"
- site.update(update_fields)
+ site.update(site_fields)
site.sync()
return 1