mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2026-05-04 18:37:52 +02:00
updates
This commit is contained in:
@@ -11,8 +11,8 @@ import yaml
|
||||
|
||||
def run():
|
||||
minionid = data['id']
|
||||
hv_name = 'jppvirt'
|
||||
DATA = data['data']
|
||||
hv_name = DATA['HYPERVISOR_HOST']
|
||||
logging.error("setup reactor: %s " % DATA)
|
||||
|
||||
vm_out_data = {
|
||||
|
||||
@@ -1,32 +1,43 @@
|
||||
#!py
|
||||
|
||||
# Copyright Security Onion Solutions LLC and/or licensed to Security Onion Solutions LLC under one
|
||||
# or more contributor license agreements. Licensed under the Elastic License 2.0 as shown at
|
||||
# or more contributor license agreements. Licensed under the Elastic License 2.0 as shown at
|
||||
# https://securityonion.net/license; you may not use this file except in compliance with the
|
||||
# Elastic License 2.0.
|
||||
|
||||
import logging
|
||||
import yaml
|
||||
import os
|
||||
import glob
|
||||
|
||||
def run():
|
||||
|
||||
def release_compute(hw_type):
|
||||
def release_compute():
|
||||
compute = hv_data['hypervisor']['hardware'][hw_type]
|
||||
compute.update({'free': compute.get('free') + vm_data.get(hw_type)})
|
||||
logging.error("virtReboot reactor: claiming %s compute: %s " % (hw_type,compute))
|
||||
|
||||
def release_pci(hw_type):
|
||||
def release_pci():
|
||||
free_hw = hv_data['hypervisor']['hardware'][hw_type]['free']
|
||||
for hw in vm_data[hw_type]:
|
||||
f_hw = {hw: hv_data['hypervisor']['hardware'][hw_type]['claimed'].pop(hw)}
|
||||
free_hw.update(f_hw)
|
||||
logging.error("virtReleaseHardware reactor: released %s: %s" % (hw_type, f_hw))
|
||||
|
||||
# this could be 0 if nothing is assigned
|
||||
if vm_data[hw_type] != 0:
|
||||
for hw in vm_data[hw_type]:
|
||||
f_hw = {hw: hv_data['hypervisor']['hardware'][hw_type]['claimed'].pop(hw)}
|
||||
free_hw.update(f_hw)
|
||||
logging.error("virtReleaseHardware reactor: released %s: %s" % (hw_type, f_hw))
|
||||
|
||||
def get_hypervisor():
|
||||
base_dir = '/opt/so/saltstack/local/pillar/hypervisor'
|
||||
pattern = os.path.join(base_dir, '**', vm_name + '.sls')
|
||||
files = glob.glob(pattern, recursive=True)
|
||||
logging.error("virtReleaseHardware reactor: files: %s " % files)
|
||||
if files:
|
||||
return files[0].split('/')[7]
|
||||
|
||||
vm_name = data['name']
|
||||
hv_name = 'jppvirt'
|
||||
# since the vm has been destroyed, we can't get the hypervisor_host grain
|
||||
hv_name = get_hypervisor()
|
||||
logging.error("virtReleaseHardware reactor: hv_name: %s " % hv_name)
|
||||
|
||||
with open("/opt/so/saltstack/local/pillar/hypervisor/" + hv_name + "/" + vm_name + ".sls") as f:
|
||||
try:
|
||||
@@ -45,10 +56,10 @@ def run():
|
||||
logging.error(exc)
|
||||
|
||||
for hw_type in ['disks', 'copper', 'sfp']:
|
||||
release_pci(hw_type)
|
||||
release_pci()
|
||||
|
||||
for hw_type in ['cpu', 'memory']:
|
||||
release_compute(hw_type)
|
||||
release_compute()
|
||||
|
||||
# update the free hardware for the hypervisor
|
||||
with open("/opt/so/saltstack/local/pillar/hypervisor/" + hv_name + "/" + hv_name + ".sls", 'w') as f:
|
||||
|
||||
@@ -23,10 +23,13 @@ def run():
|
||||
# if a list of devices was defined
|
||||
if type(vm_data[hw_type]) == list:
|
||||
for hw in vm_data[hw_type]:
|
||||
c_hw = {hw: hv_data['hypervisor']['hardware'][hw_type]['free'].pop(hw)}
|
||||
claimed_hw.update(c_hw)
|
||||
host_devices.append(c_hw[hw])
|
||||
#hv_data['hypervisor']['hardware'][hw_type].update({'claimed': claimed_hw})
|
||||
try:
|
||||
c_hw = {hw: hv_data['hypervisor']['hardware'][hw_type]['free'].pop(hw)}
|
||||
claimed_hw.update(c_hw)
|
||||
host_devices.append(c_hw[hw])
|
||||
except KeyError:
|
||||
logging.error("virtUpdate reactor: could not claim %s with key %s " % (hw_type,hw))
|
||||
return {'key1': 'val1'}
|
||||
# if a number of devices was defined
|
||||
else:
|
||||
n = vm_data[hw_type]
|
||||
@@ -44,7 +47,8 @@ def run():
|
||||
logging.error("virtUpdate reactor: claimed_hw: %s " % claimed_hw)
|
||||
|
||||
vm_name = data['name']
|
||||
hv_name = 'jppvirt'
|
||||
hv_name = local.cmd(vm_name, 'grains.get', ['hypervisor_host'])
|
||||
|
||||
host_devices = []
|
||||
|
||||
with open("/opt/so/saltstack/local/pillar/hypervisor/" + hv_name + "/" + vm_name + ".sls") as f:
|
||||
@@ -63,7 +67,7 @@ def run():
|
||||
except yaml.YAMLError as exc:
|
||||
logging.error(exc)
|
||||
|
||||
local.cmd('jppvirt', 'virt.stop', ['name=' + vm_name])
|
||||
local.cmd(hv_name, 'virt.stop', ['name=' + vm_name])
|
||||
|
||||
for hw_type in ['disks', 'copper', 'sfp']:
|
||||
claim_pci(hw_type)
|
||||
@@ -85,9 +89,9 @@ def run():
|
||||
yaml.dump(vm_data, f, default_flow_style=False)
|
||||
|
||||
mem = vm_data['memory'] * 1024
|
||||
r = local.cmd('jppvirt', 'virt.update', ['name=' + vm_name, 'mem=' + str(mem), 'cpu=' + str(vm_data['cpu']), 'host_devices=' + str(host_devices)])
|
||||
r = local.cmd(hv_name, 'virt.update', ['name=' + vm_name, 'mem=' + str(mem), 'cpu=' + str(vm_data['cpu']), 'host_devices=' + str(host_devices)])
|
||||
logging.error("virtUpdate reactor: virt.update: %s" % r)
|
||||
|
||||
local.cmd('jppvirt', 'virt.start', ['name=' + vm_name])
|
||||
local.cmd(hv_name, 'virt.start', ['name=' + vm_name])
|
||||
|
||||
return {}
|
||||
|
||||
Reference in New Issue
Block a user