Matteo Scandolo | eb0d11c | 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 | |
Murat Parlakisik | 638c65f | 2017-05-31 11:10:24 +0300 | [diff] [blame] | 17 | default_attributes = {"sflow_port": SFLOW_PORT, "sflow_api_port": SFLOW_API_PORT} |
| 18 | |
| 19 | sync_attributes = ("sflow_port", "sflow_api_port",) |
| 20 | |
| 21 | @property |
| 22 | def sflow_port(self): |
| 23 | return self.get_attribute("sflow_port", self.default_attributes["sflow_port"]) |
| 24 | |
| 25 | @sflow_port.setter |
| 26 | def sflow_port(self, value): |
| 27 | self.set_attribute("sflow_port", value) |
| 28 | |
| 29 | @property |
| 30 | def sflow_api_port(self): |
| 31 | return self.get_attribute("sflow_api_port", self.default_attributes["sflow_api_port"]) |
| 32 | |
| 33 | @sflow_api_port.setter |
| 34 | def sflow_api_port(self, value): |
| 35 | self.set_attribute("sflow_api_port", value) |
| 36 | |
| 37 | def get_instance(self): |
| 38 | if self.slices.exists(): |
| 39 | slice = self.slices.all()[0] |
| 40 | if slice.instances.exists(): |
| 41 | return slice.instances.all()[0] |
| 42 | |
| 43 | return None |
| 44 | |
| 45 | @property |
| 46 | def sflow_api_url(self): |
| 47 | if not self.get_instance(): |
| 48 | return None |
| 49 | return "http://" + self.get_instance().get_ssh_ip() + ":" + str(self.sflow_api_port) + "/" |