Skip to content

fix the new disk's permission to qemu:qemu #678

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions templates/instance.html
Original file line number Diff line number Diff line change
Expand Up @@ -473,12 +473,12 @@
<div class="tab-pane tab-inst" id="instancedevice">
<p style="font-weight:bold;">{% trans "Network devices" %}</p>

<div class="col-sm-3">
<div class="col-sm-4">
{% for network in networks %}
<p style="text-align: right;">eth{{ forloop.counter0 }} ({{ network.nic }})</p>
{% endfor %}
</div>
<div class="col-sm-9">
<div class="col-sm-8">
{% for network in networks %}
{% if network.ip %}
<p>{{ network.ip }}</p>
Expand All @@ -489,12 +489,12 @@
</div>
<p style="font-weight:bold;">{% trans "Storage devices" %}</p>

<div class="col-sm-3">
<div class="col-sm-4">
{% for disk in disks %}
<p style="text-align: right;">{{ disk.dev }} ({{ disk.storage }})</p>
{% endfor %}
</div>
<div class="col-sm-9">
<div class="col-sm-8">
{% for disk in disks %}
<p>{{ disk.image }} ({{ disk.format }})</p>
{% endfor %}
Expand Down
41 changes: 39 additions & 2 deletions vrtManager/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Copyright (C) 2013 Webvirtmgr.
#
import string

from vrtManager import util
from vrtManager.connection import wvmConnect

from webvirtmgr.settings import QEMU_CONSOLE_DEFAULT_TYPE


Expand All @@ -19,6 +19,7 @@ def get_ceph_hosts(ctx):
if name:
hosts.append({'name': name, 'port': host.prop("port")})
return hosts

ceph_hosts = util.get_xml_path(xml, func=get_ceph_hosts)
secret_uuid = util.get_xml_path(xml, "/pool/source/auth/secret/@uuid")
return ceph_user, secret_uuid, ceph_hosts
Expand All @@ -43,6 +44,18 @@ def get_storages_images(self):
else:
images.append(img)
return images

def get_images_without_template(self):
"""
:return: images list without template
"""
return [name for name in self.get_storages_images() if "template" not in name.lower()]

def get_template_images(self):
"""
return template name
"""
return [name for name in self.get_storages_images() if "template" in name.lower()]

def get_os_type(self):
"""Get guest capabilities"""
Expand All @@ -61,7 +74,7 @@ def get_cache_modes(self):
'writeback': 'Write back',
'directsync': 'Direct sync', # since libvirt 0.9.5
'unsafe': 'Unsafe', # since libvirt 0.9.7
}
}

def create_volume(self, storage, name, size, format='qcow2', metadata=False):
size = int(size) * 1073741824
Expand All @@ -80,6 +93,16 @@ def create_volume(self, storage, name, size, format='qcow2', metadata=False):
<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, format)
stg.createXML(xml, metadata)
Expand Down Expand Up @@ -115,6 +138,10 @@ def get_storage_by_vol_path(self, vol_path):
vol = self.get_volume_by_path(vol_path)
return vol.storagePoolLookupByVolume()

def get_storage_capacity_by_vol_path(self, vol_path):
vol = self.get_volume_by_path(vol_path)
return vol.info()[1] / 1024.0 / 1024.0 / 1024.0

def clone_from_template(self, clone, template, metadata=False):
vol = self.get_volume_by_path(template)
stg = vol.storagePoolLookupByVolume()
Expand All @@ -131,6 +158,16 @@ def clone_from_template(self, clone, template, metadata=False):
<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)
Expand Down
26 changes: 21 additions & 5 deletions vrtManager/instance.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#
# Copyright (C) 2013 Webvirtmgr.
#
import time
import os.path
import time


try:
from libvirt import libvirtError, VIR_DOMAIN_XML_SECURE, VIR_MIGRATE_LIVE, \
VIR_MIGRATE_UNSAFE, VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA
from libvirt import (libvirtError, VIR_DOMAIN_XML_SECURE, VIR_MIGRATE_LIVE,
VIR_MIGRATE_UNSAFE, VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA)
except:
from libvirt import libvirtError, VIR_DOMAIN_XML_SECURE, VIR_MIGRATE_LIVE
from vrtManager import util
Expand Down Expand Up @@ -220,8 +222,8 @@ def disks(ctx):
except:
pass
finally:
result.append(
{'dev': dev, 'image': volume, 'storage': storage, 'path': src_fl, 'format': disk_format})
result.append({'dev': dev, 'image': volume, 'storage': storage, 'path': src_fl,
'format': disk_format})
return result

return util.get_xml_path(self._XMLDesc(0), func=disks)
Expand Down Expand Up @@ -575,6 +577,10 @@ def snapshot_revert(self, snapshot):
def get_managed_save_image(self):
return self.instance.hasManagedSaveImage(0)

def get_storage_capacity_by_vol_path(self, vol_path):
vol = self.get_volume_by_path(vol_path)
return vol.info()[1] / 1024.0 / 1024.0 / 1024.0

def clone_instance(self, clone_data):
clone_dev_path = []

Expand Down Expand Up @@ -622,6 +628,16 @@ def clone_instance(self, clone_data):
<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>""" % (target_file, vol_format)
stg = vol.storagePoolLookupByVolume()
Expand Down
28 changes: 24 additions & 4 deletions vrtManager/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ def update_volumes(self):

for volname in vols:
vol_list.append(
{'name': volname,
'size': self.get_volume_size(volname),
'type': self.get_volume_type(volname)}
)
{'name': volname,
'size': self.get_volume_size(volname),
'type': self.get_volume_type(volname)}
)
return vol_list

def create_volume(self, name, size, vol_fmt='qcow2', metadata=False):
Expand All @@ -219,6 +219,16 @@ def create_volume(self, name, size, vol_fmt='qcow2', metadata=False):
<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)
Expand All @@ -237,6 +247,16 @@ def clone_volume(self, name, clone, vol_fmt=None, metadata=False):
<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)
self._createXMLFrom(xml, vol, metadata)
20 changes: 20 additions & 0 deletions vrtManager/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@ def randomMAC():
random.randint(0x00, 0xff)]
return ':'.join(map(lambda x: "%02x" % x, mac))

def gen_MAC_via_ip(ip_str):
"""
return MAC whose last four bytes are same as ip
:param ip_str:
:return:
"""
mac_strs = ['%02x' % int(num) for num in ip_str.split(".")]
return "52:54" + ":%s:%s:%s:%s" % tuple(mac_strs)

def get_ip_via_mac(mac_str):
"""
return a ip according to the last for bytes in mac
:param mac_str:
:return:
"""
# default MAC is not the user's input
if mac_str.startswith("52:54:00"):
return None
mac_split = mac_str.split(":")
return ".".join(["%s" % int(item, 16) for item in mac_split[2:]])

def randomUUID():
"""Generate a random UUID."""
Expand Down