fix container run defect

Some problems were found in the development of enterprise projects:

1.After repairing the container operation, the return parameter does not include the time parameter. It is necessary to judge whether to restart and obtain the running time in the business development. Compared with nova, the return info of the VM also contains the above information.

2.When creating a container, if a custom security group created with neutron is also associated, the expose_ports parameter is also given, which will cause the custom security group parameters to be overwritten, which is very important for the container to increase the exposure range of ports. Important, but it is currently a failure.

Change-Id: I1f5c2ddc835d91c14ae8936c0fb7f79d418ba804
This commit is contained in:
ycj 2021-10-26 15:03:57 +08:00 committed by yangchangjia
parent 7ed094696b
commit a053176dfe
2 changed files with 12 additions and 9 deletions

View File

@ -52,6 +52,8 @@ _basic_keys = (
'cpu_policy',
'registry_id',
'entrypoint',
'created_at',
'updated_at',
)

View File

@ -39,7 +39,6 @@ from zun.image import driver as img_driver
from zun.network import network as zun_network
from zun import objects
CONF = zun.conf.CONF
LOG = logging.getLogger(__name__)
ATTACH_FLAG = "/attach/ws?logs=0&stream=1&stdin=1&stdout=1&stderr=1"
@ -86,7 +85,6 @@ def handle_not_found(e, context, container, do_not_raise=False):
def wrap_docker_error(function):
@functools.wraps(function)
def decorated_function(*args, **kwargs):
context = args[1]
@ -382,6 +380,9 @@ class DockerDriver(driver.BaseDriver, driver.ContainerDriver,
secgroup_id = neutron_api.create_security_group({'security_group': {
"name": secgroup_name}})['security_group']['id']
neutron_api.expose_ports(secgroup_id, exposed_ports)
if container.security_groups:
container.security_groups.append(secgroup_id)
else:
container.security_groups = [secgroup_id]
# process kwargs on creating the docker container
ports = []
@ -667,8 +668,8 @@ class DockerDriver(driver.BaseDriver, driver.ContainerDriver,
container.status = status
status_detail = self.format_status_detail(
state.get('FinishedAt'))
container.status_detail = "Exited({}) {} ago " \
"(error)".format(state.get('ExitCode'), status_detail)
container.status_detail = "Exited({}) {} ago (error)".format(
state.get('ExitCode'), status_detail)
elif state.get('Paused'):
container.status = consts.PAUSED
status_detail = self.format_status_detail(