2017-02-01 10:30:14 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# Copyright (C) 2016 GNS3 Technologies Inc.
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-06-28 07:37:19 +00:00
|
|
|
import copy
|
2017-02-01 10:30:14 +00:00
|
|
|
import uuid
|
2020-04-30 06:00:50 +00:00
|
|
|
import logging
|
2021-04-13 09:16:50 +00:00
|
|
|
|
2020-04-30 06:00:50 +00:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2017-04-12 12:35:49 +00:00
|
|
|
|
2017-02-01 10:30:14 +00:00
|
|
|
class Appliance:
|
2021-04-17 09:06:32 +00:00
|
|
|
|
2018-11-28 09:12:57 +00:00
|
|
|
def __init__(self, appliance_id, data, builtin=True):
|
2021-04-17 09:06:32 +00:00
|
|
|
|
2017-02-01 10:30:14 +00:00
|
|
|
if appliance_id is None:
|
|
|
|
self._id = str(uuid.uuid4())
|
2017-06-19 06:47:50 +00:00
|
|
|
elif isinstance(appliance_id, uuid.UUID):
|
|
|
|
self._id = str(appliance_id)
|
2017-02-01 10:30:14 +00:00
|
|
|
else:
|
|
|
|
self._id = appliance_id
|
2018-11-28 09:12:57 +00:00
|
|
|
self._data = data.copy()
|
2017-04-12 12:35:49 +00:00
|
|
|
self._builtin = builtin
|
2018-11-28 09:12:57 +00:00
|
|
|
if "appliance_id" in self._data:
|
|
|
|
del self._data["appliance_id"]
|
2018-11-17 11:12:46 +00:00
|
|
|
|
2021-04-13 09:16:50 +00:00
|
|
|
if self.status != "broken":
|
2021-04-13 09:07:58 +00:00
|
|
|
log.debug(f'Appliance "{self.name}" [{self._id}] loaded')
|
2020-04-30 06:00:50 +00:00
|
|
|
|
2017-02-01 10:30:14 +00:00
|
|
|
@property
|
|
|
|
def id(self):
|
|
|
|
return self._id
|
|
|
|
|
2017-04-12 12:35:49 +00:00
|
|
|
@property
|
2018-11-28 09:12:57 +00:00
|
|
|
def status(self):
|
|
|
|
return self._data["status"]
|
2018-11-17 11:12:46 +00:00
|
|
|
|
2019-03-11 09:55:16 +00:00
|
|
|
@property
|
|
|
|
def symbol(self):
|
|
|
|
return self._data.get("symbol")
|
|
|
|
|
2020-04-30 06:00:50 +00:00
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
return self._data.get("name")
|
|
|
|
|
2021-08-11 07:28:23 +00:00
|
|
|
@property
|
|
|
|
def images(self):
|
|
|
|
return self._data.get("images")
|
|
|
|
|
|
|
|
@property
|
|
|
|
def versions(self):
|
|
|
|
return self._data.get("versions")
|
|
|
|
|
2019-03-12 11:13:33 +00:00
|
|
|
@symbol.setter
|
|
|
|
def symbol(self, new_symbol):
|
|
|
|
self._data["symbol"] = new_symbol
|
|
|
|
|
2021-04-17 14:04:28 +00:00
|
|
|
def asdict(self):
|
2017-02-01 10:30:14 +00:00
|
|
|
"""
|
2018-11-28 09:12:57 +00:00
|
|
|
Appliance data (a hash)
|
2017-02-01 10:30:14 +00:00
|
|
|
"""
|
2018-11-28 09:12:57 +00:00
|
|
|
data = copy.deepcopy(self._data)
|
|
|
|
data["builtin"] = self._builtin
|
|
|
|
return data
|