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' 2564 65 register_plugin(Libvirt) 6627 group = self.vm.setting_group('libvirt integration') 28 group.add_option('--libvirt', metavar='URI', help='Add VM to given URI') 29 self.vm.register_setting_group(group)3032 # This does not seem to work when any domain is already running 33 return self.conn.listDefinedDomains() + [self.conn.lookupByID(id).name() for id in self.conn.listDomainsID()]3436 if not self.vm.libvirt: 37 return True 38 39 import libvirt 40 41 self.conn = libvirt.open(self.vm.libvirt) 42 if self.vm.hostname in self.all_domains() and not self.vm.overwrite: 43 raise VMBuilderUserError('Domain %s already exists at %s' % (self.vm.hostname, self.vm.libvirt)) 44 45 if not self.vm.hypervisor.name == 'KVM': 46 raise VMBuilderUserError('The libvirt plugin is only equiped to work with KVM at the moment.')4749 if not self.vm.libvirt: 50 # Not for us 51 return False 52 53 if self.vm.hypervisor.preferred_storage == VMBuilder.hypervisor.STORAGE_FS_IMAGE: 54 vmxml = VMBuilder.util.render_template('libvirt', self.vm, 'libvirtxml_fsimage') 55 else: 56 vmxml = VMBuilder.util.render_template('libvirt', self.vm, 'libvirtxml') 57 58 if self.vm.hostname in self.all_domains() and not self.vm.overwrite: 59 raise VMBuilderUserError('Domain %s already exists at %s' % (self.vm.hostname, self.vm.libvirt)) 60 else: 61 self.conn.defineXML(vmxml) 62 63 return True
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Thu Nov 13 06:43:36 2008 | http://epydoc.sourceforge.net |