mirror of
https://github.com/retspen/webvirtcloud
synced 2025-07-31 12:41:08 +00:00
Merge remote-tracking branch 'retspen/master' into merge
Conflicts: instances/templates/instance.html instances/urls.py instances/views.py
This commit is contained in:
commit
01ace81c32
199 changed files with 34999 additions and 11154 deletions
|
|
@ -356,12 +356,13 @@ class wvmConnect(object):
|
|||
"""Return KVM capabilities."""
|
||||
return util.is_kvm_available(self.get_cap_xml())
|
||||
|
||||
def get_storages(self):
|
||||
def get_storages(self, only_actives=False):
|
||||
storages = []
|
||||
for pool in self.wvm.listStoragePools():
|
||||
storages.append(pool)
|
||||
for pool in self.wvm.listDefinedStoragePools():
|
||||
storages.append(pool)
|
||||
if not only_actives:
|
||||
for pool in self.wvm.listDefinedStoragePools():
|
||||
storages.append(pool)
|
||||
return storages
|
||||
|
||||
def get_networks(self):
|
||||
|
|
@ -399,6 +400,10 @@ class wvmConnect(object):
|
|||
"""Get available image formats"""
|
||||
return [ 'raw', 'qcow', 'qcow2' ]
|
||||
|
||||
def get_file_extensions(self):
|
||||
"""Get available image filename extensions"""
|
||||
return [ 'img', 'qcow', 'qcow2' ]
|
||||
|
||||
def get_iface(self, name):
|
||||
return self.wvm.interfaceLookupByName(name)
|
||||
|
||||
|
|
@ -443,10 +448,12 @@ class wvmConnect(object):
|
|||
|
||||
def get_net_device(self):
|
||||
netdevice = []
|
||||
def get_info(ctx):
|
||||
dev_type = util.get_xpath('/device/capability/@type')
|
||||
interface = util.get_xpath('/device/capability/interface')
|
||||
return (dev_type, interface)
|
||||
|
||||
def get_info(doc):
|
||||
dev_type = util.get_xpath(doc, '/device/capability/@type')
|
||||
interface = util.get_xpath(doc, '/device/capability/interface')
|
||||
return dev_type, interface
|
||||
|
||||
for dev in self.wvm.listAllDevices(0):
|
||||
xml = dev.XMLDesc(0)
|
||||
(dev_type, interface) = util.get_xml_path(xml, func=get_info)
|
||||
|
|
|
|||
|
|
@ -2,15 +2,16 @@ import string
|
|||
from vrtManager import util
|
||||
from vrtManager.connection import wvmConnect
|
||||
from webvirtcloud.settings import QEMU_CONSOLE_DEFAULT_TYPE
|
||||
from webvirtcloud.settings import INSTANCE_VOLUME_DEFAULT_FORMAT
|
||||
|
||||
|
||||
def get_rbd_storage_data(stg):
|
||||
xml = stg.XMLDesc(0)
|
||||
ceph_user = util.get_xml_path(xml, "/pool/source/auth/@username")
|
||||
|
||||
def get_ceph_hosts(ctx):
|
||||
def get_ceph_hosts(doc):
|
||||
hosts = []
|
||||
for host in ctx.xpathEval("/pool/source/host"):
|
||||
for host in doc.xpath("/pool/source/host"):
|
||||
name = host.prop("name")
|
||||
if name:
|
||||
hosts.append({'name': name, 'port': host.prop("port")})
|
||||
|
|
@ -21,12 +22,14 @@ def get_rbd_storage_data(stg):
|
|||
|
||||
|
||||
class wvmCreate(wvmConnect):
|
||||
image_format = INSTANCE_VOLUME_DEFAULT_FORMAT
|
||||
|
||||
def get_storages_images(self):
|
||||
"""
|
||||
Function return all images on all storages
|
||||
"""
|
||||
images = []
|
||||
storages = self.get_storages()
|
||||
storages = self.get_storages(only_actives=True)
|
||||
for storage in storages:
|
||||
stg = self.get_storage(storage)
|
||||
try:
|
||||
|
|
@ -48,12 +51,12 @@ class wvmCreate(wvmConnect):
|
|||
"""Get guest capabilities"""
|
||||
return util.get_xml_path(self.get_cap_xml(), "/capabilities/host/cpu/arch")
|
||||
|
||||
def create_volume(self, storage, name, size, format='qcow2', metadata=False, image_extension='img'):
|
||||
def create_volume(self, storage, name, size, image_format=image_format, metadata=False):
|
||||
size = int(size) * 1073741824
|
||||
stg = self.get_storage(storage)
|
||||
storage_type = util.get_xml_path(stg.XMLDesc(0), "/pool/@type")
|
||||
if storage_type == 'dir':
|
||||
name += '.' + image_extension
|
||||
name += '.img'
|
||||
alloc = 0
|
||||
else:
|
||||
alloc = size
|
||||
|
|
@ -65,8 +68,14 @@ class wvmCreate(wvmConnect):
|
|||
<allocation>%s</allocation>
|
||||
<target>
|
||||
<format type='%s'/>
|
||||
<permissions>
|
||||
<owner>107</owner>
|
||||
<group>107</group>
|
||||
<mode>0644</mode>
|
||||
<label>virt_image_t</label>
|
||||
</permissions>
|
||||
</target>
|
||||
</volume>""" % (name, size, alloc, format)
|
||||
</volume>""" % (name, size, alloc, image_format)
|
||||
stg.createXML(xml, metadata)
|
||||
try:
|
||||
stg.refresh(0)
|
||||
|
|
@ -86,7 +95,7 @@ class wvmCreate(wvmConnect):
|
|||
return 'raw'
|
||||
|
||||
def get_volume_path(self, volume):
|
||||
storages = self.get_storages()
|
||||
storages = self.get_storages(only_actives=True)
|
||||
for storage in storages:
|
||||
stg = self.get_storage(storage)
|
||||
if stg.info()[0] != 0:
|
||||
|
|
@ -116,6 +125,16 @@ class wvmCreate(wvmConnect):
|
|||
<allocation>0</allocation>
|
||||
<target>
|
||||
<format type='%s'/>
|
||||
<permissions>
|
||||
<owner>107</owner>
|
||||
<group>107</group>
|
||||
<mode>0644</mode>
|
||||
<label>virt_image_t</label>
|
||||
</permissions>
|
||||
<compat>1.1</compat>
|
||||
<features>
|
||||
<lazy_refcounts/>
|
||||
</features>
|
||||
</target>
|
||||
</volume>""" % (clone, format)
|
||||
stg.createXMLFrom(xml, vol, metadata)
|
||||
|
|
|
|||
|
|
@ -217,13 +217,14 @@ class wvmInstance(wvmConnect):
|
|||
result = []
|
||||
for net in ctx.xpath('/domain/devices/interface'):
|
||||
mac_host = net.xpath('mac/@address')[0]
|
||||
nic_host = net.xpath('source/@network|source/@bridge|source/@dev|target/@dev')[0]
|
||||
network_host = net.xpath('source/@network|source/@bridge|source/@dev')[0]
|
||||
target_host = '' if not net.xpath('target/@dev') else net.xpath('target/@dev')[0]
|
||||
try:
|
||||
net = self.get_network(nic_host)
|
||||
net = self.get_network(network_host)
|
||||
ip = get_mac_ipaddr(net, mac_host)
|
||||
except:
|
||||
except libvirtError as e:
|
||||
ip = None
|
||||
result.append({'mac': mac_host, 'nic': nic_host, 'ip': ip})
|
||||
result.append({'mac': mac_host, 'nic': network_host, 'target': target_host,'ip': ip})
|
||||
return result
|
||||
|
||||
return util.get_xml_path(self._XMLDesc(0), func=networks)
|
||||
|
|
@ -303,7 +304,7 @@ class wvmInstance(wvmConnect):
|
|||
disk.insert(2, src_media)
|
||||
return True
|
||||
|
||||
storages = self.get_storages()
|
||||
storages = self.get_storages(only_actives=True)
|
||||
for storage in storages:
|
||||
stg = self.get_storage(storage)
|
||||
if stg.info()[0] != 0:
|
||||
|
|
@ -597,7 +598,7 @@ class wvmInstance(wvmConnect):
|
|||
|
||||
def get_iso_media(self):
|
||||
iso = []
|
||||
storages = self.get_storages()
|
||||
storages = self.get_storages(only_actives=True)
|
||||
for storage in storages:
|
||||
stg = self.get_storage(storage)
|
||||
if stg.info()[0] != 0:
|
||||
|
|
@ -746,12 +747,13 @@ class wvmInstance(wvmConnect):
|
|||
tree = ElementTree.fromstring(xml)
|
||||
|
||||
for num, interface in enumerate(tree.findall('devices/interface')):
|
||||
net = self.get_network(network_data['net-source-' + str(num)])
|
||||
if interface.get('type') == 'bridge':
|
||||
source = interface.find('mac')
|
||||
source.set('address', network_data['net-mac-' + str(num)])
|
||||
source = interface.find('source')
|
||||
source.set('bridge', network_data['net-source-' + str(num)])
|
||||
|
||||
source.set('bridge', net.bridgeName())
|
||||
source.set('network', net.name())
|
||||
new_xml = ElementTree.tostring(tree)
|
||||
self._defineXML(new_xml)
|
||||
|
||||
|
|
|
|||
|
|
@ -169,6 +169,10 @@ class wvmStorage(wvmConnect):
|
|||
vol = self.get_volume(name)
|
||||
return vol.info()[1]
|
||||
|
||||
def get_volume_allocation(self, name):
|
||||
vol = self.get_volume(name)
|
||||
return vol.info()[2]
|
||||
|
||||
def _vol_XMLDesc(self, name):
|
||||
vol = self.get_volume(name)
|
||||
return vol.XMLDesc(0)
|
||||
|
|
@ -196,6 +200,7 @@ class wvmStorage(wvmConnect):
|
|||
vol_list.append(
|
||||
{'name': volname,
|
||||
'size': self.get_volume_size(volname),
|
||||
'allocation': self.get_volume_allocation(volname),
|
||||
'type': self.get_volume_type(volname)}
|
||||
)
|
||||
return vol_list
|
||||
|
|
@ -216,14 +221,24 @@ class wvmStorage(wvmConnect):
|
|||
<allocation>%s</allocation>
|
||||
<target>
|
||||
<format type='%s'/>
|
||||
<permissions>
|
||||
<owner>107</owner>
|
||||
<group>107</group>
|
||||
<mode>0644</mode>
|
||||
<label>virt_image_t</label>
|
||||
</permissions>
|
||||
<compat>1.1</compat>
|
||||
<features>
|
||||
<lazy_refcounts/>
|
||||
</features>
|
||||
</target>
|
||||
</volume>""" % (name, size, alloc, vol_fmt)
|
||||
self._createXML(xml, metadata)
|
||||
|
||||
def clone_volume(self, name, clone, vol_fmt=None, metadata=False):
|
||||
def clone_volume(self, name, target_file, vol_fmt=None, metadata=False):
|
||||
storage_type = self.get_type()
|
||||
if storage_type == 'dir':
|
||||
clone += '.img'
|
||||
target_file += '.img'
|
||||
vol = self.get_volume(name)
|
||||
if not vol_fmt:
|
||||
vol_fmt = self.get_volume_type(name)
|
||||
|
|
@ -234,6 +249,16 @@ class wvmStorage(wvmConnect):
|
|||
<allocation>0</allocation>
|
||||
<target>
|
||||
<format type='%s'/>
|
||||
<permissions>
|
||||
<owner>107</owner>
|
||||
<group>107</group>
|
||||
<mode>0644</mode>
|
||||
<label>virt_image_t</label>
|
||||
</permissions>
|
||||
<compat>1.1</compat>
|
||||
<features>
|
||||
<lazy_refcounts/>
|
||||
</features>
|
||||
</target>
|
||||
</volume>""" % (clone, vol_fmt)
|
||||
</volume>""" % (target_file, vol_fmt)
|
||||
self._createXMLFrom(xml, vol, metadata)
|
||||
|
|
|
|||
|
|
@ -86,25 +86,16 @@ def get_xml_path(xml, path=None, func=None):
|
|||
of a passed function (receives xpathContext as its only arg)
|
||||
"""
|
||||
doc = None
|
||||
#ctx = None
|
||||
result = None
|
||||
|
||||
#try:
|
||||
doc = etree.fromstring(xml)
|
||||
#ctx = doc.xpathNewContext()
|
||||
if path:
|
||||
result = get_xpath(doc, path)
|
||||
|
||||
elif func:
|
||||
result = func(doc)
|
||||
|
||||
else:
|
||||
raise ValueError("'path' or 'func' is required.")
|
||||
#finally:
|
||||
#if doc:
|
||||
# doc.freeDoc()
|
||||
#if ctx:
|
||||
# ctx.xpathFreeContext()
|
||||
return result
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue