blob: bd1800d39bb60736ebf4305022745b8e9176c247 [file] [log] [blame]
Matteo Scandoloeb0d11c2017-08-08 13:05:26 -07001
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 Parlakisik638c65f2017-05-31 11:10:24 +030017default_attributes = {"sflow_port": SFLOW_PORT, "sflow_api_port": SFLOW_API_PORT}
18
19sync_attributes = ("sflow_port", "sflow_api_port",)
20
21@property
22def sflow_port(self):
23 return self.get_attribute("sflow_port", self.default_attributes["sflow_port"])
24
25@sflow_port.setter
26def sflow_port(self, value):
27 self.set_attribute("sflow_port", value)
28
29@property
30def sflow_api_port(self):
31 return self.get_attribute("sflow_api_port", self.default_attributes["sflow_api_port"])
32
33@sflow_api_port.setter
34def sflow_api_port(self, value):
35 self.set_attribute("sflow_api_port", value)
36
37def 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
46def 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) + "/"