Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set interfaces by name if defined (WIP) #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,46 @@ Single maas service
server:
enabled: true

Configure node interfaces.

Interfaces are identified by provided `name` or by `mac` if `name` is not provided or not found.
When configured name is not found interface name will be renamed.

.. code-block:: yaml

maas:
region:
machines:
machine1:
pxe_interface_mac: "11:22:33:44:55:66"
interfaces:
nic01:
name: eth0
mac: "11:22:33:44:55:66"
mode: "static"
ip: "2.2.3.19"
subnet: "subnet1"
gateway: "2.2.3.2"
machine1:
pxe_interface_mac: "11:22:33:44:55:77"
interfaces:
nic01:
name: eth0
mode: manual
nic02:
name: eth0
mode: manual
bond0:
mode: dhcp
type: bond
subnet: "subnet1"
bond_mode: active-backup
parents: nic01,nic02
bond0.10
mode: auto
type: bond
parents: bond0

Single MAAS region service [single UI/API]

.. code-block:: yaml
Expand Down
43 changes: 40 additions & 3 deletions _modules/maas.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,18 @@ def _get_nic_id_by_mac(self, machine, req_mac=None):
'node:{}'.format(req_mac, machine['fqdn']))
return data

def _get_nic_id_by_name(self, machine, req_name=None):
data = {}
for nic in machine['interface_set']:
data[nic['name']] = nic['id']
if req_name:
if req_name in data.keys():
return data[req_name]
else:
raise Exception('NIC with name:{} not found at '
'node:{}'.format(req_name, machine['fqdn']))
return data

def _disconnect_all_nic(self, machine):
"""
Maas will fail, in case same config's will be to apply
Expand Down Expand Up @@ -538,7 +550,18 @@ def _process_interface(self, nic_data, machine):
external "process" method. Those broke old-MaasObject logic,
though make functions more simple in case iterable tasks.
"""
nic_id = self._get_nic_id_by_mac(machine, nic_data['mac'])

if nic_data.has_key('name'):
try:
nic_id = self._get_nic_id_by_mac(machine, nic_data['name'])
except Exception as e:
LOG.warn("Failed to find interface: {} on node: {}. Will try now by its MAC: {}".format(
nic_data['name'], machine['fqdn'], nic_data['mac_address']))
nic_id = False

if not nic_id:
# assume MAC is always provided
nic_id = self._get_nic_id_by_mac(machine, nic_data['mac'])

# Process op=link_subnet
link_data = {}
Expand Down Expand Up @@ -569,9 +592,23 @@ def _process_interface(self, nic_data, machine):
"tags": nic_data.get('tags', ""),
"vlan": nic_data.get('vlan', "")}

if nic_data.has_key('type'):
# set parents
_bond_parents=[]
if nic_data.['type'] in ('bond', 'vlan', 'bridge'):
for p_name in nic_data['parents'].split(',').split():
p_id = _get_nic_id_by_name(p_name)[p_name]
_bond_parents.append(p_id)
if len(_bond_parents) > 0:
physical_data['parents'] = _bond_parents
# set bond options
if nic_data.['type'] in ('bond'):
for k in [ k in nic_data.keys() if k.startwith('bond_'):
physical_data[k] = nic_data[k]

try:
# Cleanup-old definition
LOG.debug("Processing {}:{},{}".format(nic_data['mac'], link_data,
LOG.debug("Processing {}:{},{}".format(nic_data['name'], link_data,
physical_data))
# "link_subnet" and "fill all other data" - its 2 different
# operations. So, first we update NIC:
Expand All @@ -586,7 +623,7 @@ def _process_interface(self, nic_data, machine):
'link_subnet', **link_data)
except Exception as e:
LOG.error("Failed to process interface:{} on node:{}".format(
nic_data['mac'], machine['fqdn']))
nic_data['name'], machine['fqdn']))
raise Exception(str(e))

def fill_data(self, name, data, machines):
Expand Down