# Copyright 2017-present Open Networking Foundation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import json from xosapi.orm import ORMWrapper, register_convenience_wrapper from xosapi.convenience.service import ORMWrapperService class ORMWrapperVRouterService(ORMWrapperService): def get_gateways(self): gateways = [] aps = self.addresspools.all() for ap in aps: gateways.append({"gateway_ip": ap.gateway_ip, "gateway_mac": ap.gateway_mac}) return gateways register_convenience_wrapper("VRouterService", ORMWrapperVRouterService)
# Copyright 2017-present Open Networking Foundation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from __future__ import absolute_import from xosapi.orm import ORMWrapper, register_convenience_wrapper class ORMWrapperTag(ORMWrapper): def get_generic_foreignkeys(self): return [{ "name": "content_object", "content_type": "content_type", "id": "object_id", }] register_convenience_wrapper("Tag", ORMWrapperTag)
def get_onu_sn_from_openflow(self, dp_id, port_no): """Return the ONU serial number from logical_device informations example usage: volt = VOLTService.objects.first() sn = volt.get_onu_from_openflow("of:0000000ce2314000", 2) # BRCM1234 Arguments: dp_id {string} -- The openflow id of the OLT device port_no {int} -- The openflow port id (UNI Port) Returns: string -- ONU Serial Number """ log.debug("Searching ONUDevice for %s:%s" % (dp_id, port_no)) try: olt = self.stub.OLTDevice.objects.get(dp_id=dp_id) uni_ports = self.stub.UNIPort.objects.filter(port_no=port_no) onu = [o.onu_device for o in uni_ports if o.onu_device.pon_port.olt_device.id == olt.id][0] return onu.serial_number except IndexError: log.error("Can't find ONU for %s:%s" % (dp_id, port_no)) except Exception: log.exception("Error while finding ONUDevice for %s:%s" % (dp_id, port_no)) register_convenience_wrapper("VOLTService", ORMWrapperVOLTService)
# Copyright 2017-present Open Networking Foundation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from __future__ import absolute_import from xosapi.orm import ORMWrapper, register_convenience_wrapper class ORMWrapperController(ORMWrapper): @property def auth_url_v3(self): if self.auth_url and self.auth_url[-1] == "/": return "{}/v3/".format("/".join(self.auth_url.split("/")[:-2])) else: return "{}/v3/".format("/".join(self.auth_url.split("/")[:-1])) register_convenience_wrapper("Controller", ORMWrapperController)
@property def netbits(self): # return number of bits in the network portion of the cidr if self.cidr: parts = self.cidr.split("/") if len(parts) == 2: return int(parts[1].strip()) return None # Use for tenant_for_instance_id # TODO: These should be reimplemented using real database models def get_attribute(self, name, default=None): if self.service_specific_attribute: attributes = json.loads(self.service_specific_attribute) else: attributes = {} return attributes.get(name, default) def set_attribute(self, name, value): if self.service_specific_attribute: attributes = json.loads(self.service_specific_attribute) else: attributes = {} attributes[name] = value self.service_specific_attribute = json.dumps(attributes) register_convenience_wrapper("VRouterTenant", ORMWrapperVRouterTenant)
@property def netbits(self): # return number of bits in the network portion of the cidr if self.cidr: parts = self.cidr.split("/") if len(parts) == 2: return int(parts[1].strip()) return None # Use for tenant_for_instance_id # TODO: These should be reimplemented using real database models def get_attribute(self, name, default=None): if self.service_specific_attribute: attributes = json.loads(self.service_specific_attribute) else: attributes = {} return attributes.get(name, default) def set_attribute(self, name, value): if self.service_specific_attribute: attributes = json.loads(self.service_specific_attribute) else: attributes = {} attributes[name] = value self.service_specific_attribute = json.dumps(attributes) register_convenience_wrapper("AddressManagerServiceInstance", ORMWrapperAddressManagerServiceInstance)
# return an address on nat-net def get_network_ip(self, pattern): for ns in self.ports.all(): if pattern in ns.network.name.lower(): return ns.ip return None # return an address that the synchronizer can use to SSH to the instance def get_ssh_ip(self): # first look specifically for a management_local network for ns in self.ports.all(): if ns.network.template and ns.network.template.vtn_kind=="MANAGEMENT_LOCAL": return ns.ip # for compatibility, now look for any management network management=self.get_network_ip("management") if management: return management # if all else fails, look for nat-net (for OpenCloud?) return self.get_network_ip("nat") @property def controller(self): if self.node and self.node.site_deployment: return self.node.site_deployment.controller else: return None register_convenience_wrapper("Instance", ORMWrapperInstance)
"ServiceInstance %d linked to vsg %s does not exist" % (int(tags[0].value), self)) return service_instances[0].leaf_model.public_ip else: raise Exception("no vm_vrouter_tenant tag for instance %s" % self.instance) @property def wan_vm_mac(self): tags = self.stub.Tag.objects.filter( name="vm_vrouter_tenant", object_id=self.instance.id, content_type=self.instance.self_content_type_id) if tags: service_instances = self.stub.ServiceInstance.objects.filter( id=int(tags[0].value)) if not service_instances: raise Exception( "ServiceInstance %d linked to vsg %s does not exist" % (int(tags[0].value), self)) return service_instances[0].leaf_model.public_mac else: raise Exception("no vm_vrouter_tenant tag for instance %s" % self.instance) register_convenience_wrapper("VSGTenant", ORMWrapperVSGServiceInstance) # DEPRECATED register_convenience_wrapper("VSGServiceInstance", ORMWrapperVSGServiceInstance)
# Copyright 2017-present Open Networking Foundation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from __future__ import absolute_import from xosapi.convenience.serviceinstance import ORMWrapperServiceInstance from xosapi.orm import register_convenience_wrapper class ORMWrapperONOSApp(ORMWrapperServiceInstance): pass register_convenience_wrapper("ONOSApp", ORMWrapperONOSApp)
# 'serial_number': 'BRCM1234', # 'of_dpid': 'of:109299321' # } from xosapi.orm import register_convenience_wrapper from xosapi.convenience.serviceinstance import ORMWrapperServiceInstance import logging as log class ORMWrapperHippieOSSService(ORMWrapperServiceInstance): def validate_onu(self, event): log.info("validating ONU %s" % event["serial_number"], event=event) try: oss_si = self.stub.HippieOSSServiceInstance.objects.get( serial_number=event["serial_number"]) oss_si.no_sync = False log.debug("Found existing HippieOSSServiceInstance", si=oss_si) except IndexError: # create an HippieOSSServiceInstance, the validation will be triggered in the corresponding sync step oss_si = self.stub.HippieOSSServiceInstance( serial_number=event["serial_number"], of_dpid=event["of_dpid"]) log.debug("Created new HippieOSSServiceInstance", si=oss_si) oss_si.save(always_update_timestamp=True) register_convenience_wrapper("HippieOSSService", ORMWrapperHippieOSSService)
# Copyright 2017-present Open Networking Foundation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from xosapi.orm import ORMWrapper, register_convenience_wrapper class ORMWrapperTag(ORMWrapper): def get_generic_foreignkeys(self): return [{"name": "content_object", "content_type": "content_type", "id": "object_id"}] register_convenience_wrapper("Tag", ORMWrapperTag)
s_tag = subscriber_si.get_westbound_service_instance_properties( "s_tag", include_self=True) switch_datapath_id = subscriber_si.get_westbound_service_instance_properties( "switch_datapath_id", include_self=True) source_port = subscriber_si.get_westbound_service_instance_properties( "switch_port", include_self=True) if (s_tag is None): raise Exception("Subscriber ServiceInstance %s s-tag is None" % subscriber_si.id) if (not switch_datapath_id): raise Exception( "Subscriber ServiceInstance %s switch_datapath_id is unset" % subscriber_si.id) if (source_port is None): raise Exception( "Subscriber ServiceInstance %s switch_port is None" % subscriber_si.id) s_tag = int(s_tag) source_port = int(source_port) return (s_tag, switch_datapath_id, source_port) register_convenience_wrapper("FabricCrossconnectService", ORMWrapperFabricCrossconnectService)
# Copyright 2017-present Open Networking Foundation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from xosapi.orm import ORMWrapper, register_convenience_wrapper class ORMWrapperPrivilege(ORMWrapper): pass register_convenience_wrapper("Privilege", ORMWrapperPrivilege)
# Copyright 2017-present Open Networking Foundation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from xosapi.orm import ORMWrapper, register_convenience_wrapper class ORMWrapperPrivilege(ORMWrapper): pass register_convenience_wrapper("Privilege", ORMWrapperPrivilege)
@property def wan_container_gateway_mac(self): return self.get_address_service_instance_field("gateway_mac", None) @property def wan_vm_ip(self): tags = self.stub.Tag.objects.filter(name="vm_vrouter_tenant", object_id=self.instance.id, content_type=self.instance.self_content_type_id) if tags: service_instances = self.stub.ServiceInstance.objects.filter(id=int(tags[0].value)) if not service_instances: raise Exception("ServiceInstance %d linked to vsg %s does not exist" % (int(tags[0].value), self)) return service_instances[0].leaf_model.public_ip else: raise Exception("no vm_vrouter_tenant tag for instance %s" % self.instance) @property def wan_vm_mac(self): tags = self.stub.Tag.objects.filter(name="vm_vrouter_tenant", object_id=self.instance.id, content_type=self.instance.self_content_type_id) if tags: service_instances = self.stub.ServiceInstance.objects.filter(id=int(tags[0].value)) if not service_instances: raise Exception("ServiceInstance %d linked to vsg %s does not exist" % (int(tags[0].value), self)) return service_instances[0].leaf_model.public_mac else: raise Exception("no vm_vrouter_tenant tag for instance %s" % self.instance) register_convenience_wrapper("VSGTenant", ORMWrapperVSGServiceInstance) # DEPRECATED register_convenience_wrapper("VSGServiceInstance", ORMWrapperVSGServiceInstance)
if addr in inuse_ips: # This may have happened if someone re-ran the tosca # recipe and 'refilled' the AddressPool while some addresses # were still in use. continue inuse_ips.insert(0, addr) ap.inuse = " ".join(inuse_ips) ap.addresses = " ".join(avail_ips) return addr return None def put_address(self, addr): ap = self addresses = ap.addresses or "" parts = addresses.split() if addr not in parts: parts.insert(0, addr) ap.addresses = " ".join(parts) inuse = ap.inuse or "" parts = inuse.split() if addr in parts: parts.remove(addr) ap.inuse = " ".join(parts) register_convenience_wrapper("AddressPool", ORMWrapperAddressPool)
# See the License for the specific language governing permissions and # limitations under the License. from xosapi.orm import register_convenience_wrapper from xosapi.convenience.service import ORMWrapperService class ORMWrapperOnosService(ORMWrapperService): """ Calling convention. Assume the subscribing service does approximately (needs some checks to see if the methods exist before calling them) the following in its model_policy: if not eastbound_service.validate_links(self): eastbound_service.acquire_service_instance(self) """ def acquire_service_instance(self, subscriber_service_instance): """ Never acquire a ServiceInstance on the ONOS Service, those are ONOS apps, simply return true """ return True def validate_links(self, subscriber_service_instance): """ In the case of the ONOS service there are no links between ServiceInstances and ONOSApps, so alway return an empty list """ return [] register_convenience_wrapper("ONOSService", ORMWrapperOnosService)
# You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from __future__ import absolute_import from xosapi.orm import (ORMLocalObjectManager, ORMWrapper, register_convenience_wrapper) class ORMWrapperSlice(ORMWrapper): # TODO: this looks to be incorrect @property def slicename(self): return "%s_%s" % (self.site.login_base, self.name) # networks - emulates the ManyToMany from Slice to Network via NetworkSlice @property def networks(self): idList = [x.network.id for x in self.networkslices.all()] return ORMLocalObjectManager(self.stub, "Network", idList, False) register_convenience_wrapper("Slice", ORMWrapperSlice)
# Copyright 2017-present Open Networking Foundation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import hashlib import json from xosapi.orm import ORMWrapper, register_convenience_wrapper class ORMWrapperUser(ORMWrapper): @property def remote_password(self): return hashlib.md5(self.password).hexdigest()[:12] register_convenience_wrapper("User", ORMWrapperUser)
# Copyright 2017-present Open Networking Foundation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import hashlib from xosapi.orm import ORMWrapper, register_convenience_wrapper class ORMWrapperUser(ORMWrapper): @property def remote_password(self): return hashlib.md5(self.password).hexdigest()[:12] register_convenience_wrapper("User", ORMWrapperUser)
# cast from ServiceInstance to VOLTTenant volts = self.stub.VOLTTenant.objects.filter(id = link.provider_service_instance.id) if volts: return volts[0] return None sync_attributes = ("firewall_enable", "firewall_rules", "url_filter_enable", "url_filter_rules", "cdn_enable", "uplink_speed", "downlink_speed", "enable_uverse", "status") # figure out what to do about "devices"... is it still needed? def get_attribute(self, name, default=None): if self.service_specific_attribute: attributes = json.loads(self.service_specific_attribute) else: attributes = {} return attributes.get(name, default) @property def devices(self): return self.get_attribute("devices", []) register_convenience_wrapper("CordSubscriberRoot", ORMWrapperCordSubscriberRoot)
import json from xosapi.orm import ORMWrapper, register_convenience_wrapper class ORMWrapperService(ORMWrapper): @property def serviceattribute_dict(self): attrs = {} for attr in self.serviceattributes.all(): attrs[attr.name] = attr.value return attrs def get_composable_networks(self): SUPPORTED_VTN_SERVCOMP_KINDS = ['VSG','PRIVATE'] nets = [] for slice in self.slices.all(): for net in slice.networks.all(): if (net.template.vtn_kind not in SUPPORTED_VTN_SERVCOMP_KINDS) or (net.owner != slice): continue if not net.controllernetworks.exists(): continue nets.append(net) return nets register_convenience_wrapper("Service", ORMWrapperService)
import json from xosapi.orm import ORMWrapper, register_convenience_wrapper class ORMWrapperPort(ORMWrapper): def get_parameters(self): parameter_dict = {} for param in self.stub.NetworkParameter.objects.filter(content_type=self.self_content_type_id, object_id=self.id): parameter_dict[param.parameter.name] = param.value return parameter_dict register_convenience_wrapper("Port", ORMWrapperPort)
# Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from xosapi.orm import ORMWrapper, register_convenience_wrapper class ORMWrapperVOLTTenant(ORMWrapper): @property def vcpe(self): links = self.stub.ServiceInstanceLink.objects.filter(subscriber_service_instance_id = self.id) for link in links: # cast from ServiceInstance to VSGTenant vsgs = self.stub.VSGTenant.objects.filter(id = link.provider_service_instance.id) if vsgs: return vsgs[0] return None @property def subscriber(self): links = self.stub.ServiceInstanceLink.objects.filter(provider_service_instance_id = self.id) for link in links: subs = self.stub.CordSubscriberRoot.objects.filter(id=link.subscriber_service_instance_id) if subs: return subs[0] return None register_convenience_wrapper("VOLTTenant", ORMWrapperVOLTTenant)
# Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from xosapi.orm import ORMWrapper, ORMLocalObjectManager, register_convenience_wrapper class ORMWrapperNetwork(ORMWrapper): # slices- emulates the ManyToMany from Slice to Network via NetworkSlice @property def slices(self): idList = [x.slice.id for x in self.networkslices.all()] return ORMLocalObjectManager(self.stub, "Slice", idList, False) # instances- emulates the ManyToMany from Network to Instance via Port @property def instances(self): idList = [x.instance.id for x in self.links.all()] return ORMLocalObjectManager(self.stub, "Instance", idList, False) register_convenience_wrapper("Network", ORMWrapperNetwork)
return self.get_vrouter_field("gateway_mac", None) @property def wan_vm_ip(self): tags = self.stub.Tag.objects.filter( name="vm_vrouter_tenant", object_id=self.instance.id, content_type=self.instance.self_content_type_id) if tags: tenant = self.stub.VRouterTenant.objects.get(id=int(tags[0].value)) return tenant.public_ip else: raise Exception("no vm_vrouter_tenant tag for instance %s" % self.instance) @property def wan_vm_mac(self): tags = self.stub.Tag.objects.filter( name="vm_vrouter_tenant", object_id=self.instance.id, content_type=self.instance.self_content_type_id) if tags: tenant = self.stub.VRouterTenant.objects.get(id=int(tags[0].value)) return tenant.public_mac else: raise Exception("no vm_vrouter_tenant tag for instance %s" % self.instance) register_convenience_wrapper("VSGTenant", ORMWrapperVSGTenant)
# See the License for the specific language governing permissions and # limitations under the License. from xosapi.orm import ORMWrapper, register_convenience_wrapper class ORMWrapperRCORDSubscriber(ORMWrapper): @property def volt(self): links = self.subscribed_links.all() for link in links: # FIXME: hardcoded service dependency # cast from ServiceInstance to VOLTServiceInstance volts = self.stub.VOLTServiceInstance.objects.filter(id=link.provider_service_instance.id) if volts: return volts[0] return None sync_attributes = ("firewall_enable", "firewall_rules", "url_filter_enable", "url_filter_rules", "cdn_enable", "uplink_speed", "downlink_speed", "status") register_convenience_wrapper("RCORDSubscriber", ORMWrapperRCORDSubscriber)
# cast from ServiceInstance to VSGTenant vegs = self.stub.VEGTenant.objects.filter( id=link.provider_service_instance.id) if vegs: return vegs[0] return None # DEPRECATED @property def vcpe(self): return self.veg # DEPRECATED @property def vsg(Self): return self.veg @property def subscriber(self): links = self.stub.ServiceInstanceLink.objects.filter( provider_service_instance_id=self.id) for link in links: # assume the only thing that links to a VEE must be a subscriber if link.subscriber_service_instance: return link.subscriber_service_instance.leaf_model return None register_convenience_wrapper("VEEServiceInstance", ORMWrapperVEEServiceInstance)
if addr in inuse_ips: # This may have happened if someone re-ran the tosca # recipe and 'refilled' the AddressPool while some addresses # were still in use. continue inuse_ips.insert(0, addr) ap.inuse = " ".join(inuse_ips) ap.addresses = " ".join(avail_ips) return addr return None def put_address(self, addr): ap = self addresses = ap.addresses or "" parts = addresses.split() if addr not in parts: parts.insert(0, addr) ap.addresses = " ".join(parts) inuse = ap.inuse or "" parts = inuse.split() if addr in parts: parts.remove(addr) ap.inuse = " ".join(parts) register_convenience_wrapper("AddressPool", ORMWrapperAddressPool)
for link in links: # TODO: hardcoded service dependency # cast from ServiceInstance to VOLTTenant volts = self.stub.VOLTTenant.objects.filter( id=link.provider_service_instance.id) if volts: return volts[0] return None sync_attributes = ("firewall_enable", "firewall_rules", "url_filter_enable", "url_filter_rules", "cdn_enable", "uplink_speed", "downlink_speed", "enable_uverse", "status") # figure out what to do about "devices"... is it still needed? def get_attribute(self, name, default=None): if self.service_specific_attribute: attributes = json.loads(self.service_specific_attribute) else: attributes = {} return attributes.get(name, default) @property def devices(self): return self.get_attribute("devices", []) register_convenience_wrapper("CordSubscriberRoot", ORMWrapperCordSubscriberRoot)
# You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import json from xosapi.orm import ORMWrapper, register_convenience_wrapper class ORMWrapperServiceInstance(ORMWrapper): @property def serviceinstanceattribute_dict(self): attrs = {} for attr in self.service_instance_attributes.all(): attrs[attr.name] = attr.value return attrs @property def tenantattribute_dict(self): return self.serviceinstanceattribute_dict class ORMWrapperTenant(ORMWrapperServiceInstance): pass register_convenience_wrapper("ServiceInstance", ORMWrapperServiceInstance)
# Copyright 2017-present Open Networking Foundation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import json from xosapi.orm import ORMWrapper, register_convenience_wrapper from xosapi.convenience.service import ORMWrapperService class ORMWrapperAddressManagerService(ORMWrapperService): def get_gateways(self): gateways = [] aps = self.addresspools.all() for ap in aps: gateways.append({"gateway_ip": ap.gateway_ip, "gateway_mac": ap.gateway_mac}) return gateways register_convenience_wrapper("AddressManagerService", ORMWrapperAddressManagerService)
# Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from __future__ import absolute_import from xosapi.orm import ORMWrapper, register_convenience_wrapper class ORMWrapperPort(ORMWrapper): def get_parameters(self): parameter_dict = {} for param in self.stub.NetworkParameter.objects.filter( content_type=self.self_content_type_id, object_id=self.id ): parameter_dict[param.parameter.name] = param.value return parameter_dict register_convenience_wrapper("Port", ORMWrapperPort)
import json from xosapi.orm import ORMWrapper, register_convenience_wrapper from xosapi.convenience.tenant import ORMWrapperTenant class ORMWrapperONOSApp(ORMWrapperTenant): pass register_convenience_wrapper("ONOSApp", ORMWrapperONOSApp)
# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import json from xosapi.orm import ORMWrapper, register_convenience_wrapper class ORMWrapperVRouterApp(ORMWrapper): @property def interfaces(self): app_interfaces = [] devices = self.stub.VRouterDevice.objects.filter( vrouter_service_id=self.vrouter_service.id) for device in devices: ports = self.stub.VRouterPort.objects.filter( vrouter_device_id=device.id) for port in ports: interfaces = self.stub.VRouterInterface.objects.filter( vrouter_port_id=port.id) for iface in interfaces: app_interfaces.append(iface.name) return app_interfaces register_convenience_wrapper("VRouterApp", ORMWrapperVRouterApp)