mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-24 23:25:24 +00:00
adds link state option for instance networks. Enable/disable link while instance running
This commit is contained in:
parent
01f2290dd9
commit
ecf31b0b5b
3 changed files with 50 additions and 10 deletions
|
@ -878,6 +878,7 @@
|
||||||
<th>{% trans 'MAC' %}</th>
|
<th>{% trans 'MAC' %}</th>
|
||||||
<th>{% trans 'IP Address' %}</th>
|
<th>{% trans 'IP Address' %}</th>
|
||||||
<th>{% trans 'Source' %}</th>
|
<th>{% trans 'Source' %}</th>
|
||||||
|
<th>{% trans 'LinkState' %}</th>
|
||||||
<th>{% trans 'Filter' %}</th>
|
<th>{% trans 'Filter' %}</th>
|
||||||
<th>{% trans 'Qos' %}</th>
|
<th>{% trans 'Qos' %}</th>
|
||||||
<th>{% trans 'Actions' %}</th>
|
<th>{% trans 'Actions' %}</th>
|
||||||
|
@ -886,11 +887,20 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for network in networks %}
|
{% for network in networks %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="col-sm-2"><label>eth{{ forloop.counter0 }}({{ network.target|default:"no target" }})</label></td>
|
<td class="col-sm-1">eth{{ forloop.counter0 }}({{ network.target|default:"no target" }})</td>
|
||||||
<td><label>{{ network.mac }}</label></td>
|
<td>{{ network.mac }}</td>
|
||||||
<td><label>{{ network.ipv4|default:"unknown" }}</label></td>
|
<td>{{ network.ipv4|default:"unknown" }}</td>
|
||||||
<td><label>{{ network.nic }}</label></td>
|
<td>{{ network.nic }}</td>
|
||||||
<td><label>{{ network.filterref|default:"None" }}</label></td>
|
<td>
|
||||||
|
<form method="post">{% csrf_token %}
|
||||||
|
<input name="mac" value="{{ network.mac }}" hidden/>
|
||||||
|
<input name="set_link_state" value="{{ network.state }}" hidden/>
|
||||||
|
<input type="checkbox" {% if network.state == 'up' %} checked
|
||||||
|
{% endif %} onclick='submit();' />
|
||||||
|
{% trans 'active' %}
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
<td>{{ network.filterref|default:"None" }}</td>
|
||||||
<td>
|
<td>
|
||||||
<form class="form-horizontal" method="post" name="add_qos{{ forloop.counter0 }}" role="form">{% csrf_token %}
|
<form class="form-horizontal" method="post" name="add_qos{{ forloop.counter0 }}" role="form">{% csrf_token %}
|
||||||
<input type="text" name="net-mac-{{ forloop.counter0 }}" value="{{ network.mac }}" hidden/>
|
<input type="text" name="net-mac-{{ forloop.counter0 }}" value="{{ network.mac }}" hidden/>
|
||||||
|
|
|
@ -873,6 +873,15 @@ def instance(request, compute_id, vname):
|
||||||
addlogmsg(request.user.username, instance.name, msg)
|
addlogmsg(request.user.username, instance.name, msg)
|
||||||
return HttpResponseRedirect(request.get_full_path() + '#network')
|
return HttpResponseRedirect(request.get_full_path() + '#network')
|
||||||
|
|
||||||
|
if 'set_link_state' in request.POST:
|
||||||
|
mac_address = request.POST.get('mac', '')
|
||||||
|
state = request.POST.get('set_link_state')
|
||||||
|
state = 'down' if state == 'up' else 'up'
|
||||||
|
conn.set_link_state(mac_address, state)
|
||||||
|
msg = _("Set Link State: {}".format(state))
|
||||||
|
addlogmsg(request.user.username, instance.name, msg)
|
||||||
|
return HttpResponseRedirect(request.get_full_path() + '#network')
|
||||||
|
|
||||||
if 'set_qos' in request.POST:
|
if 'set_qos' in request.POST:
|
||||||
qos_dir = request.POST.get('qos_direction', '')
|
qos_dir = request.POST.get('qos_direction', '')
|
||||||
average = request.POST.get('qos_average') or 0
|
average = request.POST.get('qos_average') or 0
|
||||||
|
|
|
@ -331,7 +331,6 @@ class wvmInstance(wvmConnect):
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def refresh_interface_addresses(self):
|
def refresh_interface_addresses(self):
|
||||||
|
|
||||||
self._ip_cache = {"qemuga": {}, "arp": {}}
|
self._ip_cache = {"qemuga": {}, "arp": {}}
|
||||||
|
|
||||||
if not self.get_status() == 1:
|
if not self.get_status() == 1:
|
||||||
|
@ -353,6 +352,7 @@ class wvmInstance(wvmConnect):
|
||||||
mac_inst = net.xpath('mac/@address')[0]
|
mac_inst = net.xpath('mac/@address')[0]
|
||||||
nic_inst = net.xpath('source/@network|source/@bridge|source/@dev')[0]
|
nic_inst = net.xpath('source/@network|source/@bridge|source/@dev')[0]
|
||||||
target_inst = '' if not net.xpath('target/@dev') else net.xpath('target/@dev')[0]
|
target_inst = '' if not net.xpath('target/@dev') else net.xpath('target/@dev')[0]
|
||||||
|
link_state = 'up' if not net.xpath('link') else net.xpath('link/@state')[0]
|
||||||
filterref_inst = '' if not net.xpath('filterref/@filter') else net.xpath('filterref/@filter')[0]
|
filterref_inst = '' if not net.xpath('filterref/@filter') else net.xpath('filterref/@filter')[0]
|
||||||
if net.xpath('bandwidth/inbound'):
|
if net.xpath('bandwidth/inbound'):
|
||||||
in_attr = net.xpath('bandwidth/inbound')[0]
|
in_attr = net.xpath('bandwidth/inbound')[0]
|
||||||
|
@ -374,6 +374,7 @@ class wvmInstance(wvmConnect):
|
||||||
result.append({'mac': mac_inst,
|
result.append({'mac': mac_inst,
|
||||||
'nic': nic_inst,
|
'nic': nic_inst,
|
||||||
'target': target_inst,
|
'target': target_inst,
|
||||||
|
'state': link_state,
|
||||||
'ipv4': ipv4,
|
'ipv4': ipv4,
|
||||||
'ipv6': ipv6,
|
'ipv6': ipv6,
|
||||||
'filterref': filterref_inst,
|
'filterref': filterref_inst,
|
||||||
|
@ -1275,6 +1276,24 @@ class wvmInstance(wvmConnect):
|
||||||
new_xml = ElementTree.tostring(tree)
|
new_xml = ElementTree.tostring(tree)
|
||||||
self._defineXML(new_xml)
|
self._defineXML(new_xml)
|
||||||
|
|
||||||
|
def set_link_state(self, mac_address, state):
|
||||||
|
tree = etree.fromstring(self._XMLDesc(0))
|
||||||
|
for interface in tree.findall('devices/interface'):
|
||||||
|
source = interface.find('mac')
|
||||||
|
if source.get('address') == mac_address:
|
||||||
|
link = interface.find('link')
|
||||||
|
if link is not None:
|
||||||
|
interface.remove(link)
|
||||||
|
link_el = etree.Element("link")
|
||||||
|
link_el.attrib["state"] = state
|
||||||
|
interface.append(link_el)
|
||||||
|
new_xml = etree.tostring(interface)
|
||||||
|
if self.get_status() == 1:
|
||||||
|
self.instance.updateDeviceFlags(new_xml, VIR_DOMAIN_AFFECT_LIVE)
|
||||||
|
self.instance.updateDeviceFlags(new_xml, VIR_DOMAIN_AFFECT_CONFIG)
|
||||||
|
if self.get_status() == 5:
|
||||||
|
self.instance.updateDeviceFlags(new_xml, VIR_DOMAIN_AFFECT_CONFIG)
|
||||||
|
|
||||||
def _set_options(self, tree, options):
|
def _set_options(self, tree, options):
|
||||||
for o in ['title', 'description']:
|
for o in ['title', 'description']:
|
||||||
option = tree.find(o)
|
option = tree.find(o)
|
||||||
|
@ -1388,10 +1407,12 @@ class wvmInstance(wvmConnect):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
dev = util.get_xml_path(self._XMLDesc(0), func=_get_agent)
|
dev = util.get_xml_path(self._XMLDesc(0), func=_get_agent)
|
||||||
state = dev.xpath("target/@state")[0]
|
if len(dev) > 0:
|
||||||
if dev and state == "connected":
|
states = dev.xpath("target/@state")
|
||||||
return True
|
state = states[0] if len(states) > 0 else ''
|
||||||
return False
|
if state == "connected":
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue