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
|
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
|
|
|
|
2021-10-18 07:34:30 +00:00
|
|
|
def __init__(self, path, data, builtin=True):
|
2021-04-17 09:06:32 +00:00
|
|
|
|
2018-11-28 09:12:57 +00:00
|
|
|
self._data = data.copy()
|
2021-10-18 11:16:50 +00:00
|
|
|
self._id = self._data.get("appliance_id")
|
2021-10-18 07:34:30 +00:00
|
|
|
self._path = path
|
2017-04-12 12:35:49 +00:00
|
|
|
self._builtin = builtin
|
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
|
|
|
|
|
2021-10-18 07:34:30 +00:00
|
|
|
@property
|
|
|
|
def path(self):
|
|
|
|
return self._path
|
|
|
|
|
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-10-10 07:05:11 +00:00
|
|
|
@property
|
|
|
|
def type(self):
|
|
|
|
|
|
|
|
if "iou" in self._data:
|
|
|
|
return "iou"
|
|
|
|
elif "dynamips" in self._data:
|
|
|
|
return "dynamips"
|
2021-10-18 07:34:30 +00:00
|
|
|
elif "docker" in self._data:
|
|
|
|
return "docker"
|
2021-10-10 07:05:11 +00:00
|
|
|
else:
|
|
|
|
return "qemu"
|
|
|
|
|
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
|
|
|
"""
|
2021-10-18 11:16:50 +00:00
|
|
|
|
2018-11-28 09:12:57 +00:00
|
|
|
data = copy.deepcopy(self._data)
|
|
|
|
data["builtin"] = self._builtin
|
|
|
|
return data
|