Explorar el Código

Adding virtualport interface attribute for nic

Prod-Related: PROD-20747

Change-Id: Id7822963ab45ff7db3252f5329a9376aa4bf10d6
pull/73/head
Dzmitry Stremkouski hace 6 años
padre
commit
b8acf1f9c8
Se han modificado 3 ficheros con 71 adiciones y 56 borrados
  1. +5
    -0
      README.rst
  2. +47
    -56
      _modules/virtng.py
  3. +19
    -0
      tests/pillar/control_virt_custom.sls

+ 5
- 0
README.rst Ver fichero

- name: nic04 - name: nic04
bridge: br-public bridge: br-public
model: virtio model: virtio
- name: nic05
bridge: br-prv
model: virtio
virtualport:
type: openvswitch




salt: salt:

+ 47
- 56
_modules/virtng.py Ver fichero



def _nic_profile(profile_name, 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): def append_dict_profile_to_interface_list(profile_dict):
for interface_name, attributes in profile_dict.items(): for interface_name, attributes in profile_dict.items():
attributes['name'] = interface_name attributes['name'] = interface_name
interfaces.append(attributes) 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): def _normalize_net_types(attributes):
''' '''
Guess which style of definition: Guess which style of definition:


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


def _apply_default_overlay(attributes): def _apply_default_overlay(attributes):
for key, value in overlays[hypervisor].items(): for key, value in overlays[hypervisor].items():
else: else:
attributes['mac'] = salt.utils.gen_mac() 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: for interface in interfaces:
_normalize_net_types(interface) _normalize_net_types(interface)
_assign_mac(interface) _assign_mac(interface)


xml = _gen_xml(name, cpu, mem, diskp, nicp, hypervisor, **kwargs) 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 # TODO: Remove this code and refactor module, when salt-common would have updated libvirt_domain.jinja template
if rng: if rng:
rng_model = rng.get('model', 'random') rng_model = rng.get('model', 'random')

+ 19
- 0
tests/pillar/control_virt_custom.sls Ver fichero

image: snapshot.qcow image: snapshot.qcow
- cinder-volume: - cinder-volume:
size: 2048 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: salt:
minion: minion:
enabled: true enabled: true

Cargando…
Cancelar
Guardar