Attribute mac address

This commit is contained in:
Julien Duponchelle committed 2015-01-22 16:12:21 +01:00
1 parent 08b2dc6369
commit 6644c640db
5 files changed
+101 -9

No files matched your search

-7
View File
@@ -49,13 +49,6 @@ class BaseManager:
cls._instance = cls()
return cls._instance
def __del__(self):
self.destroy()
def destroy():
"""Cleanup the VMS. Call this before closing the server"""
cls._instance()
@property
def module_name(self):
"""
+36
View File
@@ -19,9 +19,45 @@
VPCS server module.
"""
import asyncio
from ..base_manager import BaseManager
from .vpcs_error import VPCSError
from .vpcs_vm import VPCSVM
class VPCS(BaseManager):
_VM_CLASS = VPCSVM
def __init__(self):
super().__init__()
self._free_mac_ids = list(range(0, 255))
self._used_mac_ids = {}
@asyncio.coroutine
def create_vm(self, *args, **kwargs):
vm = yield from super().create_vm(*args, **kwargs)
try:
self._used_mac_ids[vm.uuid] = self._free_mac_ids.pop(0)
except IndexError:
raise VPCSError("No mac address available")
return vm
@asyncio.coroutine
def delete_vm(self, uuid, *args, **kwargs):
i = self._used_mac_ids[uuid]
self._free_mac_ids.insert(0, i)
del self._used_mac_ids[uuid]
yield from super().delete_vm(uuid, *args, **kwargs)
def get_mac_id(self, vm_uuid):
"""
Get an unique VPCS mac id
:param vm_uuid: UUID of the VPCS vm
:returns: VPCS Mac id
"""
return self._used_mac_ids.get(vm_uuid, 1)
+1 -2
View File
@@ -415,8 +415,7 @@ class VPCSVM(BaseVM):
command.extend(["-e"])
command.extend(["-d", nio.tap_vm])
# FIXME: find workaround
# command.extend(["-m", str(self._id)]) # the unique ID is used to set the MAC address offset
command.extend(["-m", str(self._manager.get_mac_id(self._uuid))]) # the unique ID is used to set the MAC address offset
command.extend(["-i", "1"]) # option to start only one VPC instance
command.extend(["-F"]) # option to avoid the daemonization of VPCS
if self._script_file: