Some cleaning + move "/version" endpoint to "/server/version".

This commit is contained in:
grossmj committed 2016-06-01 17:50:31 -06:00
1 parent 87f15eafe0
commit cd07a99118
18 files changed
+70 -187

No files matched your search

+4 -5
View File
@@ -37,7 +37,7 @@ from .project_manager import ProjectManager
from .nios.nio_udp import NIOUDP
from .nios.nio_tap import NIOTAP
from .nios.nio_generic_ethernet import NIOGenericEthernet
from .nios.nio_ethernet import NIOEthernet
from ..utils.images import md5sum, remove_checksum
from .node_error import NodeError
@@ -317,8 +317,7 @@ class BaseManager:
@staticmethod
def has_privileged_access(executable):
"""
Check if an executable can access Ethernet and TAP devices in
RAW mode.
Check if an executable have the right to attach to Ethernet and TAP adapters.
:param executable: executable path
@@ -382,11 +381,11 @@ class BaseManager:
# if not self.has_privileged_access(executable):
# raise aiohttp.web.HTTPForbidden(text="{} has no privileged access to {}.".format(executable, tap_device))
nio = NIOTAP(tap_device)
elif nio_settings["type"] == "nio_generic_ethernet":
elif nio_settings["type"] in ("nio_generic_ethernet", "nio_ethernet"):
ethernet_device = nio_settings["ethernet_device"]
if not is_interface_up(ethernet_device):
raise aiohttp.web.HTTPConflict(text="Ethernet interface {} does not exist or is down".format(ethernet_device))
nio = NIOGenericEthernet(ethernet_device)
nio = NIOEthernet(ethernet_device)
assert nio is not None
return nio
+1 -1
View File
@@ -142,7 +142,7 @@ class Cloud(BaseNode):
if port_info["type"] in ("ethernet", "tap"):
network_interfaces = [interface["name"] for interface in interfaces()]
if not port_info["interface"] in network_interfaces:
raise NodeError("Interface {} could not be found on this system".format(port_info["interface"]))
raise NodeError("Interface '{}' could not be found on this system".format(port_info["interface"]))
if sys.platform.startswith("win"):
windows_interfaces = interfaces()
+2 -2
View File
@@ -41,7 +41,7 @@ from ..adapters.ethernet_adapter import EthernetAdapter
from ..adapters.serial_adapter import SerialAdapter
from ..nios.nio_udp import NIOUDP
from ..nios.nio_tap import NIOTAP
from ..nios.nio_generic_ethernet import NIOGenericEthernet
from ..nios.nio_ethernet import NIOEthernet
from ..base_node import BaseNode
from .utils.iou_import import nvram_import
from .utils.iou_export import nvram_export
@@ -610,7 +610,7 @@ class IOUVM(BaseNode):
# TAP interface
connection = {"tap_dev": "{tap_device}".format(tap_device=nio.tap_device)}
elif isinstance(nio, NIOGenericEthernet):
elif isinstance(nio, NIOEthernet):
# Ethernet interface
connection = {"eth_dev": "{ethernet_device}".format(ethernet_device=nio.ethernet_device)}
@@ -16,13 +16,13 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
Interface for generic Ethernet NIOs (PCAP library).
Interface for Ethernet NIOs.
"""
from .nio import NIO
class NIOGenericEthernet(NIO):
class NIOEthernet(NIO):
"""
Generic Ethernet NIO.
@@ -51,5 +51,5 @@ class NIOGenericEthernet(NIO):
def __json__(self):
return {"type": "nio_generic_ethernet",
return {"type": "nio_ethernet",
"ethernet_device": self._ethernet_device}
-41
View File
@@ -1,41 +0,0 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2013 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/>.
"""
Interface for NAT NIOs.
"""
from .nio import NIO
class NIONAT(NIO):
"""
NAT NIO.
"""
def __init__(self):
super().__init__()
def __str__(self):
return "NIO TAP"
def __json__(self):
return {"type": "nio_nat"}
+2 -2
View File
@@ -135,7 +135,7 @@ class PortManager:
return self._used_udp_ports
@staticmethod
def find_unused_port(start_port, end_port, host="127.0.0.1", socket_type="TCP", ignore_ports=[]):
def find_unused_port(start_port, end_port, host="127.0.0.1", socket_type="TCP", ignore_ports=None):
"""
Finds an unused port in a range.
@@ -151,7 +151,7 @@ class PortManager:
last_exception = None
for port in range(start_port, end_port + 1):
if port in ignore_ports or port in BANNED_PORTS:
if ignore_ports and (port in ignore_ports or port in BANNED_PORTS):
continue
try:
+1 -1
View File
@@ -369,7 +369,7 @@ class Project:
"""
files = []
for (dirpath, dirnames, filenames) in os.walk(self.path):
for dirpath, dirnames, filenames in os.walk(self.path):
for filename in filenames:
if not filename.endswith(".ghost"):
path = os.path.relpath(dirpath, self.path)
+9 -7
View File
@@ -31,7 +31,7 @@ class Qcow2:
def __init__(self, path):
self.path = path
self._path = path
self._reload()
def _reload(self):
@@ -57,15 +57,14 @@ class Qcow2:
# uint32_t nb_snapshots;
# uint64_t snapshots_offset;
# } QCowHeader;
struct_format = ">IIQi"
with open(self.path, 'rb') as f:
with open(self._path, 'rb') as f:
content = f.read(struct.calcsize(struct_format))
self.magic, self.version, self.backing_file_offset, self.backing_file_size = struct.unpack_from(struct_format, content)
if self.magic != 1363560955: # The first 4 bytes contain the characters 'Q', 'F', 'I' followed by 0xfb.
raise Qcow2Error("Invalid magic for {}".format(self.path))
raise Qcow2Error("Invalid magic for {}".format(self._path))
@property
def backing_file(self):
@@ -74,9 +73,11 @@ class Qcow2:
:returns: None if it's not a linked clone, the path otherwise
"""
with open(self.path, 'rb') as f:
with open(self._path, 'rb') as f:
f.seek(self.backing_file_offset)
content = f.read(self.backing_file_size)
path = content.decode()
if len(path) == 0:
return None
@@ -90,9 +91,10 @@ class Qcow2:
:param qemu_img: Path to the qemu-img binary
:param base_image: Path to the base image
"""
if not os.path.exists(base_image):
raise FileNotFoundError(base_image)
command = [qemu_img, "rebase", "-u", "-b", base_image, self.path]
command = [qemu_img, "rebase", "-u", "-b", base_image, self._path]
process = yield from asyncio.create_subprocess_exec(*command)
retcode = yield from process.wait()
if retcode != 0:
-53
View File
@@ -1,53 +0,0 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2015 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/>.
"""
Interface for VMnet NIOs.
"""
from ..nios.nio import NIO
class NIOVMNET(NIO):
"""
VMnet NIO.
"""
def __init__(self, vmnet):
super().__init__()
self._vmnet = vmnet
@property
def vmnet(self):
"""
Returns vmnet interface used by this NIO.
:returns: vmnet interface name
"""
return self._vmnet
def __str__(self):
return "NIO VMNET"
def __json__(self):
return {"type": "nio_vmnet",
"vmnet": self._vmnet}