Home | Trees | Indices | Help |
---|
|
1 # 2 # Uncomplicated VM Builder 3 # Copyright (C) 2007-2008 Canonical Ltd. 4 # 5 # See AUTHORS for list of contributors 6 # 7 # This program is free software: you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation, either version 3 of the License, or 10 # (at your option) any later version. 11 # 12 # This program is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 19 # 20 from VMBuilder import register_plugin, Plugin, VMBuilderUserError 21 import VMBuilder.util 2224 name = 'libvirt integration' 2568 69 register_plugin(Libvirt) 7027 group = self.vm.setting_group('libvirt integration') 28 group.add_option('--libvirt', metavar='URI', help='Add VM to given URI') 29 group.add_option('--bridge', metavar="BRIDGE", help='Set up bridged network connected to BRIDGE.') 30 self.vm.register_setting_group(group)3133 # This does not seem to work when any domain is already running 34 return self.conn.listDefinedDomains() + [self.conn.lookupByID(id).name() for id in self.conn.listDomainsID()]3537 if not self.vm.libvirt: 38 return True 39 40 import libvirt 41 42 self.conn = libvirt.open(self.vm.libvirt) 43 if self.vm.hostname in self.all_domains() and not self.vm.overwrite: 44 raise VMBuilderUserError('Domain %s already exists at %s' % (self.vm.hostname, self.vm.libvirt)) 45 46 if not self.vm.hypervisor.name == 'KVM': 47 raise VMBuilderUserError('The libvirt plugin is only equiped to work with KVM at the moment.') 48 49 if not self.vm.hypervisor.name == 'KVM': 50 raise VMBuilderUserError('The libvirt plugin is only equiped to work with KVM at the moment.')5153 if not self.vm.libvirt: 54 # Not for us 55 return False 56 57 if self.vm.hypervisor.preferred_storage == VMBuilder.hypervisor.STORAGE_FS_IMAGE: 58 vmxml = VMBuilder.util.render_template('libvirt', self.vm, 'libvirtxml_fsimage') 59 else: 60 vmxml = VMBuilder.util.render_template('libvirt', self.vm, 'libvirtxml') 61 62 if self.vm.hostname in self.all_domains() and not self.vm.overwrite: 63 raise VMBuilderUserError('Domain %s already exists at %s' % (self.vm.hostname, self.vm.libvirt)) 64 else: 65 self.conn.defineXML(vmxml) 66 67 return True
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Fri Apr 10 21:15:37 2009 | http://epydoc.sourceforge.net |