New command entry for acloud powerwash.
Bug: 162382338
Test: acloud-dev powerwash --instance-name $instance_name
Change-Id: Ie64761bb6e7a2bb0513002a4d610a2406a7794c8
diff --git a/Android.bp b/Android.bp
index 70d032e..cb49b12 100644
--- a/Android.bp
+++ b/Android.bp
@@ -51,6 +51,7 @@
"acloud_internal",
"acloud_list",
"acloud_pull",
+ "acloud_powerwash",
"acloud_metrics",
"acloud_proto",
"acloud_public",
@@ -191,6 +192,14 @@
}
python_library_host{
+ name: "acloud_powerwash",
+ defaults: ["acloud_default"],
+ srcs: [
+ "powerwash/*.py",
+ ],
+}
+
+python_library_host{
name: "acloud_metrics",
defaults: ["acloud_default"],
srcs: [
diff --git a/powerwash/__init__.py b/powerwash/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/powerwash/__init__.py
diff --git a/powerwash/powerwash.py b/powerwash/powerwash.py
new file mode 100644
index 0000000..f2bf338
--- /dev/null
+++ b/powerwash/powerwash.py
@@ -0,0 +1,62 @@
+# Copyright 2020 - The Android Open Source Project
+#
+# 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.
+r"""Powerwash entry point.
+
+This command will powerwash the AVD from a remote instance.
+"""
+
+from __future__ import print_function
+
+from acloud import errors
+from acloud.list import list as list_instances
+from acloud.public import config
+from acloud.public import report
+
+
+def PowerwashFromInstance(instance, instance_id):
+ """Powerwash AVD from remote CF instance.
+
+ Args:
+ instance: list.Instance() object.
+ instance_id: Integer of the instance id.
+
+ Returns:
+ A Report instance.
+ """
+ # TODO(162382338): rewrite this function to powerwash AVD from the remote instance.
+ print("We will powerwash AVD id (%s) from the instance: %s."
+ % (instance_id, instance.name))
+ return report.Report(command="powerwash")
+
+
+def Run(args):
+ """Run powerwash.
+
+ After powerwash command executed, tool will return one Report instance.
+
+ Args:
+ args: Namespace object from argparse.parse_args.
+
+ Returns:
+ A Report instance.
+
+ Raises:
+ errors.CommandArgError: Lack the instance_name in args.
+ """
+ cfg = config.GetAcloudConfig(args)
+ if args.instance_name:
+ instance = list_instances.GetInstancesFromInstanceNames(
+ cfg, [args.instance_name])
+ return PowerwashFromInstance(instance[0], args.instance_id)
+ raise errors.CommandArgError("Please assign the '--instance-name' in your command.")
diff --git a/powerwash/powerwash_args.py b/powerwash/powerwash_args.py
new file mode 100644
index 0000000..3c5c1c8
--- /dev/null
+++ b/powerwash/powerwash_args.py
@@ -0,0 +1,59 @@
+# Copyright 2020 - The Android Open Source Project
+#
+# 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.
+r"""Powerwash args.
+
+Defines the powerwash arg parser that holds powerwash specific args.
+"""
+import argparse
+
+
+CMD_POWERWASH = "powerwash"
+
+
+def GetPowerwashArgParser(subparser):
+ """Return the powerwash arg parser.
+
+ Args:
+ subparser: argparse.ArgumentParser that is attached to main acloud cmd.
+
+ Returns:
+ argparse.ArgumentParser with powerwash options defined.
+ """
+ powerwash_parser = subparser.add_parser(CMD_POWERWASH)
+ powerwash_parser.required = False
+ powerwash_parser.set_defaults(which=CMD_POWERWASH)
+ powerwash_group = powerwash_parser.add_mutually_exclusive_group()
+ powerwash_group.add_argument(
+ "--instance-name",
+ dest="instance_name",
+ type=str,
+ required=False,
+ help="The name of the remote instance that need to reset the AVDs.")
+ # TODO(b/118439885): Old arg formats to support transition, delete when
+ # transistion is done.
+ powerwash_group.add_argument(
+ "--instance_name",
+ dest="instance_name",
+ type=str,
+ required=False,
+ help=argparse.SUPPRESS)
+ powerwash_parser.add_argument(
+ "--instance-id",
+ dest="instance_id",
+ type=int,
+ required=False,
+ default=1,
+ help="The instance id of the remote instance that need to be reset.")
+
+ return powerwash_parser
diff --git a/public/acloud_main.py b/public/acloud_main.py
index bf2bc95..bf67827 100644
--- a/public/acloud_main.py
+++ b/public/acloud_main.py
@@ -123,6 +123,8 @@
from acloud.list import list as list_instances
from acloud.list import list_args
from acloud.metrics import metrics
+from acloud.powerwash import powerwash
+from acloud.powerwash import powerwash_args
from acloud.public import acloud_common
from acloud.public import config
from acloud.public.actions import create_cuttlefish_action
@@ -241,6 +243,9 @@
# Command "reconnect"
subparser_list.append(reconnect_args.GetReconnectArgParser(subparsers))
+ # Command "powerwash"
+ subparser_list.append(powerwash_args.GetPowerwashArgParser(subparsers))
+
# Command "pull"
subparser_list.append(pull_args.GetPullArgParser(subparsers))
@@ -421,6 +426,8 @@
list_instances.Run(args)
elif args.which == reconnect_args.CMD_RECONNECT:
reconnect.Run(args)
+ elif args.which == powerwash_args.CMD_POWERWASH:
+ report = powerwash.Run(args)
elif args.which == pull_args.CMD_PULL:
report = pull.Run(args)
elif args.which == setup_args.CMD_SETUP: