Beispiel #1
0
    def execute(self, args):
        out = vboxmanage(self, 'list', 'vms', capture=True)
        out = out.strip().splitlines()

        vmdata = []

        for line in out:
            name, uuid = line.rsplit(' ', 1)
            name = name[1:-1]
            uuid = uuid[1:-1]

            out = vboxmanage(self, 'showvminfo', name, capture=True)
            info, _ = out.split('\n\n', 1)
            vm = {}

            for line in info.splitlines():
                m = re.search(r'([^:]+):\s+(.*)', line)
                if m:
                    vm[m.group(1).lower()] = m.group(2)
            vmdata.append(vm)


        vmdata = [self.getinfo(vm) for vm in vmdata]
        headers = [
            ('ID', 'Name', 'OS', 'CPU', 'RAM', 'State'),
        ]

        output.printtable(headers + vmdata, headerrows=1)
Beispiel #2
0
    def execute(self, args):
        image = images.Manager(self.config).get(args.image)
        key = keys.Manager(self.config).get(args.key)
        preset = dict(self.config.items(Presets.prefix + args.type))
        name = args.name.replace(' ', '-')

        vboxmanage(self, 'import', image.filename(),
            '--vsys', '0',
            '--vmname', name,
            '--cpus', preset['cores'],
            '--memory', preset['memory']
        )

        properties.set(self, name, 'auth-key', key.content())
Beispiel #3
0
def get(instance, uuid, key, default=_NOT_PROVIDED):
    val = vboxmanage(instance, 'guestproperty', 'get', uuid, _key(key), capture=True)
    if val.strip() == 'No value set!':
        if default is _NOT_PROVIDED:
            raise KeyError('Property not set')
        else:
            return default
    val = val.strip().split(' ', 1)[1]
    return val
Beispiel #4
0
def list(instance, uuid):
    out = vboxmanage(instance, 'guestproperty', 'enumerate', uuid,
            '--patterns', PREFIX + '/*', capture=True)
    props = []

    for line in out.splitlines():
        if line.startswith('Name: '):
            name = line.split(' ', 2)[1][:-1]
            name = name.strip('/').split('/')[1:]
            props.append(tuple(name))

    return props
Beispiel #5
0
    def process_vm(self, name, uuid, args):
        if not os.path.exists(os.path.dirname(args.dest)):
            os.makedirs(os.path.dirname(args.dest))

        properties.unset_all(self, uuid)

        if os.path.exists(args.dest):
            if args.force:
                self.logger.info('Removing existing file at \'{}\''.format(args.dest))
                os.remove(args.dest)
            else:
                self.logger.error('Destination already exists (use -f/--force to override)')
                return


        vboxmanage(self, 'export', uuid, '-o', args.dest, '--manifest',
            '--vsys', '0',
                # TODO: Make the following values optional or coming from
                #       the configuration/command line arguments.
                '--product', 'simple-cloud Gentoo 3.7.10 Base VM + salt',
                '--vendor', 'Watersports Fashion Company Ltd.',
                '--version', '1.0rc2',
        )
Beispiel #6
0
def get_all(instance, uuid):
    out = vboxmanage(instance, 'guestproperty', 'enumerate', uuid,
            '--patterns', _key('*'), capture=True)
    lines = []

    for line in out.splitlines():
        if line.startswith('Name: '):
            lines.append(line)
        else:
            lines[-1] += line

    properties = _VMPropertiesContainer(instance, uuid)

    for line in lines:
        m = re.search('Name: (.+), value: (.+), timestamp: (\d+), flags: (.*)', line)
        name, value, timestamp, flags = m.groups()
        propmap = properties
        keys = name.strip('/').split('/')
        for k in keys[1:-1]:
            propmap = propmap[k]
            assert isinstance(propmap, _VMPropertiesContainer)
        propmap._populate(keys[-1], value)

    return properties
Beispiel #7
0
def set(instance, uuid, key, value):
    return vboxmanage(instance, 'guestproperty', 'set', uuid, _key(key), value)
Beispiel #8
0
def start_vm(instance, name, uuid, args):
    vboxmanage(instance, 'guestproperty', 'set', uuid,
            '/scloud/hostname', name)
    vboxmanage(instance, 'startvm', uuid, '--type', 'headless')
Beispiel #9
0
def destroy_vm(instance, name, uuid, args):
    vboxmanage(instance, 'unregistervm', '--delete', uuid)
Beispiel #10
0
def resume_vm(instance, name, uuid, args):
    vboxmanage(instance, 'controlvm', uuid, 'resume')
Beispiel #11
0
def pause_vm(instance, name, uuid, args):
    vboxmanage(instance, 'controlvm', uuid, 'pause')
Beispiel #12
0
def stop_vm(instance, name, uuid, args):
    vboxmanage(instance, 'controlvm', uuid, 'poweroff')
Beispiel #13
0
def save_vm(instance, name, uuid, args):
    vboxmanage(instance, 'controlvm', uuid, 'savestate')