def generate_network_metadata(cls, cluster): metadata = super(NeutronNetworkTemplateSerializer70, cls).generate_network_metadata(cluster) for node_data in metadata['nodes'].values(): node = Node.get_by_uid(node_data['uid']) network_roles = cls._get_network_roles(node) ip_per_ep = cls._get_endpoint_to_ip_mapping(node) node_data['network_roles'] = {} for role, ep in network_roles.items(): node_data['network_roles'][role] = ip_per_ep.get(ep) return metadata
def create_node(self, api=False, exclude=None, expect_http=201, expected_error=None, **kwargs): # TODO(alekseyk) Simplify 'interfaces' and 'mac' manipulation logic metadata = kwargs.get("meta") default_metadata = self.default_metadata() if metadata: default_metadata.update(metadata) meta_ifaces = "interfaces" in metadata mac = kwargs.get("mac", self.generate_random_mac()) if default_metadata["interfaces"]: default_metadata["interfaces"][0]["mac"] = mac if not metadata or not meta_ifaces: for iface in default_metadata["interfaces"][1:]: if "mac" in iface: iface["mac"] = self.generate_random_mac() node_data = {"mac": mac, "status": "discover", "ip": "10.20.0.130", "meta": default_metadata} if kwargs: meta = kwargs.pop("meta", None) node_data.update(kwargs) if meta: kwargs["meta"] = meta if exclude and isinstance(exclude, list): for ex in exclude: try: del node_data[ex] except KeyError as err: logger.warning(err) if api: resp = self.app.post( reverse("NodeCollectionHandler"), jsonutils.dumps(node_data), headers=self.default_headers, expect_errors=True, ) self.tester.assertEqual(resp.status_code, expect_http, resp.body) if expected_error: self.tester.assertEqual(resp.json_body["message"], expected_error) if str(expect_http)[0] != "2": return None self.tester.assertEqual(resp.status_code, expect_http) node = resp.json_body node_db = Node.get_by_uid(node["id"]) if "interfaces" not in node_data["meta"] or not node_data["meta"]["interfaces"]: self._set_interfaces_if_not_set_in_meta(node_db.id, kwargs.get("meta", None)) self.nodes.append(node_db) else: node = Node.create(node_data) db().commit() self.nodes.append(node) return node
def create_node(self, api=False, exclude=None, expect_http=201, expect_message=None, **kwargs): #TODO(alekseyk) Simplify 'interfaces' and 'mac' manipulation logic metadata = kwargs.get('meta') default_metadata = self.default_metadata() if metadata: default_metadata.update(metadata) meta_ifaces = 'interfaces' in metadata mac = kwargs.get('mac', self.generate_random_mac()) if default_metadata['interfaces']: default_metadata['interfaces'][0]['mac'] = mac if not metadata or not meta_ifaces: for iface in default_metadata['interfaces'][1:]: if 'mac' in iface: iface['mac'] = self.generate_random_mac() node_data = { 'mac': mac, 'status': 'discover', 'meta': default_metadata } if kwargs: meta = kwargs.pop('meta', None) node_data.update(kwargs) if meta: kwargs['meta'] = meta if exclude and isinstance(exclude, list): for ex in exclude: try: del node_data[ex] except KeyError as err: logger.warning(err) if api: resp = self.app.post(reverse('NodeCollectionHandler'), json.dumps(node_data), headers=self.default_headers, expect_errors=True) self.tester.assertEquals(resp.status_code, expect_http) if expect_message: self.tester.assertEquals(resp.body, expect_message) if str(expect_http)[0] != "2": return None self.tester.assertEquals(resp.status_code, expect_http) node = json.loads(resp.body) node_db = Node.get_by_uid(node['id']) if 'interfaces' not in node_data['meta'] \ or not node_data['meta']['interfaces']: self._set_interfaces_if_not_set_in_meta( node_db.id, kwargs.get('meta', None)) self.nodes.append(node_db) else: node = Node.create(node_data) db().commit() self.nodes.append(node) return node
def create_node( self, api=False, exclude=None, expect_http=201, expect_message=None, **kwargs): #TODO(alekseyk) Simplify 'interfaces' and 'mac' manipulation logic metadata = kwargs.get('meta') default_metadata = self.default_metadata() if metadata: default_metadata.update(metadata) meta_ifaces = 'interfaces' in metadata mac = kwargs.get('mac', self.generate_random_mac()) if default_metadata['interfaces']: default_metadata['interfaces'][0]['mac'] = mac if not metadata or not meta_ifaces: for iface in default_metadata['interfaces'][1:]: if 'mac' in iface: iface['mac'] = self.generate_random_mac() node_data = { 'mac': mac, 'status': 'discover', 'meta': default_metadata } if kwargs: meta = kwargs.pop('meta', None) node_data.update(kwargs) if meta: kwargs['meta'] = meta if exclude and isinstance(exclude, list): for ex in exclude: try: del node_data[ex] except KeyError as err: logger.warning(err) if api: resp = self.app.post( reverse('NodeCollectionHandler'), jsonutils.dumps(node_data), headers=self.default_headers, expect_errors=True ) self.tester.assertEqual(resp.status_code, expect_http) if expect_message: self.tester.assertEqual(resp.body, expect_message) if str(expect_http)[0] != "2": return None self.tester.assertEqual(resp.status_code, expect_http) node = resp.json_body node_db = Node.get_by_uid(node['id']) if 'interfaces' not in node_data['meta'] \ or not node_data['meta']['interfaces']: self._set_interfaces_if_not_set_in_meta( node_db.id, kwargs.get('meta', None)) self.nodes.append(node_db) else: node = Node.create(node_data) db().commit() self.nodes.append(node) return node