Matteo Scandolo | d02b73b | 2017-08-08 13:05:26 -0700 | [diff] [blame^] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
Scott Baker | 87eb740 | 2016-06-20 17:21:50 -0700 | [diff] [blame] | 17 | from service import XOSService |
Matteo Scandolo | a4e6e9a | 2016-08-23 12:04:45 -0700 | [diff] [blame] | 18 | from services.vrouter.models import * |
| 19 | |
Scott Baker | 87eb740 | 2016-06-20 17:21:50 -0700 | [diff] [blame] | 20 | |
| 21 | class XOSVRouterService(XOSService): |
| 22 | provides = "tosca.nodes.VRouterService" |
| 23 | xos_model = VRouterService |
Matteo Scandolo | a4e6e9a | 2016-08-23 12:04:45 -0700 | [diff] [blame] | 24 | copyin_props = ["view_url", "icon_url", "enabled", "published", "public_key", "versionNumber", |
| 25 | "rest_hostname", "rest_port", "rest_user", "rest_pass"] |
Scott Baker | 87eb740 | 2016-06-20 17:21:50 -0700 | [diff] [blame] | 26 | |
Matteo Scandolo | a4e6e9a | 2016-08-23 12:04:45 -0700 | [diff] [blame] | 27 | |
| 28 | class XOSVRouterDevice(XOSService): |
| 29 | provides = "tosca.nodes.VRouterDevice" |
| 30 | xos_model = VRouterDevice |
| 31 | copyin_props = ['openflow_id', 'config_key', 'driver'] |
| 32 | |
| 33 | def get_xos_args(self): |
| 34 | args = super(XOSVRouterDevice, self).get_xos_args() |
| 35 | |
| 36 | serviceName = self.get_requirement("tosca.relationships.MemberOfService", throw_exception=False) |
| 37 | if serviceName: |
| 38 | service = self.get_xos_object(Service, name=serviceName) |
| 39 | args["vrouter_service_id"] = service.id |
| 40 | return args |
| 41 | |
| 42 | |
| 43 | class XOSVRouterPort(XOSService): |
| 44 | provides = "tosca.nodes.VRouterPort" |
| 45 | xos_model = VRouterPort |
| 46 | copyin_props = ['openflow_id'] |
| 47 | |
| 48 | def get_xos_args(self): |
| 49 | args = super(XOSVRouterPort, self).get_xos_args() |
| 50 | |
| 51 | deviceName = self.get_requirement("tosca.relationships.PortOfDevice", throw_exception=False) |
| 52 | if deviceName: |
| 53 | device = self.get_xos_object(VRouterDevice, name=deviceName) |
| 54 | args["vrouter_device"] = device |
| 55 | |
| 56 | serviceName = self.get_requirement("tosca.relationships.MemberOfService", throw_exception=False) |
| 57 | if serviceName: |
| 58 | service = self.get_xos_object(Service, name=serviceName) |
| 59 | args["vrouter_service_id"] = service.id |
| 60 | |
| 61 | return args |
| 62 | |
| 63 | |
| 64 | class XOSVRouterInterface(XOSService): |
| 65 | provides = "tosca.nodes.VRouterInterface" |
| 66 | xos_model = VRouterInterface |
| 67 | copyin_props = ['name', 'mac', 'vlan'] |
| 68 | |
| 69 | def get_xos_args(self): |
| 70 | args = super(XOSVRouterInterface, self).get_xos_args() |
| 71 | |
| 72 | portName = self.get_requirement("tosca.relationships.InterfaceOfPort", throw_exception=False) |
| 73 | if portName: |
| 74 | port = self.get_xos_object(VRouterPort, name=portName) |
| 75 | args["vrouter_port"] = port |
| 76 | return args |
| 77 | |
| 78 | |
| 79 | class XOSVRouterIp(XOSService): |
| 80 | provides = "tosca.nodes.VRouterIp" |
| 81 | xos_model = VRouterIp |
| 82 | copyin_props = ['ip'] |
| 83 | |
| 84 | def get_xos_args(self): |
| 85 | args = super(XOSVRouterIp, self).get_xos_args() |
| 86 | |
| 87 | interfaceName = self.get_requirement("tosca.relationships.IpOfInterface", throw_exception=False) |
| 88 | if interfaceName: |
| 89 | interface = self.get_xos_object(VRouterInterface, name=interfaceName) |
| 90 | args["vrouter_interface"] = interface |
| 91 | return args |
| 92 | |
| 93 | |
| 94 | class XOSVRouterApp(XOSService): |
| 95 | provides = "tosca.nodes.VRouterApp" |
| 96 | xos_model = VRouterApp |
| 97 | copyin_props = ['name', 'control_plane_connect_point', 'ospf_enabled'] |
| 98 | |
| 99 | def get_xos_args(self): |
| 100 | args = super(XOSVRouterApp, self).get_xos_args() |
| 101 | |
| 102 | serviceName = self.get_requirement("tosca.relationships.MemberOfService", throw_exception=True) |
| 103 | if serviceName: |
| 104 | service = self.get_xos_object(Service, name=serviceName) |
| 105 | args["vrouter_service_id"] = service.id |
| 106 | return args |