You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ariatosca.apache.org by ra...@apache.org on 2017/04/18 13:39:55 UTC
incubator-ariatosca git commit: added aria reset cli command
Repository: incubator-ariatosca
Updated Branches:
refs/heads/ARIA-48-aria-cli 8b0e451ab -> 3bff159e6
added aria reset cli command
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/3bff159e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/3bff159e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/3bff159e
Branch: refs/heads/ARIA-48-aria-cli
Commit: 3bff159e6c3db3d855281c478c6ceab52fee6ad5
Parents: 8b0e451
Author: Ran Ziv <ra...@gigaspaces.com>
Authored: Tue Apr 18 16:39:51 2017 +0300
Committer: Ran Ziv <ra...@gigaspaces.com>
Committed: Tue Apr 18 16:39:51 2017 +0300
----------------------------------------------------------------------
aria/cli/cli/aria.py | 12 +++---------
aria/cli/cli/helptexts.py | 6 +++---
aria/cli/commands/__init__.py | 1 +
aria/cli/commands/reset.py | 40 ++++++++++++++++++++++++++++++++++++++
aria/cli/commands/services.py | 2 +-
aria/cli/config/config.py | 5 ++++-
aria/cli/env.py | 13 +++++++++++++
aria/cli/main.py | 1 +
8 files changed, 66 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3bff159e/aria/cli/cli/aria.py
----------------------------------------------------------------------
diff --git a/aria/cli/cli/aria.py b/aria/cli/cli/aria.py
index 31d6c9b..548be23 100644
--- a/aria/cli/cli/aria.py
+++ b/aria/cli/cli/aria.py
@@ -314,16 +314,10 @@ class Options(object):
is_flag=True,
help=helptexts.DRY_EXECUTION)
- self.init_hard_reset = click.option(
- '--hard',
+ self.reset_config = click.option(
+ '--reset-config',
is_flag=True,
- help=helptexts.HARD_RESET)
-
- self.reset_context = click.option(
- '-r',
- '--reset-context',
- is_flag=True,
- help=helptexts.RESET_CONTEXT)
+ help=helptexts.RESET_CONFIG)
self.enable_colors = click.option(
'--enable-colors',
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3bff159e/aria/cli/cli/helptexts.py
----------------------------------------------------------------------
diff --git a/aria/cli/cli/helptexts.py b/aria/cli/cli/helptexts.py
index c50a172..f8b315c 100644
--- a/aria/cli/cli/helptexts.py
+++ b/aria/cli/cli/helptexts.py
@@ -26,8 +26,8 @@ INPUTS_PARAMS_USAGE = (
SERVICE_TEMPLATE_PATH = "The path to the application's service template file"
SERVICE_TEMPLATE_ID = "The unique identifier for the service template"
-RESET_CONTEXT = "Reset the working environment"
-HARD_RESET = "Hard reset the configuration, including coloring and loggers"
+FORCE_RESET = "Confirmation for resetting ARIA's working directory"
+RESET_CONFIG = "Reset ARIA's user configuration"
ENABLE_COLORS = "Enable colors in logger (use --hard when working with" \
" an initialized environment) [default: False]"
@@ -47,7 +47,7 @@ JSON_OUTPUT = "Output events in a consumable JSON format"
SERVICE_ID = "The unique identifier for the service"
EXECUTION_ID = "The unique identifier for the execution"
-IGNORE_RUNNING_NODES = "Delete the service even if it has running nodes"
+IGNORE_AVAILABLE_NODES = "Delete the service even if it has available nodes"
NODE_NAME = "The node's name"
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3bff159e/aria/cli/commands/__init__.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/__init__.py b/aria/cli/commands/__init__.py
index 7777791..a01a029 100644
--- a/aria/cli/commands/__init__.py
+++ b/aria/cli/commands/__init__.py
@@ -19,6 +19,7 @@ from . import (
node_templates,
nodes,
plugins,
+ reset,
service_templates,
services,
workflows
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3bff159e/aria/cli/commands/reset.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/reset.py b/aria/cli/commands/reset.py
new file mode 100644
index 0000000..775f555
--- /dev/null
+++ b/aria/cli/commands/reset.py
@@ -0,0 +1,40 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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 ..cli import aria
+from ..cli import helptexts
+from ..env import env
+from ..exceptions import AriaCliError
+
+
+@aria.command(name='reset',
+ short_help="Reset ARIA's working directory")
+@aria.options.force(help=helptexts.FORCE_RESET)
+@aria.options.reset_config
+@aria.pass_logger
+@aria.options.verbose()
+def reset(force, reset_config, logger):
+ """
+ Reset ARIA working directory
+ Resetting the working directory will result in the deletion of all state in ARIA; The user
+ configuration will remain intact, unless the `reset_config` flag has been set as well, in
+ which case the entire ARIA working directory shall be removed.
+ """
+ if not force:
+ raise AriaCliError("To reset the ARIA's working directory, you must also provide the force"
+ " flag ('-f'/'--force').")
+
+ env.reset(reset_config=reset_config)
+ logger.info("ARIA's working directory has been reset")
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3bff159e/aria/cli/commands/services.py
----------------------------------------------------------------------
diff --git a/aria/cli/commands/services.py b/aria/cli/commands/services.py
index b785006..78899c5 100644
--- a/aria/cli/commands/services.py
+++ b/aria/cli/commands/services.py
@@ -112,7 +112,7 @@ def create(service_template_name,
@services.command(name='delete',
short_help='Delete a service')
@aria.argument('service-name')
-@aria.options.force(help=helptexts.IGNORE_RUNNING_NODES)
+@aria.options.force(help=helptexts.IGNORE_AVAILABLE_NODES)
@aria.options.verbose()
@aria.pass_model_storage
@aria.pass_resource_storage
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3bff159e/aria/cli/config/config.py
----------------------------------------------------------------------
diff --git a/aria/cli/config/config.py b/aria/cli/config/config.py
index 7d76830..99f46ca 100644
--- a/aria/cli/config/config.py
+++ b/aria/cli/config/config.py
@@ -21,6 +21,9 @@ import pkg_resources
from jinja2.environment import Template
+CONFIG_FILE_NAME = 'config.yaml'
+
+
class CliConfig(object):
def __init__(self, config_path):
@@ -29,7 +32,7 @@ class CliConfig(object):
@classmethod
def create_config(cls, workdir):
- config_path = os.path.join(workdir, 'config.yaml')
+ config_path = os.path.join(workdir, CONFIG_FILE_NAME)
if not os.path.isfile(config_path):
config_template = pkg_resources.resource_string(
__package__,
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3bff159e/aria/cli/env.py
----------------------------------------------------------------------
diff --git a/aria/cli/env.py b/aria/cli/env.py
index 71cf69a..52a4ec6 100644
--- a/aria/cli/env.py
+++ b/aria/cli/env.py
@@ -15,6 +15,7 @@
import os
+import shutil
from .config import config
from .logger import Logging
@@ -76,6 +77,18 @@ class _Environment(object):
self._plugin_manager = self._init_plugin_manager()
return self._plugin_manager
+ def reset(self, reset_config):
+ if reset_config:
+ shutil.rmtree(self._workdir)
+ else:
+ _, dirs, files = next(os.walk(self._workdir))
+ files.remove(config.CONFIG_FILE_NAME)
+
+ for dir_ in dirs:
+ shutil.rmtree(os.path.join(self._workdir, dir_))
+ for file_ in files:
+ os.remove(os.path.join(self._workdir, file_))
+
def _init_workdir(self):
if not os.path.exists(self._workdir):
os.makedirs(self._workdir)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3bff159e/aria/cli/main.py
----------------------------------------------------------------------
diff --git a/aria/cli/main.py b/aria/cli/main.py
index 9ae41bf..01d224c 100644
--- a/aria/cli/main.py
+++ b/aria/cli/main.py
@@ -45,6 +45,7 @@ def _register_commands():
_aria.add_command(commands.executions.executions)
_aria.add_command(commands.plugins.plugins)
_aria.add_command(commands.logs.logs)
+ _aria.add_command(commands.reset.reset)
def main():