1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 09:18:08 +00:00

Merge branch 'master' into 2.0

This commit is contained in:
Julien Duponchelle 2016-04-26 11:50:16 +02:00
commit 7390d833ba
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
6 changed files with 81 additions and 9 deletions

View File

@ -41,6 +41,8 @@ from ...schemas.qemu import QEMU_OBJECT_SCHEMA, QEMU_PLATFORMS
from ...utils.asyncio import monitor_process from ...utils.asyncio import monitor_process
from ...utils.images import md5sum from ...utils.images import md5sum
from .qcow2 import Qcow2, Qcow2Error from .qcow2 import Qcow2, Qcow2Error
from ...utils import macaddress_to_int, int_to_macaddress
import logging import logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -1326,7 +1328,7 @@ class QemuVM(BaseVM):
patched_qemu = True patched_qemu = True
for adapter_number, adapter in enumerate(self._ethernet_adapters): for adapter_number, adapter in enumerate(self._ethernet_adapters):
mac = "%s%02x" % (self._mac_address[:-2], (int(self._mac_address[-2:]) + adapter_number) % 255) mac = int_to_macaddress(macaddress_to_int(self._mac_address) + adapter_number)
nio = adapter.get_nio(0) nio = adapter.get_nio(0)
if self._legacy_networking: if self._legacy_networking:
# legacy QEMU networking syntax (-net) # legacy QEMU networking syntax (-net)

View File

@ -618,7 +618,7 @@ class VMware(BaseManager):
yield from self.check_vmware_version() yield from self.check_vmware_version()
inventory_path = self.get_vmware_inventory_path() inventory_path = self.get_vmware_inventory_path()
if os.path.exists(inventory_path) and self.host_type == "ws": if os.path.exists(inventory_path) and self.host_type != "player":
# inventory may exist for VMware player if VMware workstation has been previously installed # inventory may exist for VMware player if VMware workstation has been previously installed
return self._get_vms_from_inventory(inventory_path) return self._get_vms_from_inventory(inventory_path)
else: else:

View File

@ -16,6 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import textwrap
import posixpath import posixpath
@ -26,3 +27,20 @@ def force_unix_path(path):
path = path.replace("\\", "/") path = path.replace("\\", "/")
return posixpath.normpath(path) return posixpath.normpath(path)
def macaddress_to_int(macaddress):
"""
Convert a macaddress with the format 00:0c:29:11:b0:0a to a int
:param macaddress: The mac address
:returns: Integer
"""
return int(macaddress.replace(":", ""), 16)
def int_to_macaddress(integer):
"""
Convert an integer to a macaddress
"""
return ":".join(textwrap.wrap("%012x" % (integer), width=2))

View File

@ -289,9 +289,9 @@ dev tun
<connection> <connection>
remote $MY_IP_ADDR 1194 udp remote $MY_IP_ADDR 1194 udp
</connection> </connection>
EOF EOFCLIENT
cat <<EOF > /etc/openvpn/udp1194.conf cat <<EOFUDP > /etc/openvpn/udp1194.conf
server 172.16.253.0 255.255.255.0 server 172.16.253.0 255.255.255.0
verb 3 verb 3
duplicate-cn duplicate-cn
@ -308,7 +308,7 @@ port 1194
dev tun1194 dev tun1194
status openvpn-status-1194.log status openvpn-status-1194.log
log-append /var/log/openvpn-udp1194.log log-append /var/log/openvpn-udp1194.log
EOF EOFUDP
echo "Setup HTTP server for serving client certificate" echo "Setup HTTP server for serving client certificate"
mkdir -p /usr/share/nginx/openvpn/$UUID mkdir -p /usr/share/nginx/openvpn/$UUID
@ -316,12 +316,13 @@ cp /root/client.ovpn /usr/share/nginx/openvpn/$UUID/$HOSTNAME.ovpn
touch /usr/share/nginx/openvpn/$UUID/index.html touch /usr/share/nginx/openvpn/$UUID/index.html
touch /usr/share/nginx/openvpn/index.html touch /usr/share/nginx/openvpn/index.html
cat <<EOF > /etc/nginx/sites-available/openvpn cat <<EOFNGINX > /etc/nginx/sites-available/openvpn
server { server {
listen 8003; listen 8003;
root /usr/share/nginx/openvpn; root /usr/share/nginx/openvpn;
} }
EOFCLIENT EOFNGINX
[ -f /etc/nginx/sites-enabled/openvpn ] || ln -s /etc/nginx/sites-available/openvpn /etc/nginx/sites-enabled/ [ -f /etc/nginx/sites-enabled/openvpn ] || ln -s /etc/nginx/sites-available/openvpn /etc/nginx/sites-enabled/
service nginx stop service nginx stop
service nginx start service nginx start
@ -332,6 +333,6 @@ set +e
service openvpn stop service openvpn stop
service openvpn start service openvpn start
log "Download http://$MY_IP_ADDR:8003/$UUID/$HOSTNAME.ovpn to setup your OpenVPN client" log "Download http://$MY_IP_ADDR:8003/$UUID/$HOSTNAME.ovpn to setup your OpenVPN client after rebooting the server"
fi fi

View File

@ -445,6 +445,49 @@ def test_build_command_without_display(vm, loop, fake_qemu_binary):
assert "-nographic" in cmd assert "-nographic" in cmd
def test_build_command_two_adapters(vm, loop, fake_qemu_binary, port_manager):
vm.adapters = 2
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
assert cmd == [
fake_qemu_binary,
"-name",
"test",
"-m",
"256M",
"-smp",
"cpus=1",
"-boot",
"order=c",
"-serial",
"telnet:127.0.0.1:{},server,nowait".format(vm.console),
"-net",
"none",
"-device",
"e1000,mac=00:00:ab:0e:0f:00",
"-device",
"e1000,mac=00:00:ab:0e:0f:01",
"-nographic"
]
def test_build_command_two_adapters_mac_address(vm, loop, fake_qemu_binary, port_manager):
vm.adapters = 2
vm.mac_address = "00:00:ab:0e:0f:09"
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
assert "e1000,mac=00:00:ab:0e:0f:09" in cmd
assert "e1000,mac=00:00:ab:0e:0f:0a" in cmd
vm.mac_address = "00:00:ab:0e:0f:0a"
with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process:
cmd = loop.run_until_complete(asyncio.async(vm._build_command()))
assert "e1000,mac=00:00:ab:0e:0f:0a" in cmd
assert "e1000,mac=00:00:ab:0e:0f:0b" in cmd
# Windows accept this kind of mistake # Windows accept this kind of mistake
@pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows") @pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
def test_build_command_with_invalid_options(vm, loop, fake_qemu_binary): def test_build_command_with_invalid_options(vm, loop, fake_qemu_binary):

View File

@ -16,10 +16,18 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from gns3server.utils import force_unix_path from gns3server.utils import force_unix_path, macaddress_to_int, int_to_macaddress
def test_force_unix_path(): def test_force_unix_path():
assert force_unix_path("a/b") == "a/b" assert force_unix_path("a/b") == "a/b"
assert force_unix_path("a\\b") == "a/b" assert force_unix_path("a\\b") == "a/b"
assert force_unix_path("a\\b\\..\\c") == "a/c" assert force_unix_path("a\\b\\..\\c") == "a/c"
def test_macaddress_to_int():
assert macaddress_to_int("00:0c:29:11:b0:0a") == 52228632586
def test_int_to_macaddress():
assert int_to_macaddress(52228632586) == "00:0c:29:11:b0:0a"