Add network create function

This commit is contained in:
Daniel Wallace 2014-05-09 12:48:45 -05:00
parent 31cbff6954
commit 7542fba756
3 changed files with 47 additions and 1 deletions

View File

@ -960,7 +960,14 @@ def volume_list(**kwargs):
def network_list(call=None, **kwargs):
'''
Attach block volume
List private networks
'''
conn = get_conn()
return conn.network_list()
def network_create(name, **kwargs):
'''
Create private networks
'''
conn = get_conn()
return conn.network_create(name, **kwargs)

View File

@ -284,6 +284,18 @@ def volume_detach(provider, names, **kwargs):
info = client.volume_action(provider, names, action='detach', **kwargs)
return info
def network_list(provider):
'''
List private networks
'''
client = _get_client()
return action(fun='network_list', provider=provider)
def network_create(provider, names, **kwargs):
'''
Create private network
'''
client = _get_client()
return action(fun='network_create', provider=provider, names=names)

View File

@ -728,6 +728,33 @@ class SaltNova(object):
nt_ks = self.compute_conn
return [network.__dict__ for network in nt_ks.networks.list()]
def _sanatize_network_params(kwargs):
'''
Sanatize novaclient network parameters
'''
params = [
'label', 'bridge', 'bridge_interface', 'cidr', 'cidr_v6', 'dns1',
'dns2', 'fixed_cidr', 'gateway', 'gateway_v6', 'multi_host',
'priority', 'project_id', 'vlan_start', 'vpn_start'
]
for variable in kwargs.keys():
if variable not in params:
del kwargs[variable]
return kwargs
def network_create(self, name, **kwargs):
'''
Create extra private network
'''
nt_ks = self.compute_conn
kwargs['label'] = name
kwargs = _sanatize_network_params(kwargs)
net = nt_ks.networks.create(**kwargs)
log.debug('Network: \n{0}'.format(net))
return net
#The following is a list of functions that need to be incorporated in the
#nova module. This list should be updated as functions are added.
#