示例#1
0
文件: status.py 项目: okfn/buildkit
def parse_vm_info(image):
    path = '/var/lib/buildkit/vm/%s/vmtmp/vm.info'%image
    if os.path.exists(path):
        fp = open(path, 'r')
        data = fp.read().split('\n')
        fp.close()
        return stacks.obj(
            pid = data[0],
            serial = data[1],
            monitor = data[2],
        )
    else:
        return stacks.obj(
            pid = None,
        )
示例#2
0
文件: start.py 项目: okfn/buildkit
def get_vm_info():
    cmd = 'ps ax -o "pid args" | grep "/bin/kvm" | grep "/var/lib/buildkit/vm"'
    result = stacks.process(
        cmd=cmd,
        shell = True,
    )
    lines = result.stdout.split('\n')
    instances = []
    for line in lines:
        if not line.strip() or cmd in line:
            continue
        parts = [part for part in line.strip().split(' ') if part]
        pid = parts[0]
        try:
            image_arg = parts[18].split('=')[1].split(',')[0].split('/')[-2]
        except:
            image_arg = 'ERROR'
        try:
            net_arg = parts[22].split(',')[1].split('=')[1]
        except:
            net_arg = 'ERROR'
        instance = stacks.obj(
            pid = pid,
            image = image_arg,
            tunnel = net_arg 
        )
        instances.append(instance)
    return instances
示例#3
0
文件: status.py 项目: okfn/buildkit
def full_info(images=None):
    if images == []:
        images = None
    vm_info = get_vm_info()
    error = None
    instances = []
    if not vm_info:
        error = 'No VMs running'
    else:
        not_running = images[:]
        for instance in vm_info:
            if images is None or instance.image in images:
                info = parse_vm_info(instance.image)
                if instance.pid != info.pid:
                    instance['serial'] = 'UNKNOWN' 
                    instance['monitor'] = 'UNKNOWN'
                else:
                    instance.update(info)
                instances.append(instance)
                not_running.pop(not_running.index(instance.image))
    if images is not None and not_running:
        error = 'The following VMs are not running: %r'%(', '.join(not_running))
    return stacks.obj(
        error=error,
        instances=instances,
    )
示例#4
0
文件: start.py 项目: okfn/buildkit
def parse_file_and_dir_specs(value):
    result = []
    for spec in value:
        pair = spec.split('->')
        if not len(pair) == 2:
            raise Exception('A spec can only contain one set of -> characters')
        src = stacks.uniform_path(pair[0].strip())
        if not os.path.exists(src):
            raise Exception('No such file or directory %r'%src)
        dst = pair[1].strip()
        if not dst.startswith('/'):
            raise Exception('The destination path must start with a / character')
        result.append(stacks.obj(src=src, dst=dst))
    return result
示例#5
0
文件: start.py 项目: okfn/buildkit
def get_bridge_info():
    result = stacks.process(
        [
            'brctl', 'show',
        ],
    )
    lines = result.stdout.split('\n')
    interfaces_pos = lines[0].find('interfaces')
    tunnels = []
    bridges = stacks.obj()
    bridge = None
    for line in lines[1:]:
        new_bridge = line.split('\t')[0].strip()
        if new_bridge:
            bridge = new_bridge
        if not bridges.has_key(bridge):
            bridges[bridge] = []
        tunnel = line.split('\t')[-1]
        if tunnel:
            bridges[bridge].append(tunnel)
            tunnels.append(tunnel)
    tunnels.sort()
    return stacks.obj(bridges=bridges, tunnels=tunnels)