mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-24 23:25:24 +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())
|
||||
default_cache = settings.INSTANCE_VOLUME_DEFAULT_CACHE
|
||||
default_format = settings.INSTANCE_VOLUME_DEFAULT_FORMAT
|
||||
default_owner = settings.INSTANCE_VOLUME_DEFAULT_OWNER
|
||||
formats = conn.get_image_formats()
|
||||
|
||||
busses = conn.get_busses()
|
||||
|
@ -546,14 +547,14 @@ def instance(request, compute_id, vname):
|
|||
compute.type)
|
||||
storage = request.POST.get('storage', '')
|
||||
name = request.POST.get('name', '')
|
||||
format = request.POST.get('format', '')
|
||||
format = request.POST.get('format', default_format)
|
||||
size = request.POST.get('size', 0)
|
||||
meta_prealloc = request.POST.get('meta_prealloc', False)
|
||||
bus = request.POST.get('bus', '')
|
||||
cache = request.POST.get('cache', '')
|
||||
bus = request.POST.get('bus', default_bus)
|
||||
cache = request.POST.get('cache', default_cache)
|
||||
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)
|
||||
msg = _('Attach new disk')
|
||||
addlogmsg(request.user.username, instance.name, msg)
|
||||
|
|
|
@ -713,13 +713,11 @@ class wvmInstance(wvmConnect):
|
|||
source_file = elm.get('file')
|
||||
if source_file:
|
||||
clone_dev_path.append(source_file)
|
||||
clone_path = os.path.join(os.path.dirname(source_file),
|
||||
target_file)
|
||||
clone_path = os.path.join(os.path.dirname(source_file), target_file)
|
||||
elm.set('file', clone_path)
|
||||
|
||||
vol = self.get_volume_by_path(source_file)
|
||||
vol_format = util.get_xml_path(vol.XMLDesc(0),
|
||||
"/volume/target/format/@type")
|
||||
vol_format = util.get_xml_path(vol.XMLDesc(0), "/volume/target/format/@type")
|
||||
|
||||
if vol_format == 'qcow2' and meta_prealloc:
|
||||
meta_prealloc = True
|
||||
|
@ -742,8 +740,7 @@ class wvmInstance(wvmConnect):
|
|||
elm.set('name', clone_name)
|
||||
|
||||
vol = self.get_volume_by_path(source_name)
|
||||
vol_format = util.get_xml_path(vol.XMLDesc(0),
|
||||
"/volume/target/format/@type")
|
||||
vol_format = util.get_xml_path(vol.XMLDesc(0), "/volume/target/format/@type")
|
||||
|
||||
vol_clone_xml = """
|
||||
<volume type='network'>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from vrtManager import util
|
||||
from vrtManager.connection import wvmConnect
|
||||
from webvirtcloud.settings import INSTANCE_VOLUME_DEFAULT_OWNER as owner
|
||||
|
||||
|
||||
class wvmStorages(wvmConnect):
|
||||
|
@ -205,7 +206,7 @@ class wvmStorage(wvmConnect):
|
|||
)
|
||||
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
|
||||
storage_type = self.get_type()
|
||||
alloc = size
|
||||
|
@ -222,8 +223,8 @@ class wvmStorage(wvmConnect):
|
|||
<target>
|
||||
<format type='%s'/>
|
||||
<permissions>
|
||||
<owner>107</owner>
|
||||
<group>107</group>
|
||||
<owner>%s</owner>
|
||||
<group>%s</group>
|
||||
<mode>0644</mode>
|
||||
<label>virt_image_t</label>
|
||||
</permissions>
|
||||
|
@ -232,10 +233,10 @@ class wvmStorage(wvmConnect):
|
|||
<lazy_refcounts/>
|
||||
</features>
|
||||
</target>
|
||||
</volume>""" % (name, size, alloc, vol_fmt)
|
||||
</volume>""" % (name, size, alloc, vol_fmt, owner, owner)
|
||||
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()
|
||||
if storage_type == 'dir':
|
||||
target_file += '.img'
|
||||
|
@ -250,8 +251,8 @@ class wvmStorage(wvmConnect):
|
|||
<target>
|
||||
<format type='%s'/>
|
||||
<permissions>
|
||||
<owner>107</owner>
|
||||
<group>107</group>
|
||||
<owner>%s</owner>
|
||||
<group>%s</group>
|
||||
<mode>0644</mode>
|
||||
<label>virt_image_t</label>
|
||||
</permissions>
|
||||
|
@ -260,5 +261,5 @@ class wvmStorage(wvmConnect):
|
|||
<lazy_refcounts/>
|
||||
</features>
|
||||
</target>
|
||||
</volume>""" % (target_file, vol_fmt)
|
||||
</volume>""" % (target_file, vol_fmt, owner,owner)
|
||||
self._createXMLFrom(xml, vol, metadata)
|
||||
|
|
|
@ -152,3 +152,5 @@ VIEW_INSTANCES_LIST_STYLE = 'grouped'
|
|||
INSTANCE_VOLUME_DEFAULT_FORMAT = 'qcow2'
|
||||
INSTANCE_VOLUME_DEFAULT_BUS = 'virtio'
|
||||
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