mirror of
https://github.com/linux-system-roles/network.git
synced 2026-07-21 10:18:27 +00:00
library: refactor getting master connection
Move the utility functions to ArgUtil class.
This commit is contained in:
parent
2cd6d3dbdf
commit
36cd010fe9
1 changed files with 23 additions and 21 deletions
|
|
@ -404,6 +404,25 @@ class ArgUtil:
|
|||
c = connection
|
||||
return c
|
||||
|
||||
@staticmethod
|
||||
def connection_find_master(name, connections, n_connections = None):
|
||||
c = ArgUtil.connection_find_by_name(name, connections, n_connections)
|
||||
if not c:
|
||||
raise MyError('invalid master/parent "%s"' % (name))
|
||||
if c['interface_name'] is None:
|
||||
raise MyError('invalid master/parent "%s" which needs an "interface_name"' % (name))
|
||||
if not Util.ifname_valid(c['interface_name']):
|
||||
raise MyError('invalid master/parent "%s" which has not a valid "interface_name" ("%s")' % (name, c['interface_name']))
|
||||
return c['interface_name']
|
||||
|
||||
@staticmethod
|
||||
def connection_find_master_uuid(name, connections, n_connections = None):
|
||||
c = ArgUtil.connection_find_by_name(name, connections, n_connections)
|
||||
if not c:
|
||||
raise MyError('invalid master/parent "%s"' % (name))
|
||||
assert c.get('nm.uuid', None)
|
||||
return c['nm.uuid']
|
||||
|
||||
@staticmethod
|
||||
def connection_get_non_absent_names(connections):
|
||||
# @idx is the index with state['absent']. This will
|
||||
|
|
@ -926,15 +945,6 @@ class IfcfgUtil:
|
|||
s += '"'
|
||||
return s
|
||||
|
||||
@classmethod
|
||||
def _connection_find_master(cls, name, connections, n_connections = None):
|
||||
c = ArgUtil.connection_find_by_name(name, connections, n_connections)
|
||||
if not c:
|
||||
raise MyError('invalid master/parent "%s"' % (name))
|
||||
if not Util.ifname_valid(c['interface_name']):
|
||||
raise MyError('invalid master/parent "%s" which has not a valid interface name ("%s")' % (name, c['interface_name']))
|
||||
return c['interface_name']
|
||||
|
||||
@classmethod
|
||||
def ifcfg_create(cls, connections, idx, warn_fcn):
|
||||
connection = connections[idx]
|
||||
|
|
@ -976,7 +986,7 @@ class IfcfgUtil:
|
|||
elif connection['type'] == 'vlan':
|
||||
ifcfg['VLAN'] = 'yes'
|
||||
ifcfg['TYPE'] = 'Vlan'
|
||||
ifcfg['PHYSDEV'] = cls._connection_find_master(connection['parent'], connections, idx)
|
||||
ifcfg['PHYSDEV'] = ArgUtil.connection_find_master(connection['parent'], connections, idx)
|
||||
ifcfg['VID'] = str(connection['vlan_id'])
|
||||
else:
|
||||
raise MyError('unsupported type %s' % (connection['type']))
|
||||
|
|
@ -985,7 +995,7 @@ class IfcfgUtil:
|
|||
ifcfg['MTU'] = str(connection['mtu'])
|
||||
|
||||
if connection['master'] is not None:
|
||||
m = cls._connection_find_master(connection['master'], connections, idx)
|
||||
m = ArgUtil.connection_find_master(connection['master'], connections, idx)
|
||||
if connection['slave_type'] == 'bridge':
|
||||
ifcfg['BRIDGE'] = m
|
||||
elif connection['slave_type'] == 'bond':
|
||||
|
|
@ -1238,14 +1248,6 @@ class NMUtil:
|
|||
|
||||
return not(not(con_a.compare (con_b, compare_flags)))
|
||||
|
||||
@staticmethod
|
||||
def _connection_find_master_uuid(name, connections, n_connections = None):
|
||||
c = ArgUtil.connection_find_by_name(name, connections, n_connections)
|
||||
if not c:
|
||||
raise MyError('invalid master/parent "%s"' % (name))
|
||||
assert c.get('nm.uuid', None)
|
||||
return c['nm.uuid']
|
||||
|
||||
def connection_create(self, connections, idx):
|
||||
NM = Util.NM()
|
||||
|
||||
|
|
@ -1278,7 +1280,7 @@ class NMUtil:
|
|||
elif connection['type'] == 'vlan':
|
||||
s_vlan = self.connection_ensure_setting(con, NM.SettingVlan)
|
||||
s_vlan.set_property(NM.SETTING_VLAN_ID, connection['vlan_id'])
|
||||
s_vlan.set_property(NM.SETTING_VLAN_PARENT, self._connection_find_master_uuid(connection['parent'], connections, idx))
|
||||
s_vlan.set_property(NM.SETTING_VLAN_PARENT, ArgUtil.connection_find_master_uuid(connection['parent'], connections, idx))
|
||||
else:
|
||||
raise MyError('unsupported type %s' % (connection['type']))
|
||||
|
||||
|
|
@ -1288,7 +1290,7 @@ class NMUtil:
|
|||
|
||||
if connection['master'] is not None:
|
||||
s_con.set_property(NM.SETTING_CONNECTION_SLAVE_TYPE, connection['slave_type'])
|
||||
s_con.set_property(NM.SETTING_CONNECTION_MASTER, self._connection_find_master_uuid(connection['master'], connections, idx))
|
||||
s_con.set_property(NM.SETTING_CONNECTION_MASTER, ArgUtil.connection_find_master_uuid(connection['master'], connections, idx))
|
||||
else:
|
||||
ip = connection['ip']
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue