| peusterm | 72f0988 | 2018-05-15 17:10:27 +0200 | [diff] [blame] | 1 | # Copyright (c) 2015 SONATA-NFV and Paderborn University |
| 2 | # ALL RIGHTS RESERVED. |
| 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 | # Neither the name of the SONATA-NFV, Paderborn University |
| 17 | # nor the names of its contributors may be used to endorse or promote |
| 18 | # products derived from this software without specific prior written |
| 19 | # permission. |
| 20 | # |
| 21 | # This work has been performed in the framework of the SONATA project, |
| 22 | # funded by the European Commission under Grant number 671517 through |
| 23 | # the Horizon 2020 and 5G-PPP programmes. The authors would like to |
| 24 | # acknowledge the contributions of their colleagues of the SONATA |
| 25 | # partner consortium (www.sonata-nfv.eu). |
| peusterm | d7cbd21 | 2017-09-07 08:55:14 +0200 | [diff] [blame] | 26 | |
| peusterm | d7cbd21 | 2017-09-07 08:55:14 +0200 | [diff] [blame] | 27 | |
| peusterm | 0019978 | 2017-05-17 08:48:12 +0200 | [diff] [blame] | 28 | class Server(object): |
| peusterm | 72f0988 | 2018-05-15 17:10:27 +0200 | [diff] [blame] | 29 | def __init__(self, name, id=None, flavor=None, |
| 30 | image=None, command=None, nw_list=None): |
| peusterm | 0019978 | 2017-05-17 08:48:12 +0200 | [diff] [blame] | 31 | self.name = name |
| 32 | self.full_name = None |
| 33 | self.template_name = None |
| 34 | self.id = id |
| 35 | self.image = image |
| 36 | self.command = command |
| 37 | self.port_names = list() |
| splietker | 7b38ee1 | 2017-06-28 17:24:01 +0200 | [diff] [blame] | 38 | self.properties = dict() |
| peusterm | 0019978 | 2017-05-17 08:48:12 +0200 | [diff] [blame] | 39 | self.flavor = flavor |
| 40 | self.son_emu_command = None |
| 41 | self.emulator_compute = None |
| 42 | |
| 43 | def compare_attributes(self, other): |
| 44 | """ |
| 45 | Compares only class attributes like name and flavor but not the list of ports with the other server. |
| 46 | |
| 47 | :param other: The second server to compare with. |
| 48 | :type other: :class:`heat.resources.server` |
| 49 | :return: * *True*: If all attributes are alike. |
| 50 | * *False*: Else |
| 51 | :rtype: ``bool`` |
| 52 | """ |
| 53 | if self.name == other.name and self.full_name == other.full_name and \ |
| peusterm | 72f0988 | 2018-05-15 17:10:27 +0200 | [diff] [blame] | 54 | self.flavor == other.flavor and \ |
| 55 | self.image == other.image and \ |
| 56 | self.command == other.command: |
| peusterm | 0019978 | 2017-05-17 08:48:12 +0200 | [diff] [blame] | 57 | return True |
| 58 | return False |
| 59 | |
| 60 | def __eq__(self, other): |
| 61 | if self.name == other.name and self.full_name == other.full_name and \ |
| peusterm | 72f0988 | 2018-05-15 17:10:27 +0200 | [diff] [blame] | 62 | self.flavor == other.flavor and \ |
| 63 | self.image == other.image and \ |
| 64 | self.command == other.command and \ |
| 65 | len(self.port_names) == len(other.port_names) and \ |
| 66 | set(self.port_names) == set(other.port_names): |
| peusterm | 0019978 | 2017-05-17 08:48:12 +0200 | [diff] [blame] | 67 | return True |
| 68 | return False |
| 69 | |
| 70 | def create_server_dict(self, compute=None): |
| 71 | """ |
| 72 | Creates the server description dictionary. |
| 73 | |
| 74 | :param compute: The compute resource for further status information. |
| 75 | :type compute: :class:`heat.compute` |
| 76 | :return: Server description dictionary. |
| 77 | :rtype: ``dict`` |
| 78 | """ |
| 79 | server_dict = dict() |
| 80 | server_dict['name'] = self.name |
| 81 | server_dict['full_name'] = self.full_name |
| 82 | server_dict['id'] = self.id |
| 83 | server_dict['template_name'] = self.template_name |
| 84 | server_dict['flavor'] = self.flavor |
| 85 | server_dict['image'] = self.image |
| 86 | if self.son_emu_command is not None: |
| 87 | server_dict['command'] = self.son_emu_command |
| 88 | else: |
| 89 | server_dict['command'] = self.command |
| 90 | |
| 91 | if compute is not None: |
| 92 | server_dict['status'] = 'ACTIVE' |
| 93 | server_dict['OS-EXT-STS:power_state'] = 1 |
| 94 | server_dict["OS-EXT-STS:task_state"] = None |
| 95 | return server_dict |