Manually added OpenStack API code
[osm/vim-emu.git] / src / emuvim / api / openstack / resources / server.py
1 class Server(object):
2 def __init__(self, name, id=None, flavor=None, image=None, command=None, nw_list=None):
3 self.name = name
4 self.full_name = None
5 self.template_name = None
6 self.id = id
7 self.image = image
8 self.command = command
9 self.port_names = list()
10 self.flavor = flavor
11 self.son_emu_command = None
12 self.emulator_compute = None
13
14 def compare_attributes(self, other):
15 """
16 Compares only class attributes like name and flavor but not the list of ports with the other server.
17
18 :param other: The second server to compare with.
19 :type other: :class:`heat.resources.server`
20 :return: * *True*: If all attributes are alike.
21 * *False*: Else
22 :rtype: ``bool``
23 """
24 if self.name == other.name and self.full_name == other.full_name and \
25 self.flavor == other.flavor and \
26 self.image == other.image and \
27 self.command == other.command:
28 return True
29 return False
30
31 def __eq__(self, other):
32 if self.name == other.name and self.full_name == other.full_name and \
33 self.flavor == other.flavor and \
34 self.image == other.image and \
35 self.command == other.command and \
36 len(self.port_names) == len(other.port_names) and \
37 set(self.port_names) == set(other.port_names):
38 return True
39 return False
40
41 def create_server_dict(self, compute=None):
42 """
43 Creates the server description dictionary.
44
45 :param compute: The compute resource for further status information.
46 :type compute: :class:`heat.compute`
47 :return: Server description dictionary.
48 :rtype: ``dict``
49 """
50 server_dict = dict()
51 server_dict['name'] = self.name
52 server_dict['full_name'] = self.full_name
53 server_dict['id'] = self.id
54 server_dict['template_name'] = self.template_name
55 server_dict['flavor'] = self.flavor
56 server_dict['image'] = self.image
57 if self.son_emu_command is not None:
58 server_dict['command'] = self.son_emu_command
59 else:
60 server_dict['command'] = self.command
61
62 if compute is not None:
63 server_dict['status'] = 'ACTIVE'
64 server_dict['OS-EXT-STS:power_state'] = 1
65 server_dict["OS-EXT-STS:task_state"] = None
66 return server_dict