Minor refactor of get_security_group_ids
Move the check of security_group field into the method. Change-Id: I488f6b6d70431f30bd1190e7123dbb54fcc17667
This commit is contained in:
parent
6a95bebb2c
commit
d1d77e386e
@ -573,8 +573,6 @@ class DockerDriver(driver.ContainerDriver):
|
|||||||
sandbox = docker.create_container(image, name=name,
|
sandbox = docker.create_container(image, name=name,
|
||||||
hostname=name[:63])
|
hostname=name[:63])
|
||||||
self.set_sandbox_id(container, sandbox['Id'])
|
self.set_sandbox_id(container, sandbox['Id'])
|
||||||
security_group_ids = None
|
|
||||||
if container.security_groups is not None:
|
|
||||||
security_group_ids = self._get_security_group_ids(
|
security_group_ids = self._get_security_group_ids(
|
||||||
context, container.security_groups)
|
context, container.security_groups)
|
||||||
# Container connects to the bridge network by default so disconnect
|
# Container connects to the bridge network by default so disconnect
|
||||||
@ -596,7 +594,9 @@ class DockerDriver(driver.ContainerDriver):
|
|||||||
return sandbox['Id']
|
return sandbox['Id']
|
||||||
|
|
||||||
def _get_security_group_ids(self, context, security_groups):
|
def _get_security_group_ids(self, context, security_groups):
|
||||||
if security_groups:
|
if security_groups is None:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
neutron = clients.OpenStackClients(context).neutron()
|
neutron = clients.OpenStackClients(context).neutron()
|
||||||
search_opts = {'tenant_id': context.project_id}
|
search_opts = {'tenant_id': context.project_id}
|
||||||
security_groups_list = neutron.list_security_groups(
|
security_groups_list = neutron.list_security_groups(
|
||||||
@ -609,8 +609,6 @@ class DockerDriver(driver.ContainerDriver):
|
|||||||
raise exception.ZunException(_(
|
raise exception.ZunException(_(
|
||||||
"Any of the security group in %s is not found ") %
|
"Any of the security group in %s is not found ") %
|
||||||
security_groups)
|
security_groups)
|
||||||
else:
|
|
||||||
return []
|
|
||||||
|
|
||||||
def _get_available_network(self, context):
|
def _get_available_network(self, context):
|
||||||
neutron = clients.OpenStackClients(context).neutron()
|
neutron = clients.OpenStackClients(context).neutron()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user