Add possibility of editing cluster's attributes

Since Fuel 6.1 we have ability to add external repositories and change
them via UI. The set of repos are the part of cluster's attributes, so
in order to change them we have to provide the ability of changing any
of them.

This patch adds ability to download and upload cluster attributes
into/from yaml file, just like it's implemented for deployment tasks.

Implements: blueprint consume-external-ubuntu
Change-Id: I7a17d8da299b43940f20572d44615c21036538ab
This commit is contained in:
Igor Kalnitsky
2015-03-25 12:27:40 +02:00
parent 3624051242
commit f377817c7e
4 changed files with 97 additions and 2 deletions

View File

@@ -64,6 +64,7 @@ class EnvironmentAction(Action):
"Set network segment type"
),
Args.get_deployment_tasks_arg("Environment tasks configuration."),
Args.get_attributes_arg("Environment attributes."),
group(
Args.get_download_arg(
"Download configuration of specific cluster"),
@@ -75,6 +76,7 @@ class EnvironmentAction(Action):
]
self.flag_func_map = (
("deployment-tasks", self.deployment_tasks),
("attributes", self.attributes),
("create", self.create),
("set", self.set),
("delete", self.delete),
@@ -213,5 +215,28 @@ class EnvironmentAction(Action):
elif params.upload:
tasks = self.serializer.read_from_file(full_path)
cluster.update_deployment_tasks(tasks)
print("Deployment tasks for release {0} "
" uploaded from {1}.yaml".format(cluster.id, full_path))
print("Deployment tasks for cluster {0} "
"uploaded from {1}.yaml".format(cluster.id, full_path))
@check_all("env")
@check_any("download", "upload")
def attributes(self, params):
"""Modify attributes of the environment.
fuel env --env 1 --attributes --download
fuel env --env 1 --attributes --upload
"""
cluster = Environment(params.env)
dir_path = self.full_path_directory(
params.dir, 'cluster_{0}'.format(params.env))
full_path = '{0}/attributes'.format(dir_path)
if params.download:
attributes = cluster.get_attributes()
self.serializer.write_to_path(full_path, attributes)
print("Attributes of cluster {0} "
"downloaded into {1}.yaml.".format(cluster.id, full_path))
elif params.upload:
attributes = self.serializer.read_from_file(full_path)
cluster.update_attributes(attributes)
print("Attributes of cluster {0} "
"uploaded from {1}.yaml".format(cluster.id, full_path))

View File

@@ -230,6 +230,10 @@ def get_deployment_tasks_arg(help_msg):
"deployment-tasks", flags=("--deployment-tasks",), help=help_msg)
def get_attributes_arg(help_msg):
return get_boolean_arg("attributes", help=help_msg)
def get_sync_deployment_tasks_arg():
return get_boolean_arg(
"sync-deployment-tasks",

View File

@@ -31,6 +31,7 @@ class Environment(BaseObject):
instance_api_path = "clusters/{0}/"
deployment_tasks_path = 'clusters/{0}/deployment_tasks'
deployment_tasks_graph_path = 'clusters/{0}/deploy_tasks/graph.gv'
attributes_path = 'clusters/{0}/attributes'
@classmethod
def create(cls, name, release_id, net,
@@ -438,6 +439,14 @@ class Environment(BaseObject):
url = self.deployment_tasks_path.format(self.id)
return self.connection.put_request(url, data)
def get_attributes(self):
url = self.attributes_path.format(self.id)
return self.connection.get_request(url)
def update_attributes(self, data):
url = self.attributes_path.format(self.id)
return self.connection.put_request(url, data)
def get_deployment_tasks_graph(self, tasks, parents_for=None):
url = self.deployment_tasks_graph_path.format(self.id)
params = {

View File

@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
#
# 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 json
from mock import patch
from fuelclient.tests import base
@patch('fuelclient.client.requests')
@patch('fuelclient.cli.serializers.open', create=True)
@patch('fuelclient.cli.actions.base.os')
class TestClusterAttributesActions(base.UnitTestCase):
_input = {
'editable': {
'test': 'foo',
}}
_output = 'editable:\n test: foo\n'
def test_attributes_download(self, mos, mopen, mrequests):
mrequests.get().json.return_value = self._input
self.execute_wo_auth(
['fuel', 'env', '--env', '1', '--attributes', '--download'])
url = mrequests.get.call_args[0][0]
self.assertIn('clusters/1/attributes', url)
mopen().__enter__().write.assert_called_once_with(self._output)
def test_attributes_upload(self, mos, mopen, mrequests):
mopen().__enter__().read.return_value = self._output
self.execute_wo_auth(
['fuel', 'env', '--env', '1', '--attributes', '--upload'])
self.assertEqual(mrequests.put.call_count, 1)
call_args = mrequests.put.call_args_list[0]
url = call_args[0][0]
kwargs = call_args[1]
self.assertIn('clusters/1/attributes', url)
self.assertEqual(json.loads(kwargs['data']), self._input)