myfaasmctl 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. myfaasmctl-0.0.1/LICENSE.md +202 -0
  2. myfaasmctl-0.0.1/PKG-INFO +42 -0
  3. myfaasmctl-0.0.1/README.md +26 -0
  4. myfaasmctl-0.0.1/faasmctl/__init__.py +4 -0
  5. myfaasmctl-0.0.1/faasmctl/bin/gen_proto_files.py +110 -0
  6. myfaasmctl-0.0.1/faasmctl/main.py +14 -0
  7. myfaasmctl-0.0.1/faasmctl/tasks/__init__.py +29 -0
  8. myfaasmctl-0.0.1/faasmctl/tasks/cli.py +150 -0
  9. myfaasmctl-0.0.1/faasmctl/tasks/delete.py +28 -0
  10. myfaasmctl-0.0.1/faasmctl/tasks/deploy.py +103 -0
  11. myfaasmctl-0.0.1/faasmctl/tasks/flush.py +31 -0
  12. myfaasmctl-0.0.1/faasmctl/tasks/generate.py +14 -0
  13. myfaasmctl-0.0.1/faasmctl/tasks/invoke.py +102 -0
  14. myfaasmctl-0.0.1/faasmctl/tasks/logs.py +73 -0
  15. myfaasmctl-0.0.1/faasmctl/tasks/monitor.py +317 -0
  16. myfaasmctl-0.0.1/faasmctl/tasks/restart.py +46 -0
  17. myfaasmctl-0.0.1/faasmctl/tasks/scale.py +47 -0
  18. myfaasmctl-0.0.1/faasmctl/tasks/status.py +29 -0
  19. myfaasmctl-0.0.1/faasmctl/tasks/upload.py +36 -0
  20. myfaasmctl-0.0.1/faasmctl/util/backend.py +2 -0
  21. myfaasmctl-0.0.1/faasmctl/util/batch.py +14 -0
  22. myfaasmctl-0.0.1/faasmctl/util/compose.py +399 -0
  23. myfaasmctl-0.0.1/faasmctl/util/config.py +80 -0
  24. myfaasmctl-0.0.1/faasmctl/util/deploy.py +152 -0
  25. myfaasmctl-0.0.1/faasmctl/util/docker.py +52 -0
  26. myfaasmctl-0.0.1/faasmctl/util/env.py +10 -0
  27. myfaasmctl-0.0.1/faasmctl/util/faasm.py +25 -0
  28. myfaasmctl-0.0.1/faasmctl/util/flush.py +38 -0
  29. myfaasmctl-0.0.1/faasmctl/util/gen_proto/faabric_pb2.py +75 -0
  30. myfaasmctl-0.0.1/faasmctl/util/gen_proto/planner_pb2.py +65 -0
  31. myfaasmctl-0.0.1/faasmctl/util/invoke.py +156 -0
  32. myfaasmctl-0.0.1/faasmctl/util/k8s.py +371 -0
  33. myfaasmctl-0.0.1/faasmctl/util/message.py +14 -0
  34. myfaasmctl-0.0.1/faasmctl/util/network.py +38 -0
  35. myfaasmctl-0.0.1/faasmctl/util/planner.py +201 -0
  36. myfaasmctl-0.0.1/faasmctl/util/random.py +8 -0
  37. myfaasmctl-0.0.1/faasmctl/util/restart.py +21 -0
  38. myfaasmctl-0.0.1/faasmctl/util/results.py +40 -0
  39. myfaasmctl-0.0.1/faasmctl/util/time.py +6 -0
  40. myfaasmctl-0.0.1/faasmctl/util/upload.py +61 -0
  41. myfaasmctl-0.0.1/faasmctl/util/version.py +5 -0
  42. myfaasmctl-0.0.1/myfaasmctl.egg-info/PKG-INFO +42 -0
  43. myfaasmctl-0.0.1/myfaasmctl.egg-info/SOURCES.txt +48 -0
  44. myfaasmctl-0.0.1/myfaasmctl.egg-info/dependency_links.txt +1 -0
  45. myfaasmctl-0.0.1/myfaasmctl.egg-info/entry_points.txt +2 -0
  46. myfaasmctl-0.0.1/myfaasmctl.egg-info/requires.txt +3 -0
  47. myfaasmctl-0.0.1/myfaasmctl.egg-info/top_level.txt +1 -0
  48. myfaasmctl-0.0.1/pyproject.toml +29 -0
  49. myfaasmctl-0.0.1/setup.cfg +8 -0
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2023 - Faasm Team
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
@@ -0,0 +1,42 @@
1
+ Metadata-Version: 2.1
2
+ Name: myfaasmctl
3
+ Version: 0.0.1
4
+ Summary: Command line tool to deploy, manage, and interact with Faasm
5
+ Author-email: Faasm Team <foo@bar.com>
6
+ Project-URL: Homepage, https://github.com/faasm/faasmctl
7
+ Project-URL: Bug Tracker, https://github.com/faasm/faasmctl/issues
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.7
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE.md
13
+ Requires-Dist: invoke==2.1.3
14
+ Requires-Dist: requests==2.31.0
15
+ Requires-Dist: protobuf==4.23.4
16
+
17
+ # Faasm CTL [![Tests](https://github.com/faasm/faasmctl/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/faasm/faasmctl/actions/workflows/tests.yml) ![PyPI](https://img.shields.io/pypi/v/faasmctl)
18
+
19
+ `faasmctl` is a command line script to deploy, manage, and interact with a
20
+ running [Faasm](https://github.com/faasm/faasm) cluster.
21
+
22
+ ## Install
23
+
24
+ To install `faasmctl` you need a working `pip` (virtual-)environment. Then:
25
+
26
+ ```bash
27
+ pip install faasmctl==0.43.0
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ `faasmctl` aggregates tasks related to deploying, managing, and interacting
33
+ with running Faasm clusters. You can list all the available tasks with a
34
+ short description using:
35
+
36
+ ```bash
37
+ faasmctl -l
38
+ ```
39
+
40
+ ## Further Reading
41
+
42
+ For any further reading, check the [`docs`](./docs) directory.
@@ -0,0 +1,26 @@
1
+ # Faasm CTL [![Tests](https://github.com/faasm/faasmctl/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/faasm/faasmctl/actions/workflows/tests.yml) ![PyPI](https://img.shields.io/pypi/v/faasmctl)
2
+
3
+ `faasmctl` is a command line script to deploy, manage, and interact with a
4
+ running [Faasm](https://github.com/faasm/faasm) cluster.
5
+
6
+ ## Install
7
+
8
+ To install `faasmctl` you need a working `pip` (virtual-)environment. Then:
9
+
10
+ ```bash
11
+ pip install faasmctl==0.43.0
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ `faasmctl` aggregates tasks related to deploying, managing, and interacting
17
+ with running Faasm clusters. You can list all the available tasks with a
18
+ short description using:
19
+
20
+ ```bash
21
+ faasmctl -l
22
+ ```
23
+
24
+ ## Further Reading
25
+
26
+ For any further reading, check the [`docs`](./docs) directory.
@@ -0,0 +1,4 @@
1
+ # flake8: noqa
2
+
3
+ from . import tasks
4
+ from . import util
@@ -0,0 +1,110 @@
1
+ #!/usr/bin/env python3
2
+
3
+ from os import environ, listdir, makedirs
4
+ from os.path import dirname, exists, join, realpath
5
+ from shutil import rmtree
6
+ from sys import argv
7
+ from subprocess import run
8
+
9
+ FAASMCTL_ROOT = dirname(dirname(realpath(__file__)))
10
+
11
+ # Unfortunately, we need to duplicate this constants here as we need to be
12
+ # able to run this file in standalone mode, as if the proto files are not
13
+ # generated, some imports in `faasmctl` will fail
14
+ GEN_PROTO_DIR = join(FAASMCTL_ROOT, "util", "gen_proto")
15
+ FAASM_CLI_IMAGE = "faasm.azurecr.io/cli"
16
+
17
+ PROTO_FILES = [
18
+ "faabric_pb2.py",
19
+ "planner_pb2.py",
20
+ ]
21
+
22
+
23
+ # We can not import faasmctl here
24
+ def get_faasm_version():
25
+ ver_file = join(FAASMCTL_ROOT, "util", "faasm.py")
26
+ cmd = "cat {} | grep 'FAASM_VERSION =' | cut -d' ' -f3".format(ver_file)
27
+ version = (
28
+ run(cmd, shell=True, check=True, capture_output=True)
29
+ .stdout.decode("utf-8")
30
+ .strip()[1:-1]
31
+ )
32
+
33
+ return version
34
+
35
+
36
+ def gen_proto_files(clean=False):
37
+ """
38
+ Generate python proto files to interact with the Faasm cluster
39
+ """
40
+ if clean:
41
+ rmtree(GEN_PROTO_DIR)
42
+
43
+ if not exists(GEN_PROTO_DIR):
44
+ makedirs(GEN_PROTO_DIR)
45
+
46
+ pb_files = [f for f in listdir(GEN_PROTO_DIR) if f.endswith("pb2.py")]
47
+ pb_files.sort()
48
+
49
+ if pb_files == PROTO_FILES:
50
+ return
51
+
52
+ if "FAASM_VERSION" in environ:
53
+ faasm_ver = environ["FAASM_VERSION"]
54
+ else:
55
+ faasm_ver = get_faasm_version()
56
+
57
+ print("Generating Faasm (v{}) protobuf files...".format(faasm_ver))
58
+ tmp_ctr_name = "faasm_gen_proto"
59
+ cm = "docker run -d -i --name {} {}:{}".format(
60
+ tmp_ctr_name, FAASM_CLI_IMAGE, faasm_ver
61
+ )
62
+ run(cm, shell=True, check=True)
63
+
64
+ # Find the right protoc binary
65
+ docker_exec_prefix = "docker exec {}".format(tmp_ctr_name)
66
+ find_protoc_cmd = "{} bash -c 'find ~/.conan -name protoc'".format(
67
+ docker_exec_prefix
68
+ )
69
+ protoc_bin = (
70
+ run(find_protoc_cmd, shell=True, capture_output=True)
71
+ .stdout.decode("utf-8")
72
+ .split("\n")
73
+ )
74
+ p_bin = [p_bin for p_bin in protoc_bin if "build_subfolder" in p_bin]
75
+ p_bin = p_bin[0].strip()
76
+
77
+ # Generate python protobuf files
78
+ code_dir = "/usr/local/code/faasm/faabric"
79
+ protoc_cmd = [
80
+ p_bin,
81
+ "--proto_path={}".format(code_dir),
82
+ "--python_out={}".format(code_dir),
83
+ "{}/src/planner/planner.proto".format(code_dir),
84
+ "{}/src/proto/faabric.proto".format(code_dir),
85
+ ]
86
+ protoc_cmd = " ".join(protoc_cmd)
87
+ docker_cmd = "{} bash -c '{}'".format(docker_exec_prefix, protoc_cmd)
88
+ run(docker_cmd, shell=True, check=True)
89
+
90
+ # Finally, copy the generated protobuf files to the desired location
91
+ for proto_file in PROTO_FILES:
92
+ if "planner" in proto_file:
93
+ proto_ctr_path = join(code_dir, "src", "planner", proto_file)
94
+ else:
95
+ proto_ctr_path = join(code_dir, "src", "proto", proto_file)
96
+ proto_faasmctl_path = join(GEN_PROTO_DIR, proto_file)
97
+
98
+ docker_cp_cmd = "docker cp {}:{} {}".format(
99
+ tmp_ctr_name, proto_ctr_path, proto_faasmctl_path
100
+ )
101
+ run(docker_cp_cmd, shell=True, check=True)
102
+
103
+ # Delete container
104
+ run("docker rm -f {}".format(tmp_ctr_name), shell=True, check=True)
105
+ print("Done generating protobuf files!")
106
+
107
+
108
+ if __name__ == "__main__":
109
+ clean = len(argv) == 2 and argv[1] == "--clean"
110
+ gen_proto_files(clean)
@@ -0,0 +1,14 @@
1
+ from invoke import Program
2
+ from faasmctl.tasks import task_ns
3
+ from faasmctl.util.version import get_version
4
+
5
+
6
+ def main():
7
+ program = Program(
8
+ name="faasmctl",
9
+ binary="faasmctl",
10
+ binary_names=["faasmctl"],
11
+ namespace=task_ns,
12
+ version=get_version(),
13
+ )
14
+ program.run()
@@ -0,0 +1,29 @@
1
+ from invoke import Collection
2
+
3
+ from . import cli
4
+ from . import delete
5
+ from . import deploy
6
+ from . import flush
7
+ from . import generate
8
+ from . import invoke
9
+ from . import logs
10
+ from . import monitor
11
+ from . import restart
12
+ from . import scale
13
+ from . import status
14
+ from . import upload
15
+
16
+ task_ns = Collection(
17
+ cli,
18
+ delete,
19
+ deploy,
20
+ generate,
21
+ flush,
22
+ invoke,
23
+ logs,
24
+ monitor,
25
+ restart,
26
+ scale,
27
+ status,
28
+ upload,
29
+ )
@@ -0,0 +1,150 @@
1
+ from faasmctl.util.compose import run_compose_cmd, wait_for_venv
2
+ from faasmctl.util.config import (
3
+ BACKEND_INI_STRING,
4
+ get_faasm_ini_file,
5
+ get_faasm_ini_value,
6
+ )
7
+ from faasmctl.util.docker import get_docker_tag
8
+ from invoke import task
9
+ from os.path import abspath, exists
10
+ from subprocess import run
11
+
12
+
13
+ def do_run_cmd(cli, cmd, cp_in, cp_out, env, ini_file):
14
+ if not ini_file:
15
+ ini_file = get_faasm_ini_file()
16
+
17
+ backend = get_faasm_ini_value(ini_file, "Faasm", BACKEND_INI_STRING)
18
+ if backend == "compose":
19
+ # To run a command in a `compose` backend, we fist start the CLI
20
+ # container in dettached mode (if it does not exist yet) and then we
21
+ # exec into it, copying the ini file
22
+ up_cmd = "up -d --no-recreate {}".format(cli)
23
+ run_compose_cmd(ini_file, up_cmd)
24
+
25
+ # Second, copy the the ini file inside the container
26
+ ini_file = abspath(ini_file)
27
+ ini_file_ctr_path = "/tmp/faasm.ini"
28
+ cp_cmd = "cp {} {}:{}".format(ini_file, cli, ini_file_ctr_path)
29
+ run_compose_cmd(ini_file, cp_cmd)
30
+
31
+ # Third, wait for the virtual environment to be ready if we need to. We
32
+ # only need to wait for the virtual environment if we are either
33
+ # mounting the source, or using one of the clients
34
+ wait_for_venv(ini_file, cli)
35
+
36
+ # Copy files in before execution
37
+ if cp_in:
38
+ host_path = abspath(cp_in.split(":")[0])
39
+ if not exists(host_path):
40
+ print("Host path to copy from does not exist ({})".format(host_path))
41
+ raise RuntimeError("Host path to copy from does not exist")
42
+ ctr_path = cp_in.split(":")[1]
43
+
44
+ cp_cmd = "cp {} {}:{}".format(host_path, cli, ctr_path)
45
+ run_compose_cmd(ini_file, cp_cmd)
46
+
47
+ # Lastly, actually run the requested command
48
+ compose_cmd = [
49
+ "exec",
50
+ "-e FAASM_INI_FILE={}".format(ini_file_ctr_path),
51
+ " ".join(["-e {}".format(var) for var in env.split(",")])
52
+ if env is not None
53
+ else "",
54
+ "-it" if not cmd else "",
55
+ cli,
56
+ "bash" if not cmd else cmd,
57
+ ]
58
+ compose_cmd = " ".join(compose_cmd)
59
+ run_compose_cmd(ini_file, compose_cmd)
60
+
61
+ # Copy files out after execution
62
+ if cp_out:
63
+ ctr_path = cp_out.split(":")[0]
64
+ host_path = abspath(cp_out.split(":")[1])
65
+
66
+ cp_cmd = "cp {}:{} {}".format(cli, ctr_path, host_path)
67
+ run_compose_cmd(ini_file, cp_cmd)
68
+
69
+ elif backend == "k8s":
70
+ # Using a CLI container with a cluster that runs on a `k8s` backend is
71
+ # only supported to upload functions from the CPP or Python container.
72
+ # As such we: (i) disable cli.faasm calls on a `k8s` backend, and (ii)
73
+ # use a standalone container to execute the command that we remove
74
+ # immediately after (without mounting any files)
75
+ ini_file_ctr_path = "/tmp/faasm.ini"
76
+ work_dir = get_faasm_ini_value(ini_file, "Faasm", "working_dir")
77
+
78
+ if cli == "cpp":
79
+ image_tag = get_docker_tag(work_dir, "CPP_CLI_IMAGE")
80
+ elif cli == "python":
81
+ image_tag = get_docker_tag(work_dir, "PYTHON_CLI_IMAGE")
82
+ else:
83
+ raise RuntimeError("Can't call cli.faasm on a `k8s` cluster!")
84
+
85
+ docker_cmd = [
86
+ "docker run --rm",
87
+ "-v {}:{}".format(ini_file, ini_file_ctr_path),
88
+ "-e FAASM_INI_FILE={}".format(ini_file_ctr_path),
89
+ "-it" if not cmd else "",
90
+ image_tag,
91
+ "bash" if not cmd else cmd,
92
+ ]
93
+ docker_cmd = " ".join(docker_cmd)
94
+
95
+ run(docker_cmd, shell=True)
96
+
97
+ else:
98
+ raise RuntimeError("Unrecognised backend: {}".format(backend))
99
+
100
+
101
+ @task
102
+ def faasm(ctx, cmd=None, cp_in=None, cp_out=None, env=None, ini_file=None):
103
+ """
104
+ Run a command in the Faasm CLI container
105
+
106
+ By default, if --cmd is set to None, we will get a shell into the
107
+ container. If the --cmd argument is set, we execute the cmd string
108
+
109
+ Parameters:
110
+ - cmd (str): command to run in the CLI container
111
+ - cp_in (str): file to copy into the CLI as host_path:ctr_path
112
+ - cp_out (str): file to copy out of the CLI as ctr_path:host_path
113
+ - env (str): comma-separated ENV=VAR environment variables for cmd
114
+ - ini_file (str): path to the cluster's INI file
115
+ """
116
+ do_run_cmd("faasm-cli", cmd, cp_in, cp_out, env, ini_file)
117
+
118
+
119
+ @task
120
+ def cpp(ctx, cmd=None, cp_in=None, cp_out=None, env=None, ini_file=None):
121
+ """
122
+ Run a command in the CPP CLI container
123
+
124
+ By default, if --cmd is set to None, we will get a shell into the
125
+ container. If the --cmd argument is set, we execute the cmd string
126
+
127
+ Parameters:
128
+ - cmd (str): command to run in the CLI container
129
+ - cp_in (str): file to copy into the CLI as host_path:ctr_path
130
+ - cp_out (str): file to copy out of the CLI as ctr_path:host_path
131
+ - ini_file (str): path to the cluster's INI file
132
+ """
133
+ do_run_cmd("cpp", cmd, cp_in, cp_out, env, ini_file)
134
+
135
+
136
+ @task
137
+ def python(ctx, cmd=None, cp_in=None, cp_out=None, env=None, ini_file=None):
138
+ """
139
+ Run a command in the Python CLI container
140
+
141
+ By default, if --cmd is set to None, we will get a shell into the
142
+ container. If the --cmd argument is set, we execute the cmd string
143
+
144
+ Parameters:
145
+ - cmd (str): command to run in the CLI container
146
+ - cp_in (str): file to copy into the CLI as host_path:ctr_path
147
+ - cp_out (str): file to copy out of the CLI as ctr_path:host_path
148
+ - ini_file (str): path to the cluster's INI file
149
+ """
150
+ do_run_cmd("python", cmd, cp_in, cp_out, env, ini_file)
@@ -0,0 +1,28 @@
1
+ from faasmctl.util.compose import delete_compose_cluster
2
+ from faasmctl.util.config import get_faasm_ini_file, get_faasm_ini_value
3
+ from faasmctl.util.k8s import delete_k8s_cluster
4
+ from invoke import task
5
+ from os import remove
6
+
7
+
8
+ @task(default=True)
9
+ def delete(ctx, ini_file=None):
10
+ """
11
+ Delete a running Faasm cluster
12
+
13
+ Parameters:
14
+ - ini_file (str): path to the cluster's INI file (FAASM_INI_FILE env. var
15
+ if not found)
16
+ """
17
+ if not ini_file:
18
+ ini_file = get_faasm_ini_file()
19
+
20
+ backend = get_faasm_ini_value(ini_file, "Faasm", "backend")
21
+ if backend == "compose":
22
+ delete_compose_cluster(ini_file)
23
+ elif backend == "k8s":
24
+ delete_k8s_cluster(ini_file)
25
+ else:
26
+ raise RuntimeError("Unsupported backend: {}".format(backend))
27
+
28
+ remove(ini_file)