mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-25 15:45:23 +00:00
volume owner/group converted to choosable from settings.py, cloning and creating volume owner parameter added.
This commit is contained in:
parent
b916c9dcf9
commit
e44e01cad4
4 changed files with 19 additions and 18 deletions
|
@ -389,6 +389,7 @@ def instance(request, compute_id, vname):
|
||||||
cache_modes = sorted(conn.get_cache_modes().items())
|
cache_modes = sorted(conn.get_cache_modes().items())
|
||||||
default_cache = settings.INSTANCE_VOLUME_DEFAULT_CACHE
|
default_cache = settings.INSTANCE_VOLUME_DEFAULT_CACHE
|
||||||
default_format = settings.INSTANCE_VOLUME_DEFAULT_FORMAT
|
default_format = settings.INSTANCE_VOLUME_DEFAULT_FORMAT
|
||||||
|
default_owner = settings.INSTANCE_VOLUME_DEFAULT_OWNER
|
||||||
formats = conn.get_image_formats()
|
formats = conn.get_image_formats()
|
||||||
|
|
||||||
busses = conn.get_busses()
|
busses = conn.get_busses()
|
||||||
|
@ -546,14 +547,14 @@ def instance(request, compute_id, vname):
|
||||||
compute.type)
|
compute.type)
|
||||||
storage = request.POST.get('storage', '')
|
storage = request.POST.get('storage', '')
|
||||||
name = request.POST.get('name', '')
|
name = request.POST.get('name', '')
|
||||||
format = request.POST.get('format', '')
|
format = request.POST.get('format', default_format)
|
||||||
size = request.POST.get('size', 0)
|
size = request.POST.get('size', 0)
|
||||||
meta_prealloc = request.POST.get('meta_prealloc', False)
|
meta_prealloc = request.POST.get('meta_prealloc', False)
|
||||||
bus = request.POST.get('bus', '')
|
bus = request.POST.get('bus', default_bus)
|
||||||
cache = request.POST.get('cache', '')
|
cache = request.POST.get('cache', default_cache)
|
||||||
target = get_new_disk_dev(disks, bus)
|
target = get_new_disk_dev(disks, bus)
|
||||||
|
|
||||||
path = connCreate.create_volume(storage, name, size, format, meta_prealloc)
|
path = connCreate.create_volume(storage, name, size, format, meta_prealloc, default_owner)
|
||||||
conn.attach_disk(path, target, subdriver=format, cache=cache, targetbus=bus)
|
conn.attach_disk(path, target, subdriver=format, cache=cache, targetbus=bus)
|
||||||
msg = _('Attach new disk')
|
msg = _('Attach new disk')
|
||||||
addlogmsg(request.user.username, instance.name, msg)
|
addlogmsg(request.user.username, instance.name, msg)
|
||||||
|
|
|
@ -713,13 +713,11 @@ class wvmInstance(wvmConnect):
|
||||||
source_file = elm.get('file')
|
source_file = elm.get('file')
|
||||||
if source_file:
|
if source_file:
|
||||||
clone_dev_path.append(source_file)
|
clone_dev_path.append(source_file)
|
||||||
clone_path = os.path.join(os.path.dirname(source_file),
|
clone_path = os.path.join(os.path.dirname(source_file), target_file)
|
||||||
target_file)
|
|
||||||
elm.set('file', clone_path)
|
elm.set('file', clone_path)
|
||||||
|
|
||||||
vol = self.get_volume_by_path(source_file)
|
vol = self.get_volume_by_path(source_file)
|
||||||
vol_format = util.get_xml_path(vol.XMLDesc(0),
|
vol_format = util.get_xml_path(vol.XMLDesc(0), "/volume/target/format/@type")
|
||||||
"/volume/target/format/@type")
|
|
||||||
|
|
||||||
if vol_format == 'qcow2' and meta_prealloc:
|
if vol_format == 'qcow2' and meta_prealloc:
|
||||||
meta_prealloc = True
|
meta_prealloc = True
|
||||||
|
@ -742,8 +740,7 @@ class wvmInstance(wvmConnect):
|
||||||
elm.set('name', clone_name)
|
elm.set('name', clone_name)
|
||||||
|
|
||||||
vol = self.get_volume_by_path(source_name)
|
vol = self.get_volume_by_path(source_name)
|
||||||
vol_format = util.get_xml_path(vol.XMLDesc(0),
|
vol_format = util.get_xml_path(vol.XMLDesc(0), "/volume/target/format/@type")
|
||||||
"/volume/target/format/@type")
|
|
||||||
|
|
||||||
vol_clone_xml = """
|
vol_clone_xml = """
|
||||||
<volume type='network'>
|
<volume type='network'>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from vrtManager import util
|
from vrtManager import util
|
||||||
from vrtManager.connection import wvmConnect
|
from vrtManager.connection import wvmConnect
|
||||||
|
from webvirtcloud.settings import INSTANCE_VOLUME_DEFAULT_OWNER as owner
|
||||||
|
|
||||||
|
|
||||||
class wvmStorages(wvmConnect):
|
class wvmStorages(wvmConnect):
|
||||||
|
@ -205,7 +206,7 @@ class wvmStorage(wvmConnect):
|
||||||
)
|
)
|
||||||
return vol_list
|
return vol_list
|
||||||
|
|
||||||
def create_volume(self, name, size, vol_fmt='qcow2', metadata=False):
|
def create_volume(self, name, size, vol_fmt='qcow2', metadata=False, owner=owner):
|
||||||
size = int(size) * 1073741824
|
size = int(size) * 1073741824
|
||||||
storage_type = self.get_type()
|
storage_type = self.get_type()
|
||||||
alloc = size
|
alloc = size
|
||||||
|
@ -222,8 +223,8 @@ class wvmStorage(wvmConnect):
|
||||||
<target>
|
<target>
|
||||||
<format type='%s'/>
|
<format type='%s'/>
|
||||||
<permissions>
|
<permissions>
|
||||||
<owner>107</owner>
|
<owner>%s</owner>
|
||||||
<group>107</group>
|
<group>%s</group>
|
||||||
<mode>0644</mode>
|
<mode>0644</mode>
|
||||||
<label>virt_image_t</label>
|
<label>virt_image_t</label>
|
||||||
</permissions>
|
</permissions>
|
||||||
|
@ -232,10 +233,10 @@ class wvmStorage(wvmConnect):
|
||||||
<lazy_refcounts/>
|
<lazy_refcounts/>
|
||||||
</features>
|
</features>
|
||||||
</target>
|
</target>
|
||||||
</volume>""" % (name, size, alloc, vol_fmt)
|
</volume>""" % (name, size, alloc, vol_fmt, owner, owner)
|
||||||
self._createXML(xml, metadata)
|
self._createXML(xml, metadata)
|
||||||
|
|
||||||
def clone_volume(self, name, target_file, vol_fmt=None, metadata=False):
|
def clone_volume(self, name, target_file, vol_fmt=None, metadata=False, owner=owner):
|
||||||
storage_type = self.get_type()
|
storage_type = self.get_type()
|
||||||
if storage_type == 'dir':
|
if storage_type == 'dir':
|
||||||
target_file += '.img'
|
target_file += '.img'
|
||||||
|
@ -250,8 +251,8 @@ class wvmStorage(wvmConnect):
|
||||||
<target>
|
<target>
|
||||||
<format type='%s'/>
|
<format type='%s'/>
|
||||||
<permissions>
|
<permissions>
|
||||||
<owner>107</owner>
|
<owner>%s</owner>
|
||||||
<group>107</group>
|
<group>%s</group>
|
||||||
<mode>0644</mode>
|
<mode>0644</mode>
|
||||||
<label>virt_image_t</label>
|
<label>virt_image_t</label>
|
||||||
</permissions>
|
</permissions>
|
||||||
|
@ -260,5 +261,5 @@ class wvmStorage(wvmConnect):
|
||||||
<lazy_refcounts/>
|
<lazy_refcounts/>
|
||||||
</features>
|
</features>
|
||||||
</target>
|
</target>
|
||||||
</volume>""" % (target_file, vol_fmt)
|
</volume>""" % (target_file, vol_fmt, owner,owner)
|
||||||
self._createXMLFrom(xml, vol, metadata)
|
self._createXMLFrom(xml, vol, metadata)
|
||||||
|
|
|
@ -152,3 +152,5 @@ VIEW_INSTANCES_LIST_STYLE = 'grouped'
|
||||||
INSTANCE_VOLUME_DEFAULT_FORMAT = 'qcow2'
|
INSTANCE_VOLUME_DEFAULT_FORMAT = 'qcow2'
|
||||||
INSTANCE_VOLUME_DEFAULT_BUS = 'virtio'
|
INSTANCE_VOLUME_DEFAULT_BUS = 'virtio'
|
||||||
INSTANCE_VOLUME_DEFAULT_CACHE = 'directsync'
|
INSTANCE_VOLUME_DEFAULT_CACHE = 'directsync'
|
||||||
|
# up to os, 0=root, 107=qemu or libvirt-bin(for ubuntu)
|
||||||
|
INSTANCE_VOLUME_DEFAULT_OWNER = 0
|
Loading…
Reference in a new issue