示例#1
0
 def add_column(self, column):
     if not column.name_:
         raise exc.ArgumentError('Column should have a name')
     if column.name_ not in self.column_collection:
         self.column_collection[column.name_] = column
     else:
         raise exc.ArgumentError('Column "%s" is already defined'
                                 ' for table "%s"' %
                                 (column.name_, self.name_))
示例#2
0
def img_open(args):
    # TODO: check nbd module and arguments
    if len(args.values) != 1:
        raise exc.ArgumentError('missing image file')
    else:
        img_file = args.values[0]

    nbd = ModuleTool('nbd')
    if not nbd.isload():
        LOG.warning('module nbd has not been loaded, load it')
        nbd.load({'max_part': 8})
    if nbd.param_value('max_part') < 4:
        LOG.warning('the value of max_part of nbd is too small, reload this '
                    'module with a big value')
        nbd.unload()
        nbd.load({'max_part': 8})

    # TODO: do not hardcode, do not use print directly
    cmd = 'qemu-nbd -c /dev/nbd0 %s' % img_file
    (status, out) = commands.getstatusoutput(cmd)
    if status != 0:
        raise exc.OpenError(out)
    else:
        p = ConfigParser()
        p.add_section('global')
        p.set('global', 'file', img_file)
        p.set('global', 'device', '/dev/nbd0')
        p.write(open('/tmp/guest-tools.tmp', 'w'))
        img_ls(None)
示例#3
0
 def instance(url_or_conn_str=None):
     if url_or_conn_str is None and not hasattr(Connection, '_instance'):
         raise exc.ArgumentError('Connection should be first established.')
     if not hasattr(Connection, '_instance'):
         with Connection._instance_lock:
             if not hasattr(Connection, '_instance'):
                 Connection._instance = Connection(url_or_conn_str)
     return Connection._instance
示例#4
0
    def explore_database(self, schema=None):
        tables_collection = dict()
        if schema is None:
            schema = self.url.db
        tables = self.get_table_names(schema)
        for table in tables:
            if table in tables_collection:
                raise exc.ArgumentError('Table "%s" is already defined'
                                        ' in this database' % table)
            tables_collection[table] = Table(table, None)
            for column in self.get_columns(table, schema):
                tables_collection[table].add_column(column)

        return tables_collection
示例#5
0
def img_rootfs(args):
    if len(args.values) != 1:
        raise exc.ArgumentError('missing image file')
    else:
        rootfs = args.values[0]
    p = ConfigParser()
    p.read('/tmp/guest-tools.tmp')
    p.set('global', 'rootfs', rootfs)
    if args.lvm:
        p.set('global', 'lvm', args.lvm)
    p.write(open('/tmp/guest-tools.tmp', 'w'))

    # mount it, TODO: remove hard code
    if not os.path.exists('/mnt/guest-tools.mnt'):
        os.mkdir('/mnt/guest-tools.mnt')
    if args.lvm:
        # update lvm metadata
        os.system('vgchange -ay %s' % args.lvm)
        os.system('mount /dev/%s/root /mnt/guest-tools.mnt' % args.lvm)
    else:
        os.system('mount %s /mnt/guest-tools.mnt' % (rootfs))