Initial support of working with package definitions

Support the following operations:
* create (upload)
* download
* delete
* categories (get list of available category names)

Also support get, get_logo and get_ui operations for AppCatalog.

Use the `requests` library to encode form data parsed by Django back
into multipart/form-data (as murano-api expects uploaded package data
to be in this format).

Change-Id: Id83f9960e0ee9a67be8ecd37a9a4ff18cd1f21fa
Partially-implements: blueprint service-defitions-migrate-to-apps-ui
This commit is contained in:
Timur Sufiev 2014-04-02 18:25:01 +04:00
parent 56a3a4c620
commit 3e387adf1e
3 changed files with 93 additions and 0 deletions

View File

@ -15,6 +15,7 @@
from muranoclient.common import http
from muranoclient.v1 import environments, sessions, services, deployments
from muranoclient.v1 import statistics
from muranoclient.v1 import packages
class Client(http.HTTPClient):
@ -33,4 +34,5 @@ class Client(http.HTTPClient):
self.sessions = sessions.SessionManager(self)
self.services = services.ServiceManager(self)
self.deployments = deployments.DeploymentManager(self)
self.packages = packages.PackageManager(self)
self.statistics = statistics.StatisticsManager(self)

View File

@ -0,0 +1,89 @@
# Copyright (c) 2014 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import json
from muranoclient.common import base
from muranoclient.common import exceptions
import requests
import yaml
class Package(base.Resource):
def __repr__(self):
return "<Package %s>" % self._info
def data(self, **kwargs):
return self.manager.data(self, **kwargs)
class Category(base.Resource):
def __init__(self, manager, info, loaded=False):
self.value = info
def __unicode__(self):
return self.value
def __repr__(self):
return self.value
class PackageManager(base.Manager):
resource_class = Package
def list(self):
return self._list('/v1/catalog/packages', 'packages')
def categories(self):
return self._list('/v1/catalog/packages/categories',
response_key='categories', obj_class=Category)
def create(self, data, files):
data = {'data': json.dumps(data)}
url = '{0}/v1/catalog/packages'.format(self.api.endpoint)
headers = {'X-Auth-Token': self.api.auth_token}
response = requests.post(url, data=data, files=files, headers=headers)
if not response.ok:
setattr(response, 'status', response.status_code)
raise exceptions.from_response(response)
return response
def get(self, app_id):
return self._get('/v1/catalog/packages/{0}'.format(app_id))
def delete(self, app_id):
return self._delete('/v1/catalog/packages/{0}'.format(app_id))
def download(self, app_id):
url = '/v1/catalog/packages/{0}/download'.format(app_id)
response, iterator = self.api.raw_request('GET', url)
if response.status == 200:
return ''.join(iterator)
else:
raise exceptions.from_response(response)
def get_ui(self, app_id):
url = '/v1/catalog/packages/{0}/ui'.format(app_id)
response, iterator = self.api.raw_request('GET', url)
if response.status == 200:
return yaml.load(''.join(iterator))
else:
raise exceptions.from_response(response)
def get_logo(self, app_id):
url = '/v1/catalog/packages/{0}/logo'.format(app_id)
response, iterator = self.api.raw_request('GET', url)
if response.status == 200:
return ''.join(iterator)
else:
raise exceptions.from_response(response)

View File

@ -7,3 +7,5 @@ iso8601>=0.1.8
six>=1.5.2
Babel>=1.3
pyOpenSSL>=0.11
requests>=1.1
PyYAML>=3.1.0