# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. # NOTE: XenServer still only supports Python 2.4 in it's dom0 userspace # which means the Nova xenapi plugins must use only Python 2.4 features """ XenAPI Plugin for transferring data between host nodes """ import utils import pluginlib_nova pluginlib_nova.configure_logging('migration') logging = pluginlib_nova.logging def move_vhds_into_sr(session, instance_uuid, sr_path, uuid_stack): """Moves the VHDs from their copied location to the SR.""" staging_path = "/images/instance%s" % instance_uuid imported_vhds = utils.import_vhds(sr_path, staging_path, uuid_stack) utils.cleanup_staging_area(staging_path) return imported_vhds def _rsync_vhds(instance_uuid, host, staging_path, user="******"): if not staging_path.endswith('/'): staging_path += '/'
# Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. # NOTE: XenServer still only supports Python 2.4 in it's dom0 userspace # which means the Nova xenapi plugins must use only Python 2.4 features """ XenAPI Plugin for transferring data between host nodes """ import utils import pluginlib_nova pluginlib_nova.configure_logging('migration') logging = pluginlib_nova.logging def move_vhds_into_sr(session, instance_uuid, sr_path, uuid_stack): """Moves the VHDs from their copied location to the SR.""" staging_path = "/images/instance%s" % instance_uuid imported_vhds = utils.import_vhds(sr_path, staging_path, uuid_stack) utils.cleanup_staging_area(staging_path) return imported_vhds def _rsync_vhds(instance_uuid, host, staging_path, user="******"): if not staging_path.endswith('/'): staging_path += '/'
# NOTE: XenServer still only supports Python 2.4 in it's dom0 userspace # which means the Nova xenapi plugins must use only Python 2.4 features # TODO(sfinucan): Resolve all 'noqa' items once the above is no longer true """Inject network configuration into iPXE ISO for boot.""" import logging import os import shutil import utils # FIXME(sirp): should this use pluginlib from 5.6? import pluginlib_nova pluginlib_nova.configure_logging('ipxe') ISOLINUX_CFG = """SAY iPXE ISO boot image TIMEOUT 30 DEFAULT ipxe.krn LABEL ipxe.krn KERNEL ipxe.krn INITRD netcfg.ipxe """ NETCFG_IPXE = """#!ipxe :start imgfree ifclose net0 set net0/ip %(ip_address)s
# which means the Nova xenapi plugins must use only Python 2.4 features # TODO(sfinucan): Resolve all 'noqa' items once the above is no longer true """Handle the manipulation of kernel images.""" import errno import os import shutil import XenAPIPlugin import pluginlib_nova pluginlib_nova.configure_logging('kernel') logging = pluginlib_nova.logging exists = pluginlib_nova.exists optional = pluginlib_nova.optional with_vdi_in_dom0 = pluginlib_nova.with_vdi_in_dom0 KERNEL_DIR = '/boot/guest' def _copy_vdi(dest, copy_args): vdi_uuid = copy_args['vdi_uuid'] vdi_size = copy_args['vdi_size'] cached_image = copy_args['cached-image'] logging.debug("copying kernel/ramdisk file from %s to /boot/guest/%s",
# License for the specific language governing permissions and limitations # under the License. # NOTE: XenServer still only supports Python 2.4 in it's dom0 userspace # which means the Nova xenapi plugins must use only Python 2.4 features """Fetch Bandwidth data from VIF network devices.""" import utils import pluginlib_nova import re pluginlib_nova.configure_logging('bandwidth') def _read_proc_net(): f = open('/proc/net/dev', 'r') try: return f.readlines() finally: f.close() def _get_bandwitdth_from_proc(): devs = [l.strip() for l in _read_proc_net()] # ignore headers devs = devs[2:] vif_pattern = re.compile("^vif(\d+)\.(\d+)")
# # XenAPI plugin for reading/writing information to xenstore # import base64 import commands # noqa try: import json except ImportError: import simplejson as json import time import XenAPIPlugin import pluginlib_nova pluginlib_nova.configure_logging("agent") import xenstore DEFAULT_TIMEOUT = 30 PluginError = pluginlib_nova.PluginError _ = pluginlib_nova._ class TimeoutError(StandardError): pass class RebootDetectedError(StandardError): pass
# XenAPI plugin for reading/writing information to xenstore # try: import json except ImportError: import simplejson as json import logging import os import subprocess import XenAPIPlugin import pluginlib_nova as pluginlib pluginlib.configure_logging("xenstore") class XenstoreError(pluginlib.PluginError): """Errors that occur when calling xenstore-* through subprocesses""" def __init__(self, cmd, return_code, stderr, stdout): msg = "cmd: %s; returncode: %d; stderr: %s; stdout: %s" msg = msg % (cmd, return_code, stderr, stdout) self.cmd = cmd self.return_code = return_code self.stderr = stderr self.stdout = stdout pluginlib.PluginError.__init__(self, msg) def jsonify(fnc):
# NOTE: XenServer still only supports Python 2.4 in it's dom0 userspace # which means the Nova xenapi plugins must use only Python 2.4 features # TODO(sfinucan): Resolve all 'noqa' items once the above is no longer true """Handle the manipulation of kernel images.""" import errno import os import shutil import XenAPIPlugin import pluginlib_nova pluginlib_nova.configure_logging('kernel') logging = pluginlib_nova.logging exists = pluginlib_nova.exists optional = pluginlib_nova.optional with_vdi_in_dom0 = pluginlib_nova.with_vdi_in_dom0 KERNEL_DIR = '/boot/guest' def _copy_vdi(dest, copy_args): vdi_uuid = copy_args['vdi_uuid'] vdi_size = copy_args['vdi_size'] cached_image = copy_args['cached-image'] logging.debug("copying kernel/ramdisk file from %s to /boot/guest/%s", dest, vdi_uuid)
You should ensure appropriate log rotation to ensure guests are not able to consume too much Dom0 disk space, and equally should not be able to stop other guests from logging. Adding and removing the following xenstore key will reopen the log, as will be required after a log rotate: /local/logconsole/<dom_id> """ import base64 import logging import zlib import XenAPIPlugin import pluginlib_nova pluginlib_nova.configure_logging("console") CONSOLE_LOG_DIR = '/var/log/xen/guest' CONSOLE_LOG_FILE_PATTERN = CONSOLE_LOG_DIR + '/console.%d' MAX_CONSOLE_BYTES = 102400 SEEK_SET = 0 SEEK_END = 2 def _last_bytes(file_like_object): try: file_like_object.seek(-MAX_CONSOLE_BYTES, SEEK_END) except IOError, e: # noqa if e.errno == 22: file_like_object.seek(0, SEEK_SET)
# under the License. # NOTE: XenServer still only supports Python 2.4 in it's dom0 userspace # which means the Nova xenapi plugins must use only Python 2.4 features """Handle the uploading and downloading of images via Glance.""" import os import shutil import utils import pluginlib_nova pluginlib_nova.configure_logging('workarounds') def _copy_vdis(sr_path, staging_path, vdi_uuids): seq_num = 0 for vdi_uuid in vdi_uuids: src = os.path.join(sr_path, "%s.vhd" % vdi_uuid) dst = os.path.join(staging_path, "%d.vhd" % seq_num) shutil.copyfile(src, dst) seq_num += 1 def safe_copy_vdis(session, sr_path, vdi_uuids, uuid_stack): staging_path = utils.make_staging_area(sr_path) try: _copy_vdis(sr_path, staging_path, vdi_uuids)
from six.moves import http_client as httplib try: import json except ImportError: import simplejson as json import md5 # noqa import socket import urllib2 from urlparse import urlparse import pluginlib_nova import utils pluginlib_nova.configure_logging('glance') logging = pluginlib_nova.logging PluginError = pluginlib_nova.PluginError SOCKET_TIMEOUT_SECONDS = 90 class RetryableError(Exception): pass def _create_connection(scheme, netloc): if scheme == 'https': conn = httplib.HTTPSConnection(netloc) else: conn = httplib.HTTPConnection(netloc)
# XenAPI plugin for reading/writing information to xenstore # import base64 import commands # noqa try: import json except ImportError: import simplejson as json import time import XenAPIPlugin import pluginlib_nova pluginlib_nova.configure_logging("agent") import xenstore DEFAULT_TIMEOUT = 30 PluginError = pluginlib_nova.PluginError _ = pluginlib_nova._ class TimeoutError(StandardError): pass class RebootDetectedError(StandardError): pass
import errno import inspect import os import random import shutil import tempfile import time import libtorrent import urllib2 import utils import pluginlib_nova pluginlib_nova.configure_logging('bittorrent') logging = pluginlib_nova.logging # Taken from units since we don't pull down full library Mi = 1024**2 DEFAULT_TORRENT_CACHE = '/images/torrents' DEFAULT_SEED_CACHE = '/images/seeds' SEEDER_PROCESS = '_bittorrent_seeder.py' DEFAULT_MMA = int(libtorrent.bandwidth_mixed_algo_t.prefer_tcp) DEFAULT_MORQ = 400 DEFAULT_MQDB = 8 * Mi DEFAULT_MQDBLW = 0 def _make_torrent_cache(): torrent_cache_path = os.environ.get('TORRENT_CACHE', DEFAULT_TORRENT_CACHE)
# NOTE: XenServer still only supports Python 2.4 in it's dom0 userspace # which means the Nova xenapi plugins must use only Python 2.4 features # TODO(sfinucan): Resolve all 'noqa' items once the above is no longer true """Seed a bittorent image. This file should not be executed directly, rather it should be kicked off by the `bittorent` dom0 plugin.""" import os import sys import time import libtorrent import pluginlib_nova pluginlib_nova.configure_logging('_bittorrent_seeder') logging = pluginlib_nova.logging def _daemonize(stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'): """Daemonize the current process. Do the UNIX double-fork magic, see Stevens' "Advanced Programming in the UNIX Environment" for details (ISBN 0201563177). Source: http://www.jejik.com/articles/2007/02/ a_simple_unix_linux_daemon_in_python/ """ # 1st fork try: pid = os.fork()
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. # NOTE: XenServer still only supports Python 2.4 in it's dom0 userspace # which means the Nova xenapi plugins must use only Python 2.4 features import logging import os import time import pluginlib_nova as pluginlib import utils pluginlib.configure_logging("disk_utils") _ = pluginlib._ def wait_for_dev(session, dev_path, max_seconds): for i in range(0, max_seconds): if os.path.exists(dev_path): return dev_path time.sleep(1) return "" def make_partition(session, dev, partition_start, partition_end): dev_path = utils.make_dev_path(dev)
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. # NOTE: XenServer still only supports Python 2.4 in it's dom0 userspace # which means the Nova xenapi plugins must use only Python 2.4 features """Handle the uploading and downloading of images via Glance.""" import os import shutil import utils import pluginlib_nova pluginlib_nova.configure_logging('workarounds') def _copy_vdis(sr_path, staging_path, vdi_uuids): seq_num = 0 for vdi_uuid in vdi_uuids: src = os.path.join(sr_path, "%s.vhd" % vdi_uuid) dst = os.path.join(staging_path, "%d.vhd" % seq_num) shutil.copyfile(src, dst) seq_num += 1 def safe_copy_vdis(session, sr_path, vdi_uuids, uuid_stack): staging_path = utils.make_staging_area(sr_path) try: _copy_vdis(sr_path, staging_path, vdi_uuids)
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. # NOTE: XenServer still only supports Python 2.4 in it's dom0 userspace # which means the Nova xenapi plugins must use only Python 2.4 features """Fetch Bandwidth data from VIF network devices.""" import utils import pluginlib_nova import re pluginlib_nova.configure_logging('bandwidth') def _read_proc_net(): f = open('/proc/net/dev', 'r') try: return f.readlines() finally: f.close() def _get_bandwitdth_from_proc(): devs = [l.strip() for l in _read_proc_net()] # ignore headers devs = devs[2:] vif_pattern = re.compile("^vif(\d+)\.(\d+)")
# # XenAPI plugin for reading/writing information to xenstore # try: import json except ImportError: import simplejson as json import utils # noqa import XenAPIPlugin # noqa import pluginlib_nova as pluginlib # noqa pluginlib.configure_logging("xenstore") class XenstoreError(pluginlib.PluginError): """Errors that occur when calling xenstore-* through subprocesses.""" def __init__(self, cmd, return_code, stderr, stdout): msg = "cmd: %s; returncode: %d; stderr: %s; stdout: %s" msg = msg % (cmd, return_code, stderr, stdout) self.cmd = cmd self.return_code = return_code self.stderr = stderr self.stdout = stdout pluginlib.PluginError.__init__(self, msg)
import inspect import os import random import shutil import tempfile import time import libtorrent import urllib2 import utils import pluginlib_nova pluginlib_nova.configure_logging('bittorrent') logging = pluginlib_nova.logging # Taken from units since we don't pull down full library Mi = 1024 ** 2 DEFAULT_TORRENT_CACHE = '/images/torrents' DEFAULT_SEED_CACHE = '/images/seeds' SEEDER_PROCESS = '_bittorrent_seeder.py' DEFAULT_MMA = int(libtorrent.bandwidth_mixed_algo_t.prefer_tcp) DEFAULT_MORQ = 400 DEFAULT_MQDB = 8 * Mi DEFAULT_MQDBLW = 0 def _make_torrent_cache(): torrent_cache_path = os.environ.get(
# NOTE: XenServer still only supports Python 2.4 in it's dom0 userspace # which means the Nova xenapi plugins must use only Python 2.4 features # TODO(sfinucan): Resolve all 'noqa' items once the above is no longer true """Inject network configuration into iPXE ISO for boot.""" import logging import os import shutil import utils # FIXME(sirp): should this use pluginlib from 5.6? import pluginlib_nova pluginlib_nova.configure_logging('ipxe') ISOLINUX_CFG = """SAY iPXE ISO boot image TIMEOUT 30 DEFAULT ipxe.krn LABEL ipxe.krn KERNEL ipxe.krn INITRD netcfg.ipxe """ NETCFG_IPXE = """#!ipxe :start imgfree ifclose net0 set net0/ip %(ip_address)s set net0/netmask %(netmask)s
try: import json except ImportError: import simplejson as json import md5 # noqa import socket import urllib2 from urlparse import urlparse import pluginlib_nova import utils pluginlib_nova.configure_logging("glance") logging = pluginlib_nova.logging PluginError = pluginlib_nova.PluginError SOCKET_TIMEOUT_SECONDS = 90 class RetryableError(Exception): pass def _create_connection(scheme, netloc): if scheme == "https": conn = httplib.HTTPSConnection(netloc) else: conn = httplib.HTTPConnection(netloc)
import sys import time import utils import pluginlib_nova as pluginlib import XenAPI import XenAPIPlugin try: import xmlrpclib except ImportError: import six.moves.xmlrpc_client as xmlrpclib pluginlib.configure_logging("xenhost") _ = pluginlib._ host_data_pattern = re.compile(r"\s*(\S+) \([^\)]+\) *: ?(.*)") config_file_path = "/usr/etc/xenhost.conf" DEFAULT_TRIES = 23 DEFAULT_SLEEP = 10 def jsonify(fnc): def wrapper(*args, **kwargs): return json.dumps(fnc(*args, **kwargs)) return wrapper
# TODO(sfinucan): Resolve all 'noqa' items once the above is no longer true """Seed a bittorent image. This file should not be executed directly, rather it should be kicked off by the `bittorent` dom0 plugin.""" import os import sys import time import libtorrent import pluginlib_nova pluginlib_nova.configure_logging('_bittorrent_seeder') logging = pluginlib_nova.logging def _daemonize(stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'): """Daemonize the current process. Do the UNIX double-fork magic, see Stevens' "Advanced Programming in the UNIX Environment" for details (ISBN 0201563177). Source: http://www.jejik.com/articles/2007/02/ a_simple_unix_linux_daemon_in_python/ """ # 1st fork try: pid = os.fork()