badwulf 0.1.0__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.
badwulf-0.1.0/LICENSE ADDED
@@ -0,0 +1,181 @@
1
+ The Artistic License 2.0
2
+
3
+ Copyright (c) 2000-2006, The Perl Foundation.
4
+
5
+ Everyone is permitted to copy and distribute verbatim copies of this license
6
+ document, but changing it is not allowed.
7
+
8
+ Preamble
9
+
10
+ This license establishes the terms under which a given free software Package
11
+ may be copied, modified, distributed, and/or redistributed. The intent is that
12
+ the Copyright Holder maintains some artistic control over the development of
13
+ that Package while still keeping the Package available as open source and free
14
+ software.
15
+
16
+ You are always permitted to make arrangements wholly outside of this license
17
+ directly with the Copyright Holder of a given Package. If the terms of this
18
+ license do not permit the full use that you propose to make of the Package,
19
+ you should contact the Copyright Holder and seek a different licensing
20
+ arrangement.
21
+
22
+ Definitions
23
+
24
+ "Copyright Holder" means the individual(s) or organization(s) named in the
25
+ copyright notice for the entire Package.
26
+
27
+ "Contributor" means any party that has contributed code or other material to
28
+ the Package, in accordance with the Copyright Holder's procedures.
29
+
30
+ "You" and "your" means any person who would like to copy, distribute, or
31
+ modify the Package.
32
+
33
+ "Package" means the collection of files distributed by the Copyright Holder,
34
+ and derivatives of that collection and/or of those files. A given Package may
35
+ consist of either the Standard Version, or a Modified Version.
36
+
37
+ "Distribute" means providing a copy of the Package or making it accessible to
38
+ anyone else, or in the case of a company or organization, to others outside of
39
+ your company or organization.
40
+
41
+ "Distributor Fee" means any fee that you charge for Distributing this Package
42
+ or providing support for this Package to another party. It does not mean
43
+ licensing fees.
44
+
45
+ "Standard Version" refers to the Package if it has not been modified, or has
46
+ been modified only in ways explicitly requested by the Copyright Holder.
47
+
48
+ "Modified Version" means the Package, if it has been changed, and such changes
49
+ were not explicitly requested by the Copyright Holder.
50
+
51
+ "Original License" means this Artistic License as Distributed with the
52
+ Standard Version of the Package, in its current version or as it may be
53
+ modified by The Perl Foundation in the future.
54
+
55
+ "Source" form means the source code, documentation source, and configuration
56
+ files for the Package.
57
+
58
+ "Compiled" form means the compiled bytecode, object code, binary, or any other
59
+ form resulting from mechanical transformation or translation of the Source
60
+ form.
61
+
62
+ Permission for Use and Modification Without Distribution
63
+
64
+ (1) You are permitted to use the Standard Version and create and use Modified
65
+ Versions for any purpose without restriction, provided that you do not
66
+ Distribute the Modified Version.
67
+
68
+ Permissions for Redistribution of the Standard Version
69
+
70
+ (2) You may Distribute verbatim copies of the Source form of the Standard
71
+ Version of this Package in any medium without restriction, either gratis or
72
+ for a Distributor Fee, provided that you duplicate all of the original
73
+ copyright notices and associated disclaimers. At your discretion, such
74
+ verbatim copies may or may not include a Compiled form of the Package.
75
+
76
+ (3) You may apply any bug fixes, portability changes, and other modifications
77
+ made available from the Copyright Holder. The resulting Package will still be
78
+ considered the Standard Version, and as such will be subject to the Original
79
+ License.
80
+
81
+ Distribution of Modified Versions of the Package as Source
82
+
83
+ (4) You may Distribute your Modified Version as Source (either gratis or for a
84
+ Distributor Fee, and with or without a Compiled form of the Modified Version)
85
+ provided that you clearly document how it differs from the Standard Version,
86
+ including, but not limited to, documenting any non-standard features,
87
+ executables, or modules, and provided that you do at least ONE of the
88
+ following:
89
+
90
+ (a) make the Modified Version available to the Copyright Holder of the
91
+ Standard Version, under the Original License, so that the Copyright Holder may
92
+ include your modifications in the Standard Version.
93
+
94
+ (b) ensure that installation of your Modified Version does not prevent the
95
+ user installing or running the Standard Version. In addition, the Modified
96
+ Version must bear a name that is different from the name of the Standard
97
+ Version.
98
+
99
+ (c) allow anyone who receives a copy of the Modified Version to make the
100
+ Source form of the Modified Version available to others under
101
+
102
+ (i) the Original License or
103
+
104
+ (ii) a license that permits the licensee to freely copy, modify and
105
+ redistribute the Modified Version using the same licensing terms that apply to
106
+ the copy that the licensee received, and requires that the Source form of the
107
+ Modified Version, and of any works derived from it, be made freely available
108
+ in that license fees are prohibited but Distributor Fees are allowed.
109
+
110
+ Distribution of Compiled Forms of the Standard Version or Modified Versions
111
+ without the Source
112
+
113
+ (5) You may Distribute Compiled forms of the Standard Version without the
114
+ Source, provided that you include complete instructions on how to get the
115
+ Source of the Standard Version. Such instructions must be valid at the time of
116
+ your distribution. If these instructions, at any time while you are carrying
117
+ out such distribution, become invalid, you must provide new instructions on
118
+ demand or cease further distribution. If you provide valid instructions or
119
+ cease distribution within thirty days after you become aware that the
120
+ instructions are invalid, then you do not forfeit any of your rights under
121
+ this license.
122
+
123
+ (6) You may Distribute a Modified Version in Compiled form without the Source,
124
+ provided that you comply with Section 4 with respect to the Source of the
125
+ Modified Version.
126
+
127
+ Aggregating or Linking the Package
128
+
129
+ (7) You may aggregate the Package (either the Standard Version or Modified
130
+ Version) with other packages and Distribute the resulting aggregation provided
131
+ that you do not charge a licensing fee for the Package. Distributor Fees are
132
+ permitted, and licensing fees for other components in the aggregation are
133
+ permitted. The terms of this license apply to the use and Distribution of the
134
+ Standard or Modified Versions as included in the aggregation.
135
+
136
+ (8) You are permitted to link Modified and Standard Versions with other works,
137
+ to embed the Package in a larger work of your own, or to build stand-alone
138
+ binary or bytecode versions of applications that include the Package, and
139
+ Distribute the result without restriction, provided the result does not expose
140
+ a direct interface to the Package.
141
+
142
+ Items That are Not Considered Part of a Modified Version
143
+
144
+ (9) Works (including, but not limited to, modules and scripts) that merely
145
+ extend or make use of the Package, do not, by themselves, cause the Package to
146
+ be a Modified Version. In addition, such works are not considered parts of the
147
+ Package itself, and are not subject to the terms of this license.
148
+
149
+ General Provisions
150
+
151
+ (10) Any use, modification, and distribution of the Standard or Modified
152
+ Versions is governed by this Artistic License. By using, modifying or
153
+ distributing the Package, you accept this license. Do not use, modify, or
154
+ distribute the Package, if you do not accept this license.
155
+
156
+ (11) If your Modified Version has been derived from a Modified Version made by
157
+ someone other than you, you are nevertheless required to ensure that your
158
+ Modified Version complies with the requirements of this license.
159
+
160
+ (12) This license does not grant you the right to use any trademark, service
161
+ mark, tradename, or logo of the Copyright Holder.
162
+
163
+ (13) This license includes the non-exclusive, worldwide, free-of-charge patent
164
+ license to make, have made, use, offer to sell, sell, import and otherwise
165
+ transfer the Package with respect to any patent claims licensable by the
166
+ Copyright Holder that are necessarily infringed by the Package. If you
167
+ institute patent litigation (including a cross-claim or counterclaim) against
168
+ any party alleging that the Package constitutes direct or contributory patent
169
+ infringement, then this Artistic License to you shall terminate on the date
170
+ that such litigation is filed.
171
+
172
+ (14) Disclaimer of Warranty:
173
+
174
+ THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS'
175
+ AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF
176
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE
177
+ DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW,
178
+ NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT,
179
+ INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE
180
+ PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
181
+
badwulf-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,39 @@
1
+ Metadata-Version: 2.1
2
+ Name: badwulf
3
+ Version: 0.1.0
4
+ Summary: Minimal manager for Beowulf clusters and scientific data
5
+ Author-email: "Kylie A. Bemis" <k.bemis@northeastern.edu>
6
+ License: Artistic License 2.0
7
+ Project-URL: Homepage, https://github.com/kuwisdelu/badwulf
8
+ Project-URL: Issues, https://github.com/kuwisdelu/badwulf/issues
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: License :: OSI Approved :: Artistic License
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Operating System :: Unix
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: tomli>=1.1.0; python_version < "3.11"
20
+ Provides-Extra: test
21
+ Requires-Dist: pytest; extra == "test"
22
+
23
+ # Badwulf
24
+
25
+ ## Minimal manager for Beowulf clusters and scientific data
26
+
27
+ The goal of *badwulf* is a provide a minimal command line interface for accessing and managing experimental data on scientific computing servers and Beowulf clusters.
28
+
29
+ This tool is __not__ intended to replace true cluster management and scheduling software for such as *Slurm*. Instead, *badwulf* is a lightweight package for simplying tasks such as:
30
+
31
+ - Connecting an port forwarded SSH session to a research server behind a login server
32
+
33
+ - Transfering files and directories between a local client and a research server
34
+
35
+ - Managing a simple repository of experimental data and metadata
36
+
37
+ - Searching experimental metadata for terms and keywords
38
+
39
+ - Syncing experimental data between a local client and a research server
@@ -0,0 +1,17 @@
1
+ # Badwulf
2
+
3
+ ## Minimal manager for Beowulf clusters and scientific data
4
+
5
+ The goal of *badwulf* is a provide a minimal command line interface for accessing and managing experimental data on scientific computing servers and Beowulf clusters.
6
+
7
+ This tool is __not__ intended to replace true cluster management and scheduling software for such as *Slurm*. Instead, *badwulf* is a lightweight package for simplying tasks such as:
8
+
9
+ - Connecting an port forwarded SSH session to a research server behind a login server
10
+
11
+ - Transfering files and directories between a local client and a research server
12
+
13
+ - Managing a simple repository of experimental data and metadata
14
+
15
+ - Searching experimental metadata for terms and keywords
16
+
17
+ - Syncing experimental data between a local client and a research server
@@ -0,0 +1,45 @@
1
+
2
+ [build-system]
3
+ requires = ["setuptools>=61.0"]
4
+ build-backend = "setuptools.build_meta"
5
+
6
+ [project]
7
+ name = "badwulf"
8
+ version = "0.1.0"
9
+ authors = [
10
+ {name = "Kylie A. Bemis", email = "k.bemis@northeastern.edu"}
11
+ ]
12
+ description = "Minimal manager for Beowulf clusters and scientific data"
13
+ readme = "README.md"
14
+ license = {text = "Artistic License 2.0"}
15
+ requires-python = ">=3.10"
16
+ dependencies = [
17
+ "tomli >= 1.1.0 ; python_version < '3.11'"
18
+ ]
19
+ classifiers = [
20
+ "Development Status :: 3 - Alpha",
21
+ "Programming Language :: Python :: 3",
22
+ "Programming Language :: Python :: 3.10",
23
+ "Programming Language :: Python :: 3.11",
24
+ "License :: OSI Approved :: Artistic License",
25
+ "Intended Audience :: Science/Research",
26
+ "Operating System :: Unix",
27
+ ]
28
+
29
+ [project.urls]
30
+ Homepage = "https://github.com/kuwisdelu/badwulf"
31
+ Issues = "https://github.com/kuwisdelu/badwulf/issues"
32
+
33
+ [project.optional-dependencies]
34
+ test = ["pytest"]
35
+
36
+ [external]
37
+ dependencies = [
38
+ "pkg:generic/ssh",
39
+ "pkg:generic/rsync",
40
+ ]
41
+
42
+ [tool.pytest.ini_options]
43
+ addopts = [
44
+ "--import-mode=importlib",
45
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,5 @@
1
+
2
+ from .rssh import rssh
3
+ from .expdb import expdb
4
+
5
+ __all__ = ["rssh", "expdb"]
@@ -0,0 +1,5 @@
1
+
2
+ from .clmanager import clmanager
3
+ from .dbmanager import dbmanager
4
+
5
+ __all__ = ["clmanager", "dbmanager"]
@@ -0,0 +1,298 @@
1
+
2
+ import sys
3
+ import platform
4
+ import subprocess
5
+ import argparse
6
+ import datetime
7
+ import importlib.metadata
8
+ from time import sleep
9
+
10
+ from ..tools import *
11
+ from ..rssh import rssh
12
+
13
+ class clmanager:
14
+ """
15
+ Command line utility for Beowulf clusters
16
+ """
17
+
18
+ def __init__(self,
19
+ name,
20
+ nodes,
21
+ version,
22
+ date,
23
+ description,
24
+ readme = None,
25
+ program = None,
26
+ username = None,
27
+ server = None,
28
+ server_username = False,
29
+ port = None):
30
+ """
31
+ Initialize a cluster CLI utility program
32
+ :param name: The name of the cluster/server
33
+ :param nodes: A list of nodenames or dict in the form {alias: nodename}
34
+ :param version: The version of the program
35
+ :param date: The date of the program's last revision
36
+ :param description: A description of the program
37
+ :param readme: The file path of a README.md file
38
+ :param program: The name of the program (defaults to name)
39
+ :param username: Your username on the cluster
40
+ :param server: The gateway server hostname (optional)
41
+ :param server_username: Your username on the gateway server (optional)
42
+ :param port: The local port for gateway server SSH forwarding
43
+ """
44
+ self.name = name
45
+ self.nodes = nodes
46
+ self.version = version
47
+ if isinstance(date, datetime.date):
48
+ self.date = date
49
+ else:
50
+ self.date = datetime.date.fromisoformat(date)
51
+ self.description = description
52
+ self.readme = readme
53
+ if program is None:
54
+ self.program = name.casefold()
55
+ else:
56
+ self.program = program
57
+ self.username = username
58
+ self.server = server
59
+ self.server_username = server_username
60
+ self.port = port
61
+ self._parser = None
62
+ self._args = None
63
+
64
+ def _add_cluster_args(self, parser):
65
+ """
66
+ Add cluster parameters to a parser.
67
+ :param parser: The parser to update
68
+ """
69
+ if isinstance(self.nodes, dict):
70
+ for alias, nodename in self.nodes.items():
71
+ parser.add_argument(f"-{alias}", action="append_const",
72
+ help=nodename, dest="nodes", const=nodename)
73
+ parser.add_argument("-n", "--node", action="append",
74
+ help=f"{self.name} node", dest="nodes",
75
+ metavar="NODE")
76
+ parser.add_argument("-p", "--port", action="store",
77
+ help="port forwarding", default=self.port)
78
+ parser.add_argument("-u", "--user", action="store",
79
+ help=f"{self.name} user", default=self.username)
80
+ parser.add_argument("-L", "--login", action="store",
81
+ help="gateway server user", default=self.server_username)
82
+ parser.add_argument("-S", "--server", action="store",
83
+ help="gateway server host", default=self.server)
84
+
85
+ def _add_subcommand_run(self, subparsers):
86
+ """
87
+ Add 'run' subcommand to subparsers.
88
+ :param subparsers: The subparsers to update
89
+ """
90
+ cmd = subparsers.add_parser("run",
91
+ help=f"run command (e.g., shell) on a {self.name} node")
92
+ self._add_cluster_args(cmd)
93
+ cmd.add_argument("remote_command", action="store",
94
+ help="command to execute on a Magi node", nargs=argparse.OPTIONAL,
95
+ metavar="command")
96
+ cmd.add_argument("remote_args", action="store",
97
+ help="command arguments", nargs=argparse.REMAINDER,
98
+ metavar="...")
99
+
100
+ def _add_subcommand_copy_id(self, subparsers):
101
+ """
102
+ Add 'copy-id' subcommand to subparsers.
103
+ :param subparsers: The subparsers to update
104
+ """
105
+ cmd = subparsers.add_parser("copy-id",
106
+ help=f"copy ssh keys to a {self.name} node")
107
+ self._add_cluster_args(cmd)
108
+ cmd.add_argument("identity_file", action="store",
109
+ help="ssh key identity file")
110
+
111
+ def _add_subcommand_push(self, subparsers):
112
+ """
113
+ Add a 'push' subcommand to subparsers.
114
+ :param subparsers: The subparsers to update
115
+ """
116
+ cmd = subparsers.add_parser("push",
117
+ help=f"upload file(s) to {self.name}")
118
+ self._add_cluster_args(cmd)
119
+ cmd.add_argument("src", action="store",
120
+ help="source file/directory")
121
+ cmd.add_argument("dest", action="store",
122
+ help="destination file/directory")
123
+ cmd.add_argument("--ask", action="store_true",
124
+ help="ask to confirm before uploading files?")
125
+ cmd.add_argument("--dry-run", action="store_true",
126
+ help="show what would happen without doing it?")
127
+
128
+ def _add_subcommand_pull(self, subparsers):
129
+ """
130
+ Add a 'pull' subcommand to subparsers.
131
+ :param subparsers: The subparsers to update
132
+ """
133
+ cmd = subparsers.add_parser("pull",
134
+ help=f"download file(s) from {self.name}")
135
+ self._add_cluster_args(cmd)
136
+ cmd.add_argument("src", action="store",
137
+ help="source file/directory")
138
+ cmd.add_argument("dest", action="store",
139
+ help="destination file/directory")
140
+ cmd.add_argument("--ask", action="store_true",
141
+ help="ask to confirm before downloading files?")
142
+ cmd.add_argument("--dry-run", action="store_true",
143
+ help="show what would happen without doing it?")
144
+
145
+ def _add_subcommand_readme(self, subparsers):
146
+ """
147
+ Add 'readme' subcommand to subparsers.
148
+ :param subparsers: The subparsers to update
149
+ """
150
+ cmd = subparsers.add_parser("readme",
151
+ help="display readme")
152
+ cmd.add_argument("-p", "--pager", action="store",
153
+ help="program to display readme (default 'glow')")
154
+ cmd.add_argument("-w", "--width", action="store",
155
+ help="word-wrap readme at width (default 70)", default=70)
156
+
157
+ def _init_parser(self):
158
+ """
159
+ Initialize the argument parser
160
+ """
161
+ parser = argparse.ArgumentParser(self.program,
162
+ description=self.description)
163
+ parser.add_argument("-v", "--version", action="store_true",
164
+ help="display version")
165
+ subparsers = parser.add_subparsers(dest="cmd")
166
+ self._add_subcommand_run(subparsers)
167
+ self._add_subcommand_copy_id(subparsers)
168
+ self._add_subcommand_push(subparsers)
169
+ self._add_subcommand_pull(subparsers)
170
+ if self.readme is not None:
171
+ self._add_subcommand_readme(subparsers)
172
+ self._parser = parser
173
+
174
+ def is_node(self):
175
+ """
176
+ Check if the program is running on a cluster node
177
+ :returns: True if running the a cluster node, False otherwise
178
+ """
179
+ if isinstance(self.nodes, dict):
180
+ nodes = self.nodes.values()
181
+ else:
182
+ nodes = self.nodes
183
+ return is_known_host(nodes)
184
+
185
+ def resolve_node(self, nodes):
186
+ """
187
+ Get single valid nodename from a list of nodes
188
+ :param nodes: A list of nodenames
189
+ """
190
+ host = platform.node().replace(".local", "")
191
+ if nodes is None or len(nodes) != 1:
192
+ sys.exit(f"{self.program}: error: must specify exactly _one_ {self.name} node")
193
+ node = nodes[0]
194
+ if self.is_node():
195
+ if host == node.casefold():
196
+ node = "localhost"
197
+ else:
198
+ node += ".local"
199
+ return node
200
+
201
+ def open_ssh(self,
202
+ node,
203
+ username = None,
204
+ server = None,
205
+ server_username = None,
206
+ port = None):
207
+ """
208
+ Open SSH connection to a cluster node
209
+ :param node: The target cluster node
210
+ :param username: Your username on the cluster
211
+ :param server: The gateway server hostname (optional)
212
+ :param server_username: Your username on the gateway server (optional)
213
+ :param port: Port used for gateway forwarding
214
+ :returns: An open rssh instance
215
+ """
216
+ if username is None:
217
+ username = self.username
218
+ if server is None:
219
+ server = self.server
220
+ if server_username is None:
221
+ server_username = self.server_username
222
+ if port is None:
223
+ port = findport()
224
+ # connect and return the session
225
+ session = rssh(username, node,
226
+ server=server,
227
+ server_username=server_username,
228
+ port=port,
229
+ autoconnect=True)
230
+ return session
231
+
232
+ def parse_args(self):
233
+ """
234
+ Parse command line arguments
235
+ """
236
+ if self._parser is None:
237
+ self._init_parser()
238
+ self._args = self._parser.parse_args()
239
+
240
+ def main(self):
241
+ """
242
+ Run the program
243
+ """
244
+ if self._args is None:
245
+ self.parse_args()
246
+ args = self._args
247
+ # version
248
+ if args.version:
249
+ description = self.description.splitlines()[0]
250
+ print(f"{description} version {self.version} (revised {self.date})")
251
+ print(badwulf_attribution())
252
+ sys.exit()
253
+ # open ssh for server commands
254
+ if args.cmd in ("run", "copy-id", "push", "pull"):
255
+ con = self.open_ssh(self.resolve_node(args.nodes),
256
+ username=args.user,
257
+ server=args.server,
258
+ server_username=args.login,
259
+ port=args.port)
260
+ sleep(1) # allow time to connect
261
+ # help
262
+ if args.cmd is None:
263
+ self._parser.print_help()
264
+ # run
265
+ elif args.cmd == "run":
266
+ if args.remote_command is None:
267
+ con.ssh()
268
+ else:
269
+ print(f"connecting as {con.username}@{con.destination}")
270
+ dest = f"{con.username}@{con.hostname}"
271
+ if con.server is None:
272
+ cmd = ["ssh", dest]
273
+ else:
274
+ cmd = ["ssh", "-o", "NoHostAuthenticationForLocalhost=yes"]
275
+ cmd += ["-p", str(con.port), dest]
276
+ cmd.append(args.remote_command)
277
+ cmd.extend(args.remote_args)
278
+ subprocess.run(cmd)
279
+ # copy-id
280
+ elif args.cmd == "copy-id":
281
+ con.copy_id(args.identity_file)
282
+ # push
283
+ elif args.cmd == "push":
284
+ con.upload(args.src, args.dest,
285
+ dry_run=args.dry_run, ask=args.ask)
286
+ # pull
287
+ elif args.cmd == "pull":
288
+ con.download(args.src, args.dest,
289
+ dry_run=args.dry_run, ask=args.ask)
290
+ # readme
291
+ elif args.cmd == "readme":
292
+ if args.pager is None:
293
+ cmd = ["glow", "-p", "-w", str(args.width)]
294
+ else:
295
+ cmd = [args.pager]
296
+ cmd += [self.readme]
297
+ subprocess.run(cmd)
298
+ sys.exit()