Implement network association in OS API
Networks are associated with projects automatically during launch of an instance. The network is chosen rather randomly. This commit adds support for association of given network and project. DocImpact - when this lands, need to update openstack-manuals repo: doc/src/docbkx/openstack-api-site/src/wadls/compute-api/src/ext/os-networks.wadl Implements: blueprint os-api-network-associate Change-Id: Iafaf4a5ae3d3e16a6c649f1d7850fceba732efab
This commit is contained in:
committed by
annegentle
parent
f3accd2d61
commit
00b03e9094
@@ -779,9 +779,9 @@ def key_pair_count_by_user(context, user_id):
|
||||
####################
|
||||
|
||||
|
||||
def network_associate(context, project_id, force=False):
|
||||
def network_associate(context, project_id, network_id=None, force=False):
|
||||
"""Associate a free network to a project."""
|
||||
return IMPL.network_associate(context, project_id, force)
|
||||
return IMPL.network_associate(context, project_id, network_id, force)
|
||||
|
||||
|
||||
def network_count(context):
|
||||
|
||||
@@ -1996,7 +1996,7 @@ def key_pair_count_by_user(context, user_id):
|
||||
|
||||
|
||||
@require_admin_context
|
||||
def network_associate(context, project_id, force=False):
|
||||
def network_associate(context, project_id, network_id=None, force=False):
|
||||
"""Associate a project with a network.
|
||||
|
||||
called by project_get_networks under certain conditions
|
||||
@@ -2014,10 +2014,13 @@ def network_associate(context, project_id, force=False):
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
|
||||
def network_query(project_filter):
|
||||
def network_query(project_filter, id=None):
|
||||
filter_kwargs = {'project_id': project_filter}
|
||||
if id is not None:
|
||||
filter_kwargs['id'] = id
|
||||
return model_query(context, models.Network, session=session,
|
||||
read_deleted="no").\
|
||||
filter_by(project_id=project_filter).\
|
||||
filter_by(**filter_kwargs).\
|
||||
with_lockmode('update').\
|
||||
first()
|
||||
|
||||
@@ -2030,7 +2033,7 @@ def network_associate(context, project_id, force=False):
|
||||
# with a new network
|
||||
|
||||
# get new network
|
||||
network_ref = network_query(None)
|
||||
network_ref = network_query(None, network_id)
|
||||
if not network_ref:
|
||||
raise db.NoMoreNetworks()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user