mirror of
https://github.com/retspen/webvirtcloud
synced 2024-10-31 19:44:16 +00:00
add/remove guest agent channel function added
This commit is contained in:
parent
ecf31b0b5b
commit
9d58e56d16
3 changed files with 76 additions and 12 deletions
|
@ -1411,11 +1411,11 @@
|
|||
</form>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div class="well">
|
||||
<div class="well">
|
||||
<p>{% trans "To set instance vCPUs hotpluggable" %}</p>
|
||||
<form class="form-horizontal" method="post" role="form">{% csrf_token %}
|
||||
<div class="form-group">
|
||||
<label for="video_model_select" class="col-sm-3 control-label">{% trans "vCPU Hot Plug" %}</label>
|
||||
<label for="vcpu_hotplug" class="col-sm-3 control-label">{% trans "vCPU Hot Plug" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<div class="input-group">
|
||||
<select id="vcpu_hotplug" class="form-control" name="vcpu_hotplug">
|
||||
|
@ -1435,6 +1435,31 @@
|
|||
</form>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
<div class="well">
|
||||
<p>{% trans "To Enable/Disable Qemu Guest Agent. Status:" %}
|
||||
{% if guest_agent_ready %}
|
||||
<label class="label label-success">{% trans 'Connected' %}</label>
|
||||
{% else %}
|
||||
<label class="label label-danger">{% trans 'Disconnected' %}</label>
|
||||
{% endif %}</p>
|
||||
<form class="form-horizontal" method="post" role="form">{% csrf_token %}
|
||||
<div class="form-group">
|
||||
<label for="guest_agent" class="col-sm-3 control-label">{% trans "Qemu Guest Agent" %}</label>
|
||||
<div class="col-sm-6">
|
||||
<div class="input-group">
|
||||
<select id="guest_agent" class="form-control" name="guest_agent">
|
||||
<option value="True" {% if guest_agent %} selected {% endif %}>{% trans 'Enabled' %}</option>
|
||||
<option value="False" {% if not guest_agent %} selected {% endif %}>{% trans 'Disabled' %}</option>
|
||||
</select>
|
||||
<span class="input-group-btn">
|
||||
<button type="submit" class="btn btn-success" name="set_guest_agent">{% trans "Set" %}</button>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
|
|
@ -303,6 +303,8 @@ def instance(request, compute_id, vname):
|
|||
console_port = conn.get_console_port()
|
||||
console_keymap = conn.get_console_keymap()
|
||||
console_listen_address = conn.get_console_listen_addr()
|
||||
guest_agent = False if conn.get_guest_agent() is None else True
|
||||
guest_agent_ready = conn.is_agent_ready()
|
||||
video_model = conn.get_video_model()
|
||||
snapshots = sorted(conn.get_snapshot(), reverse=True, key=lambda k: k['date'])
|
||||
inst_xml = conn._XMLDesc(VIR_DOMAIN_XML_SECURE)
|
||||
|
@ -810,6 +812,17 @@ def instance(request, compute_id, vname):
|
|||
return HttpResponseRedirect(request.get_full_path() + '#vncsettings')
|
||||
|
||||
if request.user.is_superuser:
|
||||
if 'set_guest_agent' in request.POST:
|
||||
status = request.POST.get('guest_agent')
|
||||
if status == 'True':
|
||||
conn.add_guest_agent()
|
||||
if status == 'False':
|
||||
conn.remove_guest_agent()
|
||||
|
||||
msg = _("Set Quest Agent {}".format(status))
|
||||
addlogmsg(request.user.username, instance.name, msg)
|
||||
return HttpResponseRedirect(request.get_full_path() + '#options')
|
||||
|
||||
if 'set_video_model' in request.POST:
|
||||
video_model = request.POST.get('video_model', 'vga')
|
||||
conn.set_video_model(video_model)
|
||||
|
|
|
@ -336,7 +336,7 @@ class wvmInstance(wvmConnect):
|
|||
if not self.get_status() == 1:
|
||||
return
|
||||
|
||||
if self.agent_ready():
|
||||
if self.is_agent_ready():
|
||||
self._ip_cache["qemuga"] = self._get_interface_addresses(
|
||||
VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT)
|
||||
|
||||
|
@ -1381,19 +1381,37 @@ class wvmInstance(wvmConnect):
|
|||
tree = etree.fromstring(self._XMLDesc(0))
|
||||
for direct in tree.xpath("/domain/devices/interface/bandwidth/{}".format(direction)):
|
||||
band_el = direct.getparent()
|
||||
interface_el = band_el.getparent() # parent bandwidth,it parent is interface
|
||||
interface_el = band_el.getparent() # parent bandwidth,its parent is interface
|
||||
parent_mac = interface_el.xpath('mac/@address')
|
||||
if parent_mac[0] == mac:
|
||||
band_el.remove(direct)
|
||||
|
||||
self.wvm.defineXML(etree.tostring(tree))
|
||||
|
||||
def agent_ready(self):
|
||||
"""
|
||||
Return connected state of an agent.
|
||||
"""
|
||||
# we need to get a fresh agent channel object on each call so it
|
||||
# reflects the current state
|
||||
def add_guest_agent(self):
|
||||
channel_xml = """
|
||||
<channel type='unix'>
|
||||
<target type='virtio' name='org.qemu.guest_agent.0'/>
|
||||
</channel>
|
||||
"""
|
||||
if self.get_status() == 1:
|
||||
self.instance.attachDeviceFlags(channel_xml, VIR_DOMAIN_AFFECT_LIVE)
|
||||
self.instance.attachDeviceFlags(channel_xml, VIR_DOMAIN_AFFECT_CONFIG)
|
||||
if self.get_status() == 5:
|
||||
self.instance.attachDeviceFlags(channel_xml, VIR_DOMAIN_AFFECT_CONFIG)
|
||||
|
||||
def remove_guest_agent(self):
|
||||
tree = etree.fromstring(self._XMLDesc(0))
|
||||
for target in tree.xpath("/domain/devices/channel[@type='unix']/target[@name='org.qemu.guest_agent.0']"):
|
||||
parent = target.getparent()
|
||||
channel_xml = etree.tostring(parent)
|
||||
if self.get_status() == 1:
|
||||
self.instance.detachDeviceFlags(channel_xml, VIR_DOMAIN_AFFECT_LIVE)
|
||||
self.instance.detachDeviceFlags(channel_xml, VIR_DOMAIN_AFFECT_CONFIG)
|
||||
if self.get_status() == 5:
|
||||
self.instance.detachDeviceFlags(channel_xml, VIR_DOMAIN_AFFECT_CONFIG)
|
||||
|
||||
def get_guest_agent(self):
|
||||
def _get_agent(doc):
|
||||
"""
|
||||
Return agent channel object if it is defined.
|
||||
|
@ -1406,8 +1424,16 @@ class wvmInstance(wvmConnect):
|
|||
return channel
|
||||
return None
|
||||
|
||||
dev = util.get_xml_path(self._XMLDesc(0), func=_get_agent)
|
||||
if len(dev) > 0:
|
||||
return util.get_xml_path(self._XMLDesc(0), func=_get_agent)
|
||||
|
||||
def is_agent_ready(self):
|
||||
"""
|
||||
Return connected state of an agent.
|
||||
"""
|
||||
# we need to get a fresh agent channel object on each call so it
|
||||
# reflects the current state
|
||||
dev = self.get_guest_agent()
|
||||
if dev is not None:
|
||||
states = dev.xpath("target/@state")
|
||||
state = states[0] if len(states) > 0 else ''
|
||||
if state == "connected":
|
||||
|
|
Loading…
Reference in a new issue