blob: 2224de9d774245954f3259b03b4c4c536bcb9499 [file] [log] [blame]
peustermd7cbd212017-09-07 08:55:14 +02001"""
2Copyright (c) 2017 SONATA-NFV and Paderborn University
3ALL RIGHTS RESERVED.
4
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations under the License.
16
17Neither the name of the SONATA-NFV, Paderborn University
18nor the names of its contributors may be used to endorse or promote
19products derived from this software without specific prior written
20permission.
21
22This work has been performed in the framework of the SONATA project,
23funded by the European Commission under Grant number 671517 through
24the Horizon 2020 and 5G-PPP programmes. The authors would like to
25acknowledge the contributions of their colleagues of the SONATA
26partner consortium (www.sonata-nfv.eu).
27"""
peusterm00199782017-05-17 08:48:12 +020028class Server(object):
29 def __init__(self, name, id=None, flavor=None, image=None, command=None, nw_list=None):
30 self.name = name
31 self.full_name = None
32 self.template_name = None
33 self.id = id
34 self.image = image
35 self.command = command
36 self.port_names = list()
splietker7b38ee12017-06-28 17:24:01 +020037 self.properties = dict()
peusterm00199782017-05-17 08:48:12 +020038 self.flavor = flavor
39 self.son_emu_command = None
40 self.emulator_compute = None
41
42 def compare_attributes(self, other):
43 """
44 Compares only class attributes like name and flavor but not the list of ports with the other server.
45
46 :param other: The second server to compare with.
47 :type other: :class:`heat.resources.server`
48 :return: * *True*: If all attributes are alike.
49 * *False*: Else
50 :rtype: ``bool``
51 """
52 if self.name == other.name and self.full_name == other.full_name and \
53 self.flavor == other.flavor and \
54 self.image == other.image and \
55 self.command == other.command:
56 return True
57 return False
58
59 def __eq__(self, other):
60 if self.name == other.name and self.full_name == other.full_name and \
61 self.flavor == other.flavor and \
62 self.image == other.image and \
63 self.command == other.command and \
64 len(self.port_names) == len(other.port_names) and \
65 set(self.port_names) == set(other.port_names):
66 return True
67 return False
68
69 def create_server_dict(self, compute=None):
70 """
71 Creates the server description dictionary.
72
73 :param compute: The compute resource for further status information.
74 :type compute: :class:`heat.compute`
75 :return: Server description dictionary.
76 :rtype: ``dict``
77 """
78 server_dict = dict()
79 server_dict['name'] = self.name
80 server_dict['full_name'] = self.full_name
81 server_dict['id'] = self.id
82 server_dict['template_name'] = self.template_name
83 server_dict['flavor'] = self.flavor
84 server_dict['image'] = self.image
85 if self.son_emu_command is not None:
86 server_dict['command'] = self.son_emu_command
87 else:
88 server_dict['command'] = self.command
89
90 if compute is not None:
91 server_dict['status'] = 'ACTIVE'
92 server_dict['OS-EXT-STS:power_state'] = 1
93 server_dict["OS-EXT-STS:task_state"] = None
94 return server_dict