Ask Your Question
0

nova-manage and libvirt_type flag

asked 2012-02-09 18:28:45 -0500

armando-migliaccio gravatar image

Is there any reason why the flag libvirt_type is declared on nova-manage?

flags.DECLARE('libvirt_type', 'nova.virt.libvirt.connection')

Can't we do without? I see no reason we couldn't just use FLAGS.libvirt_type and rely on the flag file definition.

Thanks, Armando

edit retag flag offensive close merge delete

4 answers

Sort by ยป oldest newest most voted
0

answered 2012-02-13 10:54:33 -0500

armando-migliaccio gravatar image

Thanks Mark McLoughlin, that solved my question.

edit flag offensive delete link more
0

answered 2012-02-10 11:36:06 -0500

markmc gravatar image

bin/nova-manage uses libvirt_type here:

    if (FLAGS.connection_type != 'libvirt' or
       (FLAGS.connection_type == 'libvirt' and
        FLAGS.libvirt_type not in ['kvm', 'qemu'])):
        msg = _('Only KVM and QEmu are supported for now. Sorry!')
        raise exception.Error(msg)

in order for --libvirt_type to be parsed from the command line or the contents of the flagfile, the option has to be registered before it is referenced in the code above

the option is registered in nova/virt/libvirt/connection.py:

  cfg.StrOpt('libvirt_type',

FLAGS = flags.FLAGS FLAGS.add_options(libvirt_opts)

i.e. you need to import nova.virt.libvirt.connection in order for the option to be registered

Rather than import the module into the namespace, we use flags.DECLARE() to do this - all it does is import the module and check that the option has been registered:

def DECLARE(name, module_string, flag_values=FLAGS): if module_string not in sys.modules: __import__(module_string, globals(), locals()) if name not in flag_values: raise UnrecognizedFlag('%s not defined by %s' % (name, module_string))

We don't need to declare options like connection_type because that is registered when we import the nova.flags module

edit flag offensive delete link more
0

answered 2012-02-10 12:40:02 -0500

armando-migliaccio gravatar image

Hi Mark,

thanks for the exhaustive reply! I was asking because I believe that nova-manage shouldn't be loading the entire libvirt module, just for retrieving a simply flag. In principle, the tool should be agnostic to underlying implementation details (e.g. hypervisors, networking etc), but I can see why you need it in this case.

Besides, if I don't have libvirt installed on my box (e.g. because I use xenserver/xpc or vmware) and I see these all sorts of logging traces about libvirt:

No handlers could be found for logger "nova.virt.libvirt.firewall" WARNING Libvirt module could not be loaded. NWFilterFirewall will not work correctly. ...

I wonder if this should be avoided.

edit flag offensive delete link more
0

answered 2012-02-10 14:00:36 -0500

markmc gravatar image

"nova-manage prints libvirt related warnings if libvirt isn't installed" is certainly a valid bug IMHO

This would work:

   def is_libvirt_kvm_or_qemu():
       if FLAGS.connection_type != 'libvirt':
           return False

       flags.DECLARE('libvirt_type', 'nova.virt.libvirt.connection')

       return FLAGS.libvirt_type in ['kvm', 'qemu']

    if not is_libvirt_kvm_or_qermu():
        msg = _('Only KVM and QEmu are supported for now. Sorry!')
        raise exception.Error(msg)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2012-02-09 18:28:45 -0500

Seen: 161 times

Last updated: Feb 13 '12