diff --git a/fuelclient/commands/graph.py b/fuelclient/commands/graph.py index d459b4b..9c1866e 100644 --- a/fuelclient/commands/graph.py +++ b/fuelclient/commands/graph.py @@ -352,3 +352,53 @@ class GraphList(base.BaseListCommand): scolumn_ids = [self.columns.index(col) for col in args.sort_columns] data.sort(key=lambda x: [x[scolumn_id] for scolumn_id in scolumn_ids]) return self.columns, data + + +class GraphDelete(base.BaseCommand): + """Delete deployment graph.""" + entity_name = 'graph' + + def get_parser(self, prog_name): + parser = super(GraphDelete, self).get_parser(prog_name) + graph_class = parser.add_mutually_exclusive_group(required=True) + graph_class.add_argument('-e', + '--environment', + type=int, + help='Id of the environment') + graph_class.add_argument('-r', + '--release', + type=int, + help='Id of the release') + graph_class.add_argument('-p', + '--plugin', + type=int, + help='Id of the plugin') + parser.add_argument('-t', + '--graph-type', + required=True, + help='Type of the deployment graph') + return parser + + def take_action(self, parsed_args): + parameters_to_graph_class = ( + ('environment', 'clusters'), + ('release', 'releases'), + ('plugin', 'plugins'), + ) + + msg = '' + for parameter, graph_class in parameters_to_graph_class: + model_id = getattr(parsed_args, parameter) + if model_id: + self.client.delete( + related_model=graph_class, + related_id=model_id, + graph_type=parsed_args.graph_type + ) + msg = ("Deployment graph '{0}' for {1} with id {2} was " + "deleted.\n".format(parsed_args.graph_type, + parameter, + model_id)) + break + + self.app.stdout.write(msg) diff --git a/fuelclient/tests/unit/v2/cli/test_deployment_graph.py b/fuelclient/tests/unit/v2/cli/test_deployment_graph.py index c96a722..077a301 100644 --- a/fuelclient/tests/unit/v2/cli/test_deployment_graph.py +++ b/fuelclient/tests/unit/v2/cli/test_deployment_graph.py @@ -327,3 +327,14 @@ class TestGraphActions(test_engine.BaseCLITest): mock.call(env_id=None, filters=['cluster']), mock.call(env_id=None, filters=None) ]) + + def test_delete(self): + self._test_cmd( + 'delete', + '--env 1 --graph-type custom_graph', + dict( + graph_type='custom_graph', + related_id=1, + related_model='clusters' + ) + ) diff --git a/fuelclient/tests/unit/v2/lib/test_deployment_graph.py b/fuelclient/tests/unit/v2/lib/test_deployment_graph.py index 1584c6b..03023ca 100644 --- a/fuelclient/tests/unit/v2/lib/test_deployment_graph.py +++ b/fuelclient/tests/unit/v2/lib/test_deployment_graph.py @@ -330,3 +330,13 @@ class TestDeploymentGraphFacade(test_api.BaseLibTest): self.client.download(env_id=1, level='cluster', graph_type='custom_graph') self.assertTrue(matcher_get.called) + + def test_graph_delete(self): + matcher_delete = self.m_request.delete( + '/api/v1/clusters/1/deployment_graphs/custom_graph', + json={} + ) + self.client.delete(graph_type='custom_graph', + related_id=1, + related_model='clusters') + self.assertTrue(matcher_delete.called) diff --git a/fuelclient/v1/graph.py b/fuelclient/v1/graph.py index 5339233..27bf5a9 100644 --- a/fuelclient/v1/graph.py +++ b/fuelclient/v1/graph.py @@ -266,6 +266,12 @@ class GraphClient(base_v1.BaseV1Client): return graphs_list + def delete(self, related_model, related_id, graph_type): + return self.connection.delete_request( + self.related_graph_api_path.format(related_model=related_model, + related_model_id=related_id, + graph_type=graph_type)) + def get_client(connection): return GraphClient(connection) diff --git a/setup.cfg b/setup.cfg index 29e4929..1354fb1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -61,6 +61,7 @@ fuelclient = env_update=fuelclient.commands.environment:EnvUpdate extension_list=fuelclient.commands.extension:ExtensionList fuel-version=fuelclient.commands.fuelversion:FuelVersion + graph_delete=fuelclient.commands.graph:GraphDelete graph_download=fuelclient.commands.graph:GraphDownload graph_execute=fuelclient.commands.graph:GraphExecute graph_list=fuelclient.commands.graph:GraphList