Files
deb-python-fuelclient/fuelclient/objects/openstack_config.py
Alexander Saprykin 88274ba134 Implement CLI v1 for openstack configuration
Add openstack-config commands for fuel
Examples for fuel:

fuel openstack-config --env 1 --list
fuel openstack-config --env 1 [--node 1 | --role controller] --upload
    --file config.yaml
fuel openstack-config --config 1 --download --file config.yaml
fuel openstack-config --env 1 [--node 1 | --role controller] --execute

Change-Id: Id701d4b8408bd275ac6e7bc53ca23b9f3deb4f6d
Implements: blueprint openstack-config-change
2015-11-30 15:30:38 +02:00

68 lines
2.1 KiB
Python

# Copyright 2015 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 os
import six
from fuelclient.cli import error
from fuelclient.cli.serializers import Serializer
from fuelclient.objects.base import BaseObject
class OpenstackConfig(BaseObject):
class_api_path = 'openstack-config/'
instance_api_path = 'openstack-config/{0}/'
execute_api_path = 'openstack-config/execute/'
@classmethod
def _prepare_params(cls, filters):
return dict((k, v) for k, v in six.iteritems(filters) if v is not None)
@classmethod
def create(cls, **kwargs):
params = cls._prepare_params(kwargs)
data = cls.connection.post_request(cls.class_api_path, params)
return cls.init_with_data(data)
def delete(self):
return self.connection.delete_request(
self.instance_api_path.format(self.id))
@classmethod
def execute(cls, **kwargs):
params = cls._prepare_params(kwargs)
return cls.connection.put_request(cls.execute_api_path, params)
@classmethod
def get_filtered_data(cls, **kwargs):
url = cls.class_api_path
params = cls._prepare_params(kwargs)
return cls.connection.get_request(url, params=params)
@classmethod
def read_file(cls, path):
if not os.path.exists(path):
raise error.InvalidFileException(
"File '{0}' doesn't exist.".format(path))
serializer = Serializer()
return serializer.read_from_full_path(path)
@classmethod
def write_file(cls, path, data):
serializer = Serializer()
return serializer.write_to_full_path(path, data)