Merge "Send the binary data instead of path"
This commit is contained in:
commit
092ae16191
|
@ -40,7 +40,7 @@ class AppManager(base.Manager):
|
|||
def upload(self, data):
|
||||
"""Stage the specified application, getting it ready for deployment.
|
||||
|
||||
:param data: application name and location of tarfile
|
||||
:param data: application name and location of tarfile and the binary of the tarfile
|
||||
"""
|
||||
return self._create(self._path(), data)
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
import base64
|
||||
import os
|
||||
import re
|
||||
|
||||
|
@ -105,6 +106,15 @@ def do_application_show(cc, args):
|
|||
def do_application_upload(cc, args):
|
||||
"""Upload application Helm chart(s) and manifest"""
|
||||
data = _application_check(args)
|
||||
|
||||
if not _is_url(data["tarfile"]):
|
||||
try:
|
||||
with open(data["tarfile"], 'rb') as tarfile:
|
||||
binary_data = base64.urlsafe_b64encode(tarfile.read())
|
||||
data.update({'binary_data': binary_data})
|
||||
except Exception:
|
||||
raise exc.CommandError("Error: Could not open file %s." % data["tarfile"])
|
||||
|
||||
response = cc.app.upload(data)
|
||||
_print_application_show(response)
|
||||
_print_reminder_msg(response.name)
|
||||
|
|
|
@ -4,10 +4,13 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
import base64
|
||||
import os
|
||||
import hashlib
|
||||
import pecan
|
||||
import pwd
|
||||
from pecan import rest
|
||||
import time
|
||||
import wsme
|
||||
from wsme import types as wtypes
|
||||
import wsmeext.pecan as wsme_pecan
|
||||
|
@ -200,10 +203,30 @@ class KubeAppController(rest.RestController):
|
|||
@wsme_pecan.wsexpose(KubeApp, body=types.apidict)
|
||||
def post(self, body):
|
||||
"""Uploading an application to be deployed by Armada"""
|
||||
tarfile = body.get('tarfile')
|
||||
tarfile_path = body.get('tarfile')
|
||||
tarfile_binary = body.get('binary_data', '')
|
||||
name = body.get('name', '')
|
||||
version = body.get('app_version', '')
|
||||
name, version, mname, mfile = self._check_tarfile(tarfile, name, version,
|
||||
|
||||
if not cutils.is_url(tarfile_path) and not os.path.exists(tarfile_path):
|
||||
path_tarballs = '/tmp/tarball_uploads'
|
||||
if not os.path.exists(path_tarballs):
|
||||
os.makedirs(path_tarballs)
|
||||
uid, gid = pwd.getpwnam('sysinv').pw_uid, pwd.getpwnam('sysinv').pw_uid
|
||||
os.chown(path_tarballs, uid, gid)
|
||||
|
||||
# Keep unique tarball name to avoid conflicts
|
||||
tarball_name = '{}-{}'.format(time.time(), os.path.basename(tarfile_path))
|
||||
tarfile_path = os.path.join(path_tarballs, tarball_name)
|
||||
try:
|
||||
with open(tarfile_path, 'wb') as f:
|
||||
f.write(base64.urlsafe_b64decode(tarfile_binary))
|
||||
except Exception as e:
|
||||
LOG.exception('Error: writing the tarfile: {}'.format(e))
|
||||
raise wsme.exc.ClientSideError(_(
|
||||
"Could not save the application on path {}".format(tarfile_path)))
|
||||
|
||||
name, version, mname, mfile = self._check_tarfile(tarfile_path, name, version,
|
||||
constants.APP_UPLOAD_OP)
|
||||
|
||||
try:
|
||||
|
@ -231,7 +254,7 @@ class KubeAppController(rest.RestController):
|
|||
lifecycle_hook_info.mode = constants.APP_LIFECYCLE_MODE_MANUAL
|
||||
|
||||
pecan.request.rpcapi.perform_app_upload(pecan.request.context,
|
||||
new_app, tarfile,
|
||||
new_app, tarfile_path,
|
||||
lifecycle_hook_info=lifecycle_hook_info)
|
||||
return KubeApp.convert_with_links(new_app)
|
||||
|
||||
|
|
|
@ -126,7 +126,11 @@ class ApiDictType(wtypes.UserType):
|
|||
name = 'apidict'
|
||||
__name__ = name
|
||||
|
||||
basetype = {wtypes.text: apiutils.ValidTypes(wtypes.text, six.integer_types)}
|
||||
basetype = {wtypes.text: apiutils.ValidTypes(
|
||||
wtypes.text,
|
||||
six.integer_types,
|
||||
wsme.types.bytes
|
||||
)}
|
||||
|
||||
|
||||
apidict = ApiDictType()
|
||||
|
|
Loading…
Reference in New Issue