
Partially Implements: bp new-flavor Depends-On: I5fa154dbf8bc96d15c3cdd3699c671e5eccc1cdd Change-Id: I5f56b5975f0d48ae0a9a1c70598604494901189b
61 lines
1.9 KiB
Python
61 lines
1.9 KiB
Python
# Copyright 2016 Huawei, Inc. All rights reserved.
|
|
#
|
|
# 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.
|
|
#
|
|
|
|
from moganclient.common import base
|
|
|
|
|
|
class Flavor(base.Resource):
|
|
pass
|
|
|
|
|
|
class FlavorManager(base.ManagerWithFind):
|
|
resource_class = Flavor
|
|
|
|
def create(self, name, resources, resource_traits, is_public, disabled,
|
|
description=None):
|
|
url = '/flavors'
|
|
data = {
|
|
'name': name,
|
|
'description': description,
|
|
'is_public': is_public,
|
|
'disabled': disabled,
|
|
}
|
|
if resources:
|
|
data['resources'] = resources
|
|
if resource_traits:
|
|
data['resource_traits'] = resource_traits
|
|
return self._create(url, data=data)
|
|
|
|
def delete(self, flavor):
|
|
url = '/flavors/%s' % base.getid(flavor)
|
|
return self._delete(url)
|
|
|
|
def get(self, flavor):
|
|
url = '/flavors/%s' % base.getid(flavor)
|
|
return self._get(url)
|
|
|
|
def list(self):
|
|
url = '/flavors'
|
|
return self._list(url, response_key='flavors')
|
|
|
|
def add_tenant_access(self, flavor, project):
|
|
url = '/flavors/%s/access' % base.getid(flavor)
|
|
return self._create(url, data={'tenant_id': project})
|
|
|
|
def remove_tenant_access(self, flavor, project):
|
|
url = '/flavors/%(id)s/access/%(project)s' % {
|
|
'id': base.getid(flavor), 'project': project}
|
|
return self._delete(url)
|