| peusterm | 0019978 | 2017-05-17 08:48:12 +0200 | [diff] [blame] | 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() |
| splietker | 7b38ee1 | 2017-06-28 17:24:01 +0200 | [diff] [blame^] | 10 | self.properties = dict() |
| peusterm | 0019978 | 2017-05-17 08:48:12 +0200 | [diff] [blame] | 11 | self.flavor = flavor |
| 12 | self.son_emu_command = None |
| 13 | self.emulator_compute = None |
| 14 | |
| 15 | def compare_attributes(self, other): |
| 16 | """ |
| 17 | Compares only class attributes like name and flavor but not the list of ports with the other server. |
| 18 | |
| 19 | :param other: The second server to compare with. |
| 20 | :type other: :class:`heat.resources.server` |
| 21 | :return: * *True*: If all attributes are alike. |
| 22 | * *False*: Else |
| 23 | :rtype: ``bool`` |
| 24 | """ |
| 25 | if self.name == other.name and self.full_name == other.full_name and \ |
| 26 | self.flavor == other.flavor and \ |
| 27 | self.image == other.image and \ |
| 28 | self.command == other.command: |
| 29 | return True |
| 30 | return False |
| 31 | |
| 32 | def __eq__(self, other): |
| 33 | if self.name == other.name and self.full_name == other.full_name and \ |
| 34 | self.flavor == other.flavor and \ |
| 35 | self.image == other.image and \ |
| 36 | self.command == other.command and \ |
| 37 | len(self.port_names) == len(other.port_names) and \ |
| 38 | set(self.port_names) == set(other.port_names): |
| 39 | return True |
| 40 | return False |
| 41 | |
| 42 | def create_server_dict(self, compute=None): |
| 43 | """ |
| 44 | Creates the server description dictionary. |
| 45 | |
| 46 | :param compute: The compute resource for further status information. |
| 47 | :type compute: :class:`heat.compute` |
| 48 | :return: Server description dictionary. |
| 49 | :rtype: ``dict`` |
| 50 | """ |
| 51 | server_dict = dict() |
| 52 | server_dict['name'] = self.name |
| 53 | server_dict['full_name'] = self.full_name |
| 54 | server_dict['id'] = self.id |
| 55 | server_dict['template_name'] = self.template_name |
| 56 | server_dict['flavor'] = self.flavor |
| 57 | server_dict['image'] = self.image |
| 58 | if self.son_emu_command is not None: |
| 59 | server_dict['command'] = self.son_emu_command |
| 60 | else: |
| 61 | server_dict['command'] = self.command |
| 62 | |
| 63 | if compute is not None: |
| 64 | server_dict['status'] = 'ACTIVE' |
| 65 | server_dict['OS-EXT-STS:power_state'] = 1 |
| 66 | server_dict["OS-EXT-STS:task_state"] = None |
| 67 | return server_dict |