mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +00:00
Delete the Nic classes from my previous implemntation
Not sure what I did, but when I was squashing, I accidently this in.
This commit is contained in:
parent
960a875420
commit
48fab47e09
@ -450,98 +450,6 @@ def _get_image_info(hypervisor, name, **kwargs):
|
||||
ret['pool'] = __salt__['config.option']('virt.images')
|
||||
return ret
|
||||
|
||||
|
||||
class _Interface(object):
|
||||
def __init__(self,
|
||||
name=None,
|
||||
source=None,
|
||||
type=None, # pylint: disable=redefined-builtin
|
||||
model='virtio',
|
||||
mac=None,
|
||||
**kwargs):
|
||||
if not (source and type):
|
||||
raise Exception('Need a source and type for _Interface, '
|
||||
'got: \'{0}\' and \'{1}\' respectively'
|
||||
.format(source, type))
|
||||
self.name = name
|
||||
self.model = model
|
||||
self.source = source
|
||||
self.type = type
|
||||
|
||||
if mac is not None:
|
||||
self.mac = mac
|
||||
else:
|
||||
self.mac = salt.utils.gen_mac()
|
||||
|
||||
def __str__(self):
|
||||
return ('Name: {0}, Type: {1}, Source: {2}, '
|
||||
'Model: {3}, MAC: {4}'
|
||||
.format(self.name, self.type, self.source, self.model, self.mac))
|
||||
|
||||
def __repr__(self):
|
||||
return '{0} ({1})'.format(self.__class__, self.__str__())
|
||||
|
||||
|
||||
class _NicProfile(object):
|
||||
default = {'eth0': {'bridge': 'br0', 'model': 'virtio'}}
|
||||
|
||||
def __init__(self, name):
|
||||
self.interfaces = []
|
||||
self.name = name
|
||||
|
||||
config_data = __salt__['config.option']('virt.nic', {}).get(
|
||||
name, self.__class__.default
|
||||
)
|
||||
|
||||
# support old style dicts
|
||||
if isinstance(config_data, dict):
|
||||
for interface_name, attributes in config_data.items():
|
||||
attributes['name'] = interface_name
|
||||
self.interfaces.append(attributes)
|
||||
|
||||
# new style lists
|
||||
elif isinstance(config_data, list):
|
||||
self.interfaces = config_data
|
||||
|
||||
for interface in self.interfaces:
|
||||
self._normalize_net_types(interface)
|
||||
|
||||
def _normalize_net_types(self, attributes):
|
||||
'''
|
||||
Guess which style of definition:
|
||||
|
||||
bridge: br0
|
||||
|
||||
network: net0
|
||||
|
||||
type: network
|
||||
source: net0
|
||||
'''
|
||||
for type_ in ['bridge', 'network']:
|
||||
if type_ in attributes:
|
||||
attributes['type'] = type_
|
||||
# we want to discard the original key
|
||||
attributes['source'] = attributes.pop(type_)
|
||||
|
||||
attributes['type'] = attributes.get('type', None)
|
||||
attributes['source'] = attributes.get('source', None)
|
||||
|
||||
def __str__(self):
|
||||
lines = []
|
||||
for interface in self.interfaces:
|
||||
lines.append(interface.__str__())
|
||||
return '\n'.join(lines)
|
||||
|
||||
def create_interfaces(self, **kwargs):
|
||||
results = []
|
||||
for interface in self.interfaces:
|
||||
dmac = '{0}_mac'.format(interface['name'])
|
||||
if dmac in kwargs:
|
||||
interface['mac'] = kwargs[dmac]
|
||||
results.append(_Interface(**interface))
|
||||
return results
|
||||
|
||||
|
||||
def _disk_profile(profile, hypervisor, **kwargs):
|
||||
'''
|
||||
Gather the disk profile from the config or apply the default based
|
||||
|
Loading…
Reference in New Issue
Block a user