fixed tap id for each NIC, add more logging when VM is declared killed
This commit is contained in:
parent
66b7cf525f
commit
bbe09667a6
3 changed files with 21 additions and 12 deletions
|
@ -36,6 +36,8 @@ class CreateVM(Resource):
|
||||||
"hdd": validator.specs["hdd"],
|
"hdd": validator.specs["hdd"],
|
||||||
}
|
}
|
||||||
macs = [generate_mac() for i in range(len(data["network"]))]
|
macs = [generate_mac() for i in range(len(data["network"]))]
|
||||||
|
tap_ids = [counters.increment_etcd_counter(etcd_client, "/v1/counter/tap")
|
||||||
|
for i in range(len(data["network"]))]
|
||||||
vm_entry = {
|
vm_entry = {
|
||||||
"name": data["vm_name"],
|
"name": data["vm_name"],
|
||||||
"owner": data["name"],
|
"owner": data["name"],
|
||||||
|
@ -46,7 +48,7 @@ class CreateVM(Resource):
|
||||||
"image_uuid": validator.image_uuid,
|
"image_uuid": validator.image_uuid,
|
||||||
"log": [],
|
"log": [],
|
||||||
"vnc_socket": "",
|
"vnc_socket": "",
|
||||||
"network": list(zip(data["network"], macs)),
|
"network": list(zip(data["network"], macs, tap_ids)),
|
||||||
"metadata": {"ssh-keys": []},
|
"metadata": {"ssh-keys": []},
|
||||||
}
|
}
|
||||||
etcd_client.put(vm_key, vm_entry, value_in_json=True)
|
etcd_client.put(vm_key, vm_entry, value_in_json=True)
|
||||||
|
@ -73,8 +75,8 @@ class VmStatus(Resource):
|
||||||
)
|
)
|
||||||
vm_value = vm.value.copy()
|
vm_value = vm.value.copy()
|
||||||
vm_value["ip"] = []
|
vm_value["ip"] = []
|
||||||
for network_and_mac in vm.network:
|
for network_mac_and_tap in vm.network:
|
||||||
network_name, mac = network_and_mac
|
network_name, mac, tap = network_mac_and_tap
|
||||||
network = etcd_client.get(
|
network = etcd_client.get(
|
||||||
join_path(
|
join_path(
|
||||||
env_vars.get("NETWORK_PREFIX"),
|
env_vars.get("NETWORK_PREFIX"),
|
||||||
|
|
|
@ -63,6 +63,7 @@ def maintenance(host):
|
||||||
# initiated by user inside VM. OR crash of VM by some
|
# initiated by user inside VM. OR crash of VM by some
|
||||||
# user running process
|
# user running process
|
||||||
if (_vm and not _vm.handle.is_running()) or not _vm:
|
if (_vm and not _vm.handle.is_running()) or not _vm:
|
||||||
|
logger.debug("_vm = %s, is_running() = %s" % (_vm, _vm.handle.is_running()))
|
||||||
vm_entry.add_log("""{} is not running but is said to be running.
|
vm_entry.add_log("""{} is not running but is said to be running.
|
||||||
So, shutting it down and declare it killed""".format(vm_entry.key))
|
So, shutting it down and declare it killed""".format(vm_entry.key))
|
||||||
vm_entry.declare_killed()
|
vm_entry.declare_killed()
|
||||||
|
|
|
@ -11,9 +11,9 @@ import tempfile
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from os.path import join as join_path
|
|
||||||
from string import Template
|
from string import Template
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
from os.path import join as join_path
|
||||||
|
|
||||||
import bitmath
|
import bitmath
|
||||||
import sshtunnel
|
import sshtunnel
|
||||||
|
@ -49,7 +49,7 @@ def create_dev(script, _id, dev, ip=None):
|
||||||
return output.decode("utf-8").strip()
|
return output.decode("utf-8").strip()
|
||||||
|
|
||||||
|
|
||||||
def create_vxlan_br_tap(_id, _dev, ip=None):
|
def create_vxlan_br_tap(_id, _dev, tap_id, ip=None):
|
||||||
network_script_base = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'network')
|
network_script_base = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'network')
|
||||||
vxlan = create_dev(script=os.path.join(network_script_base, 'create-vxlan.sh'),
|
vxlan = create_dev(script=os.path.join(network_script_base, 'create-vxlan.sh'),
|
||||||
_id=_id, dev=_dev)
|
_id=_id, dev=_dev)
|
||||||
|
@ -58,7 +58,7 @@ def create_vxlan_br_tap(_id, _dev, ip=None):
|
||||||
_id=_id, dev=vxlan, ip=ip)
|
_id=_id, dev=vxlan, ip=ip)
|
||||||
if bridge:
|
if bridge:
|
||||||
tap = create_dev(script=os.path.join(network_script_base, 'create-tap.sh'),
|
tap = create_dev(script=os.path.join(network_script_base, 'create-tap.sh'),
|
||||||
_id=str(random.randint(1, 100000)), dev=bridge)
|
_id=str(tap_id), dev=bridge)
|
||||||
if tap:
|
if tap:
|
||||||
return tap
|
return tap
|
||||||
|
|
||||||
|
@ -108,6 +108,7 @@ def update_radvd_conf(etcd_client):
|
||||||
except Exception:
|
except Exception:
|
||||||
sp.check_output(['service', 'radvd', 'restart'])
|
sp.check_output(['service', 'radvd', 'restart'])
|
||||||
|
|
||||||
|
|
||||||
def get_start_command_args(vm_entry, vnc_sock_filename: str, migration=False, migration_port=None):
|
def get_start_command_args(vm_entry, vnc_sock_filename: str, migration=False, migration_port=None):
|
||||||
threads_per_core = 1
|
threads_per_core = 1
|
||||||
vm_memory = int(bitmath.parse_string_unsafe(vm_entry.specs["ram"]).to_MB())
|
vm_memory = int(bitmath.parse_string_unsafe(vm_entry.specs["ram"]).to_MB())
|
||||||
|
@ -129,8 +130,8 @@ def get_start_command_args(vm_entry, vnc_sock_filename: str, migration=False, mi
|
||||||
command += " -incoming tcp:[::]:{}".format(migration_port)
|
command += " -incoming tcp:[::]:{}".format(migration_port)
|
||||||
|
|
||||||
tap = None
|
tap = None
|
||||||
for network_and_mac in vm_networks:
|
for network_mac_and_tap in vm_networks:
|
||||||
network_name, mac = network_and_mac
|
network_name, mac, tap = network_mac_and_tap
|
||||||
|
|
||||||
_key = os.path.join(env_vars.get('NETWORK_PREFIX'), vm_entry.owner, network_name)
|
_key = os.path.join(env_vars.get('NETWORK_PREFIX'), vm_entry.owner, network_name)
|
||||||
network = etcd_client.get(_key, value_in_json=True)
|
network = etcd_client.get(_key, value_in_json=True)
|
||||||
|
@ -139,7 +140,10 @@ def get_start_command_args(vm_entry, vnc_sock_filename: str, migration=False, mi
|
||||||
network_ipv6 = network.value["ipv6"]
|
network_ipv6 = network.value["ipv6"]
|
||||||
|
|
||||||
if network_type == "vxlan":
|
if network_type == "vxlan":
|
||||||
tap = create_vxlan_br_tap(network_id, env_vars.get("VXLAN_PHY_DEV"), network_ipv6)
|
tap = create_vxlan_br_tap(_id=network_id,
|
||||||
|
_dev=env_vars.get("VXLAN_PHY_DEV"),
|
||||||
|
tap_id=tap,
|
||||||
|
ip=network_ipv6)
|
||||||
update_radvd_conf(etcd_client)
|
update_radvd_conf(etcd_client)
|
||||||
|
|
||||||
command += " -netdev tap,id=vmnet{net_id},ifname={tap},script=no,downscript=no" \
|
command += " -netdev tap,id=vmnet{net_id},ifname={tap},script=no,downscript=no" \
|
||||||
|
@ -237,10 +241,12 @@ def delete(vm_entry):
|
||||||
logger.info("Deleting VM | %s", vm_entry)
|
logger.info("Deleting VM | %s", vm_entry)
|
||||||
stop(vm_entry)
|
stop(vm_entry)
|
||||||
|
|
||||||
|
if image_storage_handler.is_vm_image_exists(vm_entry.uuid):
|
||||||
r_status = image_storage_handler.delete_vm_image(vm_entry.uuid)
|
r_status = image_storage_handler.delete_vm_image(vm_entry.uuid)
|
||||||
if r_status:
|
if r_status:
|
||||||
etcd_client.client.delete(vm_entry.key)
|
etcd_client.client.delete(vm_entry.key)
|
||||||
|
else:
|
||||||
|
etcd_client.client.delete(vm_entry.key)
|
||||||
|
|
||||||
def transfer(request_event):
|
def transfer(request_event):
|
||||||
# This function would run on source host i.e host on which the vm
|
# This function would run on source host i.e host on which the vm
|
||||||
|
|
Loading…
Reference in a new issue