def find_vm_size_limits(vm): global pv_kernel_max_size, pv_initrd_max_size store = xs.xs() try: domains = store.ls("", "/vm/" + vm + "/domains") domid = int(domains[0], 10) except (ValueError, TypeError, IndexError, xs.Error): raise APILevelException("Unable to find domid for " + vm) xs_path = "/local/domain/%s/platform/pv-%s-max-size" try: pv_kernel_max_size = int(store.read("", xs_path % (domid, "kernel")), 10) except (ValueError, TypeError, xs.Error): pass try: pv_initrd_max_size = int(store.read("", xs_path % (domid, "ramdisk")), 10) except (ValueError, TypeError, xs.Error): pass xcp.logger.debug("VM limits: kernel %d, ramdisk %d" % (pv_kernel_max_size, pv_initrd_max_size))
def getTTYByDomID(DomID): sock = xs.xs() trans = sock.transaction_start() path = sock.get_domain_path(DomID) pty = sock.read(trans, path + "/console/tty") sock.transaction_end(trans) return pty
def getDomIDFromName(DomName): found = -1 sock = xs.xs() trans = sock.transaction_start() domains = sock.ls(trans, "/local/domain") for domid in domains: path = "/local/domain/" + domid + "/name" name = sock.read(trans, path) if name == DomName: found = domid sock.transaction_end(trans) return found
def find_host_size_limits(): global pv_kernel_max_size, pv_initrd_max_size store = xs.xs() try: pv_kernel_max_size = int(store.read("", "/mh/limits/pv-kernel-max-size"), 10 ) except (ValueError, TypeError, xs.Error): pass try: pv_initrd_max_size = int(store.read("", "/mh/limits/pv-ramdisk-max-size"), 10 ) except (ValueError, TypeError, xs.Error): pass xcp.logger.debug("Host limits: kernel %d, ramdisk %d" % (pv_kernel_max_size, pv_initrd_max_size))
def __init__(self, receive_prefix = "data/host", send_prefix = "data/guest", data_prefix = "vm-data", *args, **kwargs): # pylint: disable=C0301 """Initialize a communication "bus" with the Xen Hypervisor. ### Description Sets up watches on paths we'll be receiving data on in xenstore and initializes pathing information used elsewhere. """ super(XenCommunicator, self).__init__(*args, **kwargs) self._receive_prefix = receive_prefix self._send_prefix = send_prefix self._data_prefix = data_prefix self.xs = xs.xs() # pylint: disable=C0103 self.xs.watch(self._receive_prefix, "COMMAND") self.xs.watch(self._data_prefix, "DATA")
#!/usr/bin/env python import argparse import threading import logging import subprocess from scapy.all import Ether, IP, sendp from scapy.contrib.igmp import IGMP from xcp import logger as log import sys import os from xen.lowlevel.xs import xs # global xenstore handler g_xs_handler = xs() VIF_CONNECTED_STATE = '4' class XSWatcher(object): """Tool for watching xenstore """ def __init__(self): self.watches = dict() def watch(self, path, token): self.watches[path] = token return g_xs_handler.watch(path, token) def unwatch(self, path, token): self.watches.pop(path) return g_xs_handler.unwatch(path, token)