X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FAddNodeNetwork.py;h=6e24bce7d67e59d153e8224da933c38080e27d7c;hb=90a9c8342a4f5bcf02e6407dcf4ed1975ad15baf;hp=16e3782d82339cfe30c49d77e425a8113b711a27;hpb=f8e0c71d96dce99eff25e5bb6bdf941468e897a2;p=plcapi.git diff --git a/PLC/Methods/AddNodeNetwork.py b/PLC/Methods/AddNodeNetwork.py index 16e3782..6e24bce 100644 --- a/PLC/Methods/AddNodeNetwork.py +++ b/PLC/Methods/AddNodeNetwork.py @@ -3,23 +3,24 @@ 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.Auth import Auth -can_update = lambda (field, value): field in \ - ['ip', 'mac', 'gateway', 'network', 'broadcast', 'netmask', - 'dns1', 'dns2', 'hostname', 'bwlimit', 'is_primary'] +can_update = lambda (field, value): field not in ['nodenetwork_id', 'node_id'] class AddNodeNetwork(Method): """ + Adds a new network for a node. Any values specified in - 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 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 + nodenetwork_fields are used, otherwise defaults are + used. Acceptable values for method may be retrieved via + GetNetworkMethods. Acceptable values for type may be retrieved via + GetNetworkTypes. + + If type is static, ip, gateway, network, broadcast, netmask, and + dns1 must all be 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. Admins may add networks to any node. Returns the new nodenetwork_id (> 0) if successful, faults otherwise. @@ -27,27 +28,23 @@ class AddNodeNetwork(Method): roles = ['admin', 'pi', 'tech'] - update_fields = dict(filter(can_update, NodeNetwork.fields.items())) + nodenetwork_fields = dict(filter(can_update, NodeNetwork.fields.items())) accepts = [ - PasswordAuth(), - Node.fields['node_id'], - NodeNetwork.fields['method'], - NodeNetwork.fields['type'], - update_fields + Auth(), + Mixed(Node.fields['node_id'], + Node.fields['hostname']), + nodenetwork_fields ] returns = Parameter(int, 'New nodenetwork_id (> 0) if successful') - event_type = 'Add' - object_type = 'NodeNetwork' - object_ids = [] - - def call(self, auth, node_id, method, type, nodenetwork_fields = {}): + + def call(self, auth, node_id_or_hostname, nodenetwork_fields): nodenetwork_fields = dict(filter(can_update, nodenetwork_fields.items())) # Check if node exists - nodes = Nodes(self.api, [node_id]).values() + nodes = Nodes(self.api, [node_id_or_hostname]) if not nodes: raise PLCInvalidArgument, "No such node" node = nodes[0] @@ -63,10 +60,14 @@ class AddNodeNetwork(Method): # Add node network nodenetwork = NodeNetwork(self.api, nodenetwork_fields) - nodenetwork['node_id'] = node_id - nodenetwork['method'] = method - nodenetwork['type'] = type + nodenetwork['node_id'] = node['node_id'] + # if this is the first node network, make it primary + if not node['nodenetwork_ids']: + nodenetwork['is_primary'] = True nodenetwork.sync() - self.object_ids = [nodenetwork['nodenetwork_id']] + + # Logging variables + self.object_ids = [node['node_id'], nodenetwork['nodenetwork_id']] + self.messgage = "Node network %d added" % nodenetwork['nodenetwork_id'] return nodenetwork['nodenetwork_id']