liusheng 3e3dc6a8a1 Improve flavor set command to support updating flavor
For now, "flavor set" command only support to add flavor accesses, this
change add support to updating flavor other attributes for this command.

Change-Id: If32a46decebee62695f4e4f7f51c2fafbb64b5bf
2017-08-15 11:40:32 +08:00

65 lines
2.0 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 update(self, flavor, data):
url = '/flavors/%s' % base.getid(flavor)
return self._update(url, data)
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)