Following up patch of 80d8397bd4
This decodes the injected files. Change-Id: I9d23cc084b8af0af621b04dd5516ad220bb69c2c
This commit is contained in:
parent
80d8397bd4
commit
ef81b84b73
|
@ -626,6 +626,7 @@ class InstanceController(InstanceControllerBase):
|
|||
except (exception.GlanceConnectionFailed,
|
||||
exception.InstanceUserDataMalformed,
|
||||
exception.InstanceUserDataTooLarge,
|
||||
exception.Base64Exception,
|
||||
exception.NetworkRequiresSubnet,
|
||||
exception.NetworkNotFound) as e:
|
||||
raise wsme.exc.ClientSideError(
|
||||
|
|
|
@ -396,4 +396,8 @@ class InstanceUserDataMalformed(MoganException):
|
|||
msg_fmt = _("User data needs to be valid base 64.")
|
||||
|
||||
|
||||
class Base64Exception(MoganException):
|
||||
_msg_fmt = _("Invalid Base 64 data for file %(path)s")
|
||||
|
||||
|
||||
ObjectActionError = obj_exc.ObjectActionError
|
||||
|
|
|
@ -15,6 +15,9 @@
|
|||
|
||||
"""Handles all requests relating to compute resources"""
|
||||
|
||||
import base64
|
||||
import binascii
|
||||
|
||||
from oslo_log import log
|
||||
from oslo_serialization import base64 as base64utils
|
||||
from oslo_utils import excutils
|
||||
|
@ -168,6 +171,22 @@ class API(object):
|
|||
else:
|
||||
raise exception.OverQuota(overs='instances')
|
||||
|
||||
def _decode_files(self, injected_files):
|
||||
"""Base64 decode the list of files to inject."""
|
||||
if not injected_files:
|
||||
return []
|
||||
|
||||
def _decode(f):
|
||||
path, contents = f
|
||||
# Py3 raises binascii.Error instead of TypeError as in Py27
|
||||
try:
|
||||
decoded = base64.b64decode(contents)
|
||||
return path, decoded
|
||||
except (TypeError, binascii.Error):
|
||||
raise exception.Base64Exception(path=path)
|
||||
|
||||
return [_decode(f) for f in injected_files]
|
||||
|
||||
def _provision_instances(self, context, base_options,
|
||||
min_count, max_count):
|
||||
# Return num_instances according quota
|
||||
|
@ -245,6 +264,8 @@ class API(object):
|
|||
max_count = max_net_count
|
||||
|
||||
# TODO(zhenguo): Check injected file quota
|
||||
# b64 decode the files to inject:
|
||||
decoded_files = self._decode_files(injected_files)
|
||||
|
||||
instances = self._provision_instances(context, base_options,
|
||||
min_count, max_count)
|
||||
|
@ -265,7 +286,7 @@ class API(object):
|
|||
self.engine_rpcapi.create_instance(context, instance,
|
||||
requested_networks,
|
||||
user_data,
|
||||
injected_files,
|
||||
decoded_files,
|
||||
request_spec,
|
||||
filter_properties=None)
|
||||
|
||||
|
|
Loading…
Reference in New Issue