Merge "Resolve error when create container with bind volume"
This commit is contained in:
commit
6e8c9a221a
@ -581,7 +581,6 @@ class ContainersController(base.Controller):
|
|||||||
for mount in mounts:
|
for mount in mounts:
|
||||||
volume_dict = {
|
volume_dict = {
|
||||||
'cinder_volume_id': None,
|
'cinder_volume_id': None,
|
||||||
'container_path': None,
|
|
||||||
'auto_remove': False,
|
'auto_remove': False,
|
||||||
'contents': None,
|
'contents': None,
|
||||||
'user_id': context.user_id,
|
'user_id': context.user_id,
|
||||||
@ -593,20 +592,22 @@ class ContainersController(base.Controller):
|
|||||||
volume = cinder_api.search_volume(mount['source'])
|
volume = cinder_api.search_volume(mount['source'])
|
||||||
cinder_api.ensure_volume_usable(volume)
|
cinder_api.ensure_volume_usable(volume)
|
||||||
volume_dict['cinder_volume_id'] = volume.id
|
volume_dict['cinder_volume_id'] = volume.id
|
||||||
volume_dict['container_path'] = mount['destination']
|
|
||||||
volume_dict['volume_provider'] = 'cinder'
|
volume_dict['volume_provider'] = 'cinder'
|
||||||
elif mount.get('size'):
|
elif mount.get('size'):
|
||||||
volume = cinder_api.create_volume(mount['size'])
|
volume = cinder_api.create_volume(mount['size'])
|
||||||
cinder_api.ensure_volume_usable(volume)
|
cinder_api.ensure_volume_usable(volume)
|
||||||
volume_dict['cinder_volume_id'] = volume.id
|
volume_dict['cinder_volume_id'] = volume.id
|
||||||
volume_dict['container_path'] = mount['destination']
|
|
||||||
volume_dict['volume_provider'] = 'cinder'
|
volume_dict['volume_provider'] = 'cinder'
|
||||||
volume_dict['auto_remove'] = True
|
volume_dict['auto_remove'] = True
|
||||||
elif volume_type == 'bind':
|
elif volume_type == 'bind':
|
||||||
volume_dict['contents'] = mount.pop('source', '')
|
volume_dict['contents'] = mount.pop('source', '')
|
||||||
volume_dict['container_path'] = mount['destination']
|
|
||||||
volume_dict['volume_provider'] = 'local'
|
volume_dict['volume_provider'] = 'local'
|
||||||
|
|
||||||
|
volume_object = objects.Volume(context, **volume_dict)
|
||||||
|
volume_object.create(context)
|
||||||
|
volume_dict['volume_id'] = volume_object.id
|
||||||
|
volume_dict['container_path'] = mount['destination']
|
||||||
|
|
||||||
volmapp = objects.VolumeMapping(context, **volume_dict)
|
volmapp = objects.VolumeMapping(context, **volume_dict)
|
||||||
requested_volumes[container.uuid].append(volmapp)
|
requested_volumes[container.uuid].append(volmapp)
|
||||||
|
|
||||||
|
@ -48,7 +48,8 @@ class API(object):
|
|||||||
pci_requests=None):
|
pci_requests=None):
|
||||||
requested_host = extra_spec.get('requested_host')
|
requested_host = extra_spec.get('requested_host')
|
||||||
if requested_host:
|
if requested_host:
|
||||||
self._validate_host(context, new_container, requested_host)
|
self._validate_host(context, new_container, requested_host,
|
||||||
|
requested_volumes)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
host_state = self._schedule_container(context, new_container,
|
host_state = self._schedule_container(context, new_container,
|
||||||
@ -100,13 +101,14 @@ class API(object):
|
|||||||
requested_networks, requested_volumes,
|
requested_networks, requested_volumes,
|
||||||
run, pci_requests)
|
run, pci_requests)
|
||||||
|
|
||||||
def _validate_host(self, context, container, host):
|
def _validate_host(self, context, container, host, requested_volumes):
|
||||||
"""Check whether compute nodes exist by validating the host.
|
"""Check whether compute nodes exist by validating the host.
|
||||||
If host is supplied, we can lookup the ComputeNode in
|
If host is supplied, we can lookup the ComputeNode in
|
||||||
the API DB.
|
the API DB.
|
||||||
|
|
||||||
:param context: The API request context.
|
:param context: The API request context.
|
||||||
:param host: Target host.
|
:param host: Target host.
|
||||||
|
:param requested_volumes: the requested volumes.
|
||||||
:raises: exception.RequestedHostNotFound if we find no compute nodes
|
:raises: exception.RequestedHostNotFound if we find no compute nodes
|
||||||
with host and/or hypervisor_hostname.
|
with host and/or hypervisor_hostname.
|
||||||
"""
|
"""
|
||||||
@ -119,6 +121,11 @@ class API(object):
|
|||||||
LOG.info('No compute node record found for host %(host)s.',
|
LOG.info('No compute node record found for host %(host)s.',
|
||||||
{'host': host})
|
{'host': host})
|
||||||
container.destroy(context)
|
container.destroy(context)
|
||||||
|
for volmap in requested_volumes[container.uuid]:
|
||||||
|
try:
|
||||||
|
volmap._destroy_volume(context)
|
||||||
|
except exception.VolumeNotFound:
|
||||||
|
pass
|
||||||
raise exception.RequestedHostNotFound(host=host)
|
raise exception.RequestedHostNotFound(host=host)
|
||||||
|
|
||||||
def _schedule_container(self, context, new_container, extra_spec):
|
def _schedule_container(self, context, new_container, extra_spec):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user