mirror of
https://github.com/retspen/webvirtcloud
synced 2024-11-01 03:54:15 +00:00
instance/network: allow to select compute interface, previously only compute network
This commit is contained in:
parent
9c37dcc2dc
commit
b4da655644
4 changed files with 42 additions and 13 deletions
|
@ -25,7 +25,10 @@
|
||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
<select class="form-control" name="add-net-network">
|
<select class="form-control" name="add-net-network">
|
||||||
{% for c_net in compute_networks %}
|
{% for c_net in compute_networks %}
|
||||||
<option value="{{ c_net }}">{{ c_net }}</option>
|
<option value="net:{{ c_net }}">Network {{ c_net }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
{% for c_iface in compute_interfaces %}
|
||||||
|
<option value="iface:{{ c_iface }}">Interface {{ c_iface }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -846,9 +846,12 @@
|
||||||
<select name="net-source-{{ forloop.counter0 }}" class="form-control" id="network_select" onchange="network_select_enable()">
|
<select name="net-source-{{ forloop.counter0 }}" class="form-control" id="network_select" onchange="network_select_enable()">
|
||||||
{% for c_nets in compute_networks %}
|
{% for c_nets in compute_networks %}
|
||||||
{% if forloop.counter0 == 0 %}
|
{% if forloop.counter0 == 0 %}
|
||||||
<option value="{{ network.nic }}" selected hidden>{% trans "to Change" %}</option>
|
<option value="iface:{{ network.nic }}" selected hidden>{% trans "to Change" %}</option>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<option value="{{ c_nets }}">{{ c_nets }}</option>
|
<option value="net:{{ c_nets }}">Network {{ c_nets }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
{% for c_iface in compute_interfaces %}
|
||||||
|
<option value="iface:{{ c_iface }}">Interface {{ c_iface }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -322,6 +322,13 @@ def instance(request, compute_id, vname):
|
||||||
return dev
|
return dev
|
||||||
raise Exception(_('None available device name'))
|
raise Exception(_('None available device name'))
|
||||||
|
|
||||||
|
def get_network_tuple(network_source_str):
|
||||||
|
network_source_pack = network_source_str.split(":", 1)
|
||||||
|
if len(network_source_pack) > 1:
|
||||||
|
return (network_source_pack[1], network_source_pack[0])
|
||||||
|
else:
|
||||||
|
return (network_source_pack[0], 'net')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
conn = wvmInstance(compute.hostname,
|
conn = wvmInstance(compute.hostname,
|
||||||
compute.login,
|
compute.login,
|
||||||
|
@ -329,6 +336,7 @@ def instance(request, compute_id, vname):
|
||||||
compute.type,
|
compute.type,
|
||||||
vname)
|
vname)
|
||||||
compute_networks = sorted(conn.get_networks())
|
compute_networks = sorted(conn.get_networks())
|
||||||
|
compute_interfaces = sorted(conn.get_ifaces())
|
||||||
status = conn.get_status()
|
status = conn.get_status()
|
||||||
autostart = conn.get_autostart()
|
autostart = conn.get_autostart()
|
||||||
vcpu = conn.get_vcpu()
|
vcpu = conn.get_vcpu()
|
||||||
|
@ -686,7 +694,11 @@ def instance(request, compute_id, vname):
|
||||||
network_data = {}
|
network_data = {}
|
||||||
|
|
||||||
for post in request.POST:
|
for post in request.POST:
|
||||||
if post.startswith('net-'):
|
if post.startswith('net-source-'):
|
||||||
|
(source, source_type) = get_network_tuple(request.POST.get(post))
|
||||||
|
network_data[post] = source
|
||||||
|
network_data[post + '-type'] = source_type
|
||||||
|
elif post.startswith('net-'):
|
||||||
network_data[post] = request.POST.get(post, '')
|
network_data[post] = request.POST.get(post, '')
|
||||||
|
|
||||||
conn.change_network(network_data)
|
conn.change_network(network_data)
|
||||||
|
@ -698,9 +710,9 @@ def instance(request, compute_id, vname):
|
||||||
|
|
||||||
if 'add_network' in request.POST:
|
if 'add_network' in request.POST:
|
||||||
mac = request.POST.get('add-net-mac')
|
mac = request.POST.get('add-net-mac')
|
||||||
network = request.POST.get('add-net-network')
|
(source, source_type) = get_network_tuple(request.POST.get('add-net-network'))
|
||||||
|
|
||||||
conn.add_network(mac, network)
|
conn.add_network(mac, source, source_type)
|
||||||
msg = _("Edit network")
|
msg = _("Edit network")
|
||||||
addlogmsg(request.user.username, instance.name, msg)
|
addlogmsg(request.user.username, instance.name, msg)
|
||||||
msg = _("Network Devices are changed. Please reboot instance to activate.")
|
msg = _("Network Devices are changed. Please reboot instance to activate.")
|
||||||
|
|
|
@ -742,16 +742,25 @@ class wvmInstance(wvmConnect):
|
||||||
|
|
||||||
return self.get_instance(clone_data['name']).UUIDString()
|
return self.get_instance(clone_data['name']).UUIDString()
|
||||||
|
|
||||||
def add_network(self, mac_address, network, interface_type='bridge', model='virtio'):
|
def get_bridge_name(self, source, source_type='net'):
|
||||||
|
if source_type == 'iface':
|
||||||
|
iface = self.get_iface(source)
|
||||||
|
bridge_name = iface.name()
|
||||||
|
else:
|
||||||
|
net = self.get_network(source)
|
||||||
|
bridge_name = net.bridgeName()
|
||||||
|
return bridge_name
|
||||||
|
|
||||||
|
def add_network(self, mac_address, source, source_type='net', interface_type='bridge', model='virtio'):
|
||||||
tree = ElementTree.fromstring(self._XMLDesc(0))
|
tree = ElementTree.fromstring(self._XMLDesc(0))
|
||||||
net = self.get_network(network)
|
bridge_name = self.get_bridge_name(source, source_type)
|
||||||
xml_interface = """
|
xml_interface = """
|
||||||
<interface type='%s'>
|
<interface type='%s'>
|
||||||
<mac address='%s'/>
|
<mac address='%s'/>
|
||||||
<source bridge='%s'/>
|
<source bridge='%s'/>
|
||||||
<model type='%s'/>
|
<model type='%s'/>
|
||||||
</interface>
|
</interface>
|
||||||
""" % (interface_type, mac_address, net.bridgeName(), model)
|
""" % (interface_type, mac_address, bridge_name, model)
|
||||||
if self.get_status() == 5:
|
if self.get_status() == 5:
|
||||||
devices = tree.find('devices')
|
devices = tree.find('devices')
|
||||||
elm_interface = ElementTree.fromstring(xml_interface)
|
elm_interface = ElementTree.fromstring(xml_interface)
|
||||||
|
@ -764,13 +773,15 @@ class wvmInstance(wvmConnect):
|
||||||
tree = ElementTree.fromstring(xml)
|
tree = ElementTree.fromstring(xml)
|
||||||
|
|
||||||
for num, interface in enumerate(tree.findall('devices/interface')):
|
for num, interface in enumerate(tree.findall('devices/interface')):
|
||||||
net = self.get_network(network_data['net-source-' + str(num)])
|
net_source = network_data['net-source-' + str(num)]
|
||||||
|
net_source_type = network_data['net-source-' + str(num) + '-type']
|
||||||
|
net_mac = network_data['net-mac-' + str(num)]
|
||||||
|
bridge_name = self.get_bridge_name(net_source, net_source_type)
|
||||||
if interface.get('type') == 'bridge':
|
if interface.get('type') == 'bridge':
|
||||||
source = interface.find('mac')
|
source = interface.find('mac')
|
||||||
source.set('address', network_data['net-mac-' + str(num)])
|
source.set('address', net_mac)
|
||||||
source = interface.find('source')
|
source = interface.find('source')
|
||||||
source.set('bridge', net.bridgeName())
|
source.set('bridge', bridge_name)
|
||||||
source.set('network', net.name())
|
|
||||||
new_xml = ElementTree.tostring(tree)
|
new_xml = ElementTree.tostring(tree)
|
||||||
self._defineXML(new_xml)
|
self._defineXML(new_xml)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue