Example #1
0
def create_filter(**kwargs):
    conditions = ['1']
    for key in kwargs:
        if key.startswith('!'):
            continue
        conditions.append('$_.%s -eq %s' % (key, escape(str(kwargs[key]))))
    filter = '? { %s }' % ' -and '.join(conditions)
    return filter
Example #2
0
def create_setattr(obj, **kwargs):
    statements = []
    for key in kwargs:
        if key.startswith('!'):
            continue
        value = kwargs[key]
        statements.append('$%s.%s = %s' % (obj, key, escape(str(value))))
    statement = ';'.join(statements) + ';'
    return statement
Example #3
0
def create_cmdline(**kwargs):
    arguments = []
    for key in kwargs:
        value = kwargs[key]
        if key.startswith('!'):
            continue
        elif value is None:
            pass
        elif value is True:
            arguments.append('-%s' % key)
        elif key.endswith('Object'):
            # XXX: ugly hack:
            arguments.append('-%s %s' % (key, value))
        else:
            arguments.append('-%s %s' % (key, escape(str(value))))
    cmdline = ' '.join(arguments)
    return cmdline
Example #4
0
 def list(self, **filter):
     query = filter.pop('query', 'vms:')
     filter = create_filter(**filter)
     result = powershell.execute('Select-Vm -SearchText %s | %s'
                                 % (escape(query), filter))
     return result