from PLC.Filter import Filter
from PLC.Debug import profile
from PLC.Table import Row, Table
-from PLC.Interfaces import Interface, Interfaces
+from PLC.NodeTypes import NodeTypes
from PLC.BootStates import BootStates
+from PLC.Interfaces import Interface, Interfaces
def valid_hostname(hostname):
# 1. Each part begins and ends with a letter or number.
related_fields = {
'interfaces': [Mixed(Parameter(int, "Interface identifier"),
Filter(Interface.fields))],
- 'nodegroups': [Mixed(Parameter(int, "NodeGroup identifier"),
- Parameter(str, "NodeGroup name"))],
'conf_files': [Parameter(int, "ConfFile identifier")],
'slices': [Mixed(Parameter(int, "Slice identifier"),
Parameter(str, "Slice name"))],
'slices_whitelist': [Mixed(Parameter(int, "Slice identifier"),
Parameter(str, "Slice name"))]
}
- view_name = "view_nodes"
+
view_tags_name = "view_node_tags"
- tags = {
- # regular
- 'arch': Parameter(str, "node/config", ro=True),
- 'deployment': Parameter(str, "node/operation"),
- # dummynet
- }
+ # tags are used by the Add/Get/Update methods to expose tags
+ # this is initialized here and updated by the accessors factory
+ tags = { }
def validate_hostname(self, hostname):
if not valid_hostname(hostname):
return hostname
+ def validate_node_type(self, node_type):
+ node_types = [row['node_type'] for row in NodeTypes(self.api)]
+ if node_type not in node_types:
+ raise PLCInvalidArgument, "Invalid node type %r"%node_type
+ return node_type
+
def validate_boot_state(self, boot_state):
boot_states = [row['boot_state'] for row in BootStates(self.api)]
if boot_state not in boot_states:
- raise PLCInvalidArgument, "Invalid boot state"
-
+ raise PLCInvalidArgument, "Invalid boot state %r"%boot_state
return boot_state
validate_date_created = Row.validate_timestamp
node_filter = Filter(Node.fields, {'node_id': ints, 'hostname': strs})
sql += " AND (%s) %s" % node_filter.sql(api, "OR")
elif isinstance(node_filter, dict):
- node_filter = Filter(Node.fields, node_filter)
+ allowed_fields=dict(Node.fields.items()+Node.tags.items())
+ node_filter = Filter(allowed_fields, node_filter)
sql += " AND (%s) %s" % node_filter.sql(api, "AND")
elif isinstance (node_filter, StringTypes):
node_filter = Filter(Node.fields, {'hostname':[node_filter]})