5b50c92a8a36031f20c7ef9b3c6a91bd2471206c
[osm/vim-emu.git] / src / emuvim / api / openstack / resources / flow_classifier.py
1 """
2 Copyright (c) 2017 SONATA-NFV and Paderborn University
3 ALL RIGHTS RESERVED.
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16
17 Neither the name of the SONATA-NFV, Paderborn University
18 nor the names of its contributors may be used to endorse or promote
19 products derived from this software without specific prior written
20 permission.
21
22 This work has been performed in the framework of the SONATA project,
23 funded by the European Commission under Grant number 671517 through
24 the Horizon 2020 and 5G-PPP programmes. The authors would like to
25 acknowledge the contributions of their colleagues of the SONATA
26 partner consortium (www.sonata-nfv.eu).
27 """
28 import uuid
29
30
31 class FlowClassifier(object):
32 def __init__(self, name):
33 self.id = str(uuid.uuid4())
34 self.tenant_id = "abcdefghijklmnopqrstuvwxyz123456"
35 self.name = name
36 self.description = ""
37 self.ethertype = "IPv4"
38 self.protocol = None
39 self.source_port_range_min = 0
40 self.source_port_range_max = 0
41 self.destination_port_range_min = 0
42 self.destination_port_range_max = 0
43 self.source_ip_prefix = None
44 self.destination_ip_prefix = None
45 self.logical_source_port = ""
46 self.logical_destination_port = ""
47 self.l7_parameters = dict()
48
49 def create_dict(self, compute):
50 representation = {
51 "name": self.name,
52 "tenant_id": self.tenant_id,
53 "description": self.description,
54 "id": self.id,
55 }
56 if self.ethertype:
57 representation["ethertype"] = self.ethertype
58 if self.protocol:
59 representation["protocol"] = self.protocol
60 if self.source_port_range_min:
61 representation["source_port_range_min"] = self.source_port_range_min
62 if self.source_port_range_max:
63 representation["source_port_range_max"] = self.source_port_range_max
64 if self.destination_port_range_min:
65 representation["destination_port_range_min"] = self.destination_port_range_min
66 if self.destination_port_range_max:
67 representation["destination_port_range_max"] = self.destination_port_range_max
68 if self.source_ip_prefix:
69 representation["source_ip_prefix"] = self.source_ip_prefix
70 if self.destination_ip_prefix:
71 representation["destination_ip_prefix"] = self.destination_ip_prefix
72 if len(self.logical_source_port):
73 representation["logical_source_port"] = self.logical_source_port
74 if len(self.logical_destination_port):
75 representation["logical_destination_port"] = self.logical_destination_port
76 if len(self.l7_parameters.items()):
77 representation["l7_parameters"] = self.l7_parameters
78
79 return representation