Преглед на файлове

Adding virtualport interface attribute for nic

Prod-Related: PROD-20747

Change-Id: Id7822963ab45ff7db3252f5329a9376aa4bf10d6
pull/73/head
Dzmitry Stremkouski преди 6 години
родител
ревизия
b8acf1f9c8
променени са 3 файла, в които са добавени 71 реда и са изтрити 56 реда
  1. +5
    -0
      README.rst
  2. +47
    -56
      _modules/virtng.py
  3. +19
    -0
      tests/pillar/control_virt_custom.sls

+ 5
- 0
README.rst Целия файл

@@ -404,6 +404,11 @@ Control VM provisioning
- name: nic04
bridge: br-public
model: virtio
- name: nic05
bridge: br-prv
model: virtio
virtualport:
type: openvswitch


salt:

+ 47
- 56
_modules/virtng.py Целия файл

@@ -430,67 +430,11 @@ def _disk_profile(profile, hypervisor, **kwargs):

def _nic_profile(profile_name, hypervisor, **kwargs):

default = [{'eth0': {}}]
vmware_overlay = {'type': 'bridge', 'source': 'DEFAULT', 'model': 'e1000'}
kvm_overlay = {'type': 'bridge', 'source': 'br0', 'model': 'virtio'}
overlays = {
'kvm': kvm_overlay,
'qemu': kvm_overlay,
'esxi': vmware_overlay,
'vmware': vmware_overlay,
}

# support old location
config_data = __salt__['config.option']('virt.nic', {}).get(
profile_name, None
)

if config_data is None:
config_data = __salt__['config.get']('virt:nic', {}).get(
profile_name, default
)

interfaces = []

def append_dict_profile_to_interface_list(profile_dict):
for interface_name, attributes in profile_dict.items():
attributes['name'] = interface_name
interfaces.append(attributes)

# old style dicts (top-level dicts)
#
# virt:
# nic:
# eth0:
# bridge: br0
# eth1:
# network: test_net
if isinstance(config_data, dict):
append_dict_profile_to_interface_list(config_data)

# new style lists (may contain dicts)
#
# virt:
# nic:
# - eth0:
# bridge: br0
# - eth1:
# network: test_net
#
# virt:
# nic:
# - name: eth0
# bridge: br0
# - name: eth1
# network: test_net
elif isinstance(config_data, list):
for interface in config_data:
if isinstance(interface, dict):
if len(interface) == 1:
append_dict_profile_to_interface_list(interface)
else:
interfaces.append(interface)

def _normalize_net_types(attributes):
'''
Guess which style of definition:
@@ -514,6 +458,7 @@ def _nic_profile(profile_name, hypervisor, **kwargs):

attributes['type'] = attributes.get('type', None)
attributes['source'] = attributes.get('source', None)
attributes['virtualport'] = attributes.get('virtualport', None)

def _apply_default_overlay(attributes):
for key, value in overlays[hypervisor].items():
@@ -532,6 +477,40 @@ def _nic_profile(profile_name, hypervisor, **kwargs):
else:
attributes['mac'] = salt.utils.gen_mac()


default = [{'eth0': {}}]
vmware_overlay = {'type': 'bridge', 'source': 'DEFAULT', 'model': 'e1000'}
kvm_overlay = {'type': 'bridge', 'source': 'br0', 'model': 'virtio'}
overlays = {
'kvm': kvm_overlay,
'qemu': kvm_overlay,
'esxi': vmware_overlay,
'vmware': vmware_overlay,
}

# support old location
config_data = __salt__['config.option']('virt.nic', {}).get(
profile_name, None
)

if config_data is None:
config_data = __salt__['config.get']('virt:nic', {}).get(
profile_name, default
)

interfaces = []

if isinstance(config_data, dict):
append_dict_profile_to_interface_list(config_data)

elif isinstance(config_data, list):
for interface in config_data:
if isinstance(interface, dict):
if len(interface) == 1:
append_dict_profile_to_interface_list(interface)
else:
interfaces.append(interface)

for interface in interfaces:
_normalize_net_types(interface)
_assign_mac(interface)
@@ -670,6 +649,18 @@ def init(name,

xml = _gen_xml(name, cpu, mem, diskp, nicp, hypervisor, **kwargs)

# TODO: Remove this code and refactor module, when salt-common would have updated libvirt_domain.jinja template
for _nic in nicp:
if _nic['virtualport']:
xml_doc = minidom.parseString(xml)
interfaces = xml_doc.getElementsByTagName("domain")[0].getElementsByTagName("devices")[0].getElementsByTagName("interface")
for interface in interfaces:
if interface.getElementsByTagName('mac')[0].getAttribute('address').lower() == _nic['mac'].lower():
vport_xml = xml_doc.createElement("virtualport")
vport_xml.setAttribute("type", _nic['virtualport']['type'])
interface.appendChild(vport_xml)
xml = xml_doc.toxml()

# TODO: Remove this code and refactor module, when salt-common would have updated libvirt_domain.jinja template
if rng:
rng_model = rng.get('model', 'random')

+ 19
- 0
tests/pillar/control_virt_custom.sls Целия файл

@@ -9,6 +9,25 @@ virt:
image: snapshot.qcow
- cinder-volume:
size: 2048
nic:
control:
- name: nic01
bridge: br-pxe
model: virtio
- name: nic02
bridge: br-cp
model: virtio
- name: nic03
bridge: br-store-front
model: virtio
- name: nic04
bridge: br-public
model: virtio
- name: nic05
bridge: br-prv
model: virtio
virtualport:
type: openvswitch
salt:
minion:
enabled: true

Loading…
Отказ
Запис