Exemple #1
0
def apply_profile(profile, container):
    """
    apply config and devices to container
    """
    # STORAGE_CONFIG
    VM_ID = profile['VM_ID']
    DS_ID = profile['DS_ID']
    DISK_TYPE = profile['DISK_TYPE']
    DISK_SOURCE = profile['DISK_SOURCE']
    DISK_CLONE = profile['DISK_CLONE']
    # rootfs
    root_source = lc.storage_rootfs_mount(VM_ID, DISK_TYPE[0], DS_ID,
                                          DISK_SOURCE[0], DISK_CLONE[0])
    profile['config'].append(root_source)

    if profile['CONTEXT_DISK_ID']:
        CONTEXT_DISK_ID = profile['CONTEXT_DISK_ID']
        DS_ID = profile['DS_ID']
        DS_LOCATION = '/var/lib/one/datastores/' + DS_ID + '/' + VM_ID + '/'
        # push context files into the container
        contextiso = lc.isoparser.parse(DS_LOCATION + 'disk.' +
                                        CONTEXT_DISK_ID)
        lc.storage_context(container, contextiso)

    # FIXME: duplicated block of code
    for i in profile['config']:
        try:
            container.config.update(i)
            container.save(wait=True)
        except LXDAPIException as lxdapie:
            lc.log_function('ERROR',
                            'container: ' + i.keys()[0] + ': ' + str(lxdapie))
            lc.sys.exit(1)

    for i in profile['devices']:
        try:
            container.devices.update(i)
            container.save(wait=True)
        except LXDAPIException as lxdapie:
            lc.log_function('ERROR',
                            'container: ' + i.keys()[0] + ': ' + str(lxdapie))
            lc.sys.exit(1)
Exemple #2
0
#!/usr/bin/python

import lxd_common as lc

t0 = lc.time()

DOMAIN = lc.sys.argv[1]
HOST = lc.sys.argv[2]
VM_ID = lc.sys.argv[3]

client = lc.Client()
container = client.containers.get(DOMAIN)
lc.log_function(lc.separator)

dicc = lc.xml_start(container.config['user.xml'])

# CONTAINER_SHUTDOWN
signal = lc.sys.argv[4].split("/")[-1]
if signal == "cancel":
    container.stop(force=True, wait=True)
elif signal == "shutdown":
    container.stop(wait=True)
else:
    lc.log_function("Unknown kill VM signal given", 'e')
    lc.sys.exit(1)
lc.container_wipe(container, dicc)

lc.clock(t0)
Exemple #3
0
            container.config.update(i)
            container.save(wait=True)
        except lc.LXDAPIException as lxdapie:
            lc.log_function(i.keys()[0] + ': ' + str(lxdapie), 'e')
            lc.sys.exit(1)

    for i in profile['devices']:
        try:
            container.devices.update(i)
            container.save(wait=True)
        except lc.LXDAPIException as lxdapie:
            lc.log_function(i.keys()[0] + ': ' + str(lxdapie), 'e')
            lc.sys.exit(1)


lc.log_function(lc.separator)

# INITIALIZE_CONTAINER
# xml is passed by opennebula as argument ex. deployment.0
profile = create_profile(lc.sys.argv[1])
VM_NAME = 'one-' + profile['VM_ID']
init = {'name': VM_NAME, 'source': {'type': 'none'}}

try:
    container = client.containers.create(init, wait=True)
except lc.LXDAPIException as lxdapie:  # probably this container already exists
    container = client.containers.get(VM_NAME)
    if container.status == 'Running':
        lc.log_function("A container with the same ID is already running", 'e')
        lc.sys.exit(1)
apply_profile(profile, container)
Exemple #4
0
            container.save(wait=True)
        except LXDAPIException as lxdapie:
            lc.log_function('ERROR',
                            'container: ' + i.keys()[0] + ': ' + str(lxdapie))
            lc.sys.exit(1)


# READ_XML
xml = lc.sys.argv[1]

profile = create_profile(xml)

VM_ID = profile['VM_ID']
VM_NAME = 'one-' + VM_ID

lc.log_function('INFO', 40 * "#")

# INITIALIZE_CONTAINER
init = {'name': VM_NAME, 'source': {'type': 'none'}}
try:
    container = client.containers.create(init, wait=True)
except LXDAPIException as lxdapie:
    # probably this container already exists
    lc.log_function('INFO', 'container: ' + VM_NAME + ' ' + str(lxdapie))
    container = client.containers.get(VM_NAME)

# BOOT_CONTAINER
apply_profile(profile, container)
try:
    container.start(wait=True)
    container.config['user.xml']  # validate config
Exemple #5
0
# -------------------------------------------------------------------------- #

import lxd_common as lc
t0 = lc.time()
from lxd_common import xml_query_list as xql
from lxd_common import xml_query_dict as xqd
from lxd_common import xml_query_item as xqi
client = lc.Client()

# READ_XML
xml = lc.sys.argv[1]
dicc = lc.xml_start(xml)
VM_ID = dicc["/VM/ID"][0]

# lc.log_info(70 * "-", VM_ID)
lc.log_function('INFO', 70 * "-")

# INITIALIZE_CONTAINER
try:
    container = client.containers.create(
        {
            'name': 'one-' + VM_ID,
            'source': {
                'type': 'none'
            }
        }, wait=True)
except:
    container = client.containers.get('one-' + VM_ID)

# GENERAL_CONFIG
MEMORY = lc.map_ram(xqi('MEMORY', dicc))