tiktalik-cli 1.10__0-py3-none-any.whl

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.
@@ -0,0 +1,23 @@
1
+ # Copyright (c) 2013 Techstorage sp. z o.o.
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ # this software and associated documentation files (the "Software"), to deal in
5
+ # the Software without restriction, including without limitation the rights to
6
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ # the Software, and to permit persons to whom the Software is furnished to do so,
8
+ # subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
+
20
+ from .main import main
21
+
22
+ if __name__ == "__main__":
23
+ main()
tiktalik_cli/auth.py ADDED
@@ -0,0 +1,92 @@
1
+ """Module tiktalik_cli.auth"""
2
+ # Copyright (c) 2013 Techstorage sp. z o.o.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ # this software and associated documentation files (the "Software"), to deal in
6
+ # the Software without restriction, including without limitation the rights to
7
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ # the Software, and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+
21
+ import os.path
22
+ import os
23
+ import stat
24
+ import errno
25
+ import configparser
26
+ import base64
27
+
28
+
29
+ class AuthError(Exception):
30
+ """AuthError class"""
31
+
32
+
33
+ class SecurityError(Exception):
34
+ """SecurityError class"""
35
+
36
+
37
+ # $HOME/.tiktalik/auth
38
+ CONFIG_DIR = os.path.expanduser("~/.tiktalik")
39
+ CONFIG_FILE_PATH = os.path.join(CONFIG_DIR, "auth")
40
+
41
+
42
+ def add_parser_arguments(parser):
43
+ """Add args to generic parser"""
44
+ parser.add_argument("--key", dest="api_key", required=False, help="Your API Key")
45
+ parser.add_argument(
46
+ "--secret", dest="api_secret", required=False, help="Your API Secret Key"
47
+ )
48
+
49
+
50
+ def get_credentials(args):
51
+ """Read credentials from args"""
52
+ # cmdline credentials override those stored in config file
53
+ if args.api_key or args.api_secret:
54
+ if not args.api_key or not args.api_secret:
55
+ raise AuthError(
56
+ (
57
+ "Both --key and --secret must be provided "
58
+ "when passing auth tokens from commandline."
59
+ )
60
+ )
61
+
62
+ return args.api_key, args.api_secret
63
+
64
+ key, secret = read_from_file()
65
+ if not key:
66
+ raise AuthError(
67
+ (
68
+ "Credentials not configured. "
69
+ "Try `tiktalik init-auth`, or use --key and --secret."
70
+ )
71
+ )
72
+
73
+ return key, base64.b64decode(secret)
74
+
75
+
76
+ def read_from_file():
77
+ """Try to read from file"""
78
+ try:
79
+ st = os.stat(CONFIG_FILE_PATH)
80
+ except OSError as ex:
81
+ if ex.errno == errno.ENOENT:
82
+ return None, None
83
+ else:
84
+ print(("Unable to access %s: %s" % (CONFIG_FILE_PATH, ex)))
85
+
86
+ if (stat.S_IMODE(st.st_mode) != 0o600) and (os.name == "posix"):
87
+ raise SecurityError()
88
+
89
+ cfg = configparser.ConfigParser()
90
+ cfg.read(CONFIG_FILE_PATH)
91
+
92
+ return cfg.get("main", "key"), cfg.get("main", "secret")
@@ -0,0 +1,53 @@
1
+ """Module tiktalik_cli.command"""
2
+ # Copyright (c) 2013 Techstorage sp. z o.o.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ # this software and associated documentation files (the "Software"), to deal in
6
+ # the Software without restriction, including without limitation the rights to
7
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ # the Software, and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+
21
+ from .instance import (
22
+ ListInstances as ListInstances,
23
+ CreateInstance as CreateInstance,
24
+ InstanceCommand as InstanceCommand,
25
+ StartInstance as StartInstance,
26
+ StopInstance as StopInstance,
27
+ BackupInstance as BackupInstance,
28
+ DeleteInstance as DeleteInstance,
29
+ InstanceInfo as InstanceInfo,
30
+ AddInterface as AddInterface,
31
+ RemoveInterface as RemoveInterface,
32
+ )
33
+ from .image import (
34
+ ListImages as ListImages,
35
+ RenameImage as RenameImage,
36
+ DeleteImage as DeleteImage,
37
+ )
38
+ from .network import (
39
+ ListNetworks as ListNetworks,
40
+ CreateNetwork as CreateNetwork,
41
+ )
42
+ from .auth import (
43
+ InitAuth as InitAuth,
44
+ )
45
+ from .command import (
46
+ CommandError as CommandError,
47
+ CommandAborted as CommandAborted,
48
+ Command as Command,
49
+ GeneralCommand as GeneralCommand,
50
+ ComputingCommand as ComputingCommand,
51
+ ComputingImageCommand as ComputingImageCommand,
52
+ ComputingNetworkCommand as ComputingNetworkCommand,
53
+ )
@@ -0,0 +1,62 @@
1
+ """Module tiktalik_cli.command.auth"""
2
+ # Copyright (c) 2013 Techstorage sp. z o.o.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ # this software and associated documentation files (the "Software"), to deal in
6
+ # the Software without restriction, including without limitation the rights to
7
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ # the Software, and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+
21
+ import os
22
+ import errno
23
+ import configparser
24
+ from .command import GeneralCommand, CommandError
25
+ from .. import auth
26
+
27
+
28
+ class InitAuth(GeneralCommand):
29
+ """Initialise auth"""
30
+
31
+ @classmethod
32
+ def add_parser(cls, parser, subparser):
33
+ p = subparser.add_parser(
34
+ "init-auth",
35
+ description="Store auth information locally %s" % auth.CONFIG_FILE_PATH,
36
+ )
37
+ p.add_argument("key", help="Your API Key")
38
+ p.add_argument("secret", help="Your API Secret")
39
+
40
+ return "init-auth"
41
+
42
+ def execute(self):
43
+ key, secret = auth.read_from_file()
44
+ if key:
45
+ raise CommandError(
46
+ "Authentication information already exists in " + auth.CONFIG_FILE_PATH
47
+ )
48
+
49
+ try:
50
+ os.mkdir(auth.CONFIG_DIR)
51
+ os.chmod(auth.CONFIG_DIR, 0o700)
52
+ except OSError as e:
53
+ if e.errno != errno.EEXIST:
54
+ raise CommandError(e)
55
+
56
+ cfg = configparser.ConfigParser()
57
+ cfg.add_section("main")
58
+ cfg.set("main", "key", self.args.key)
59
+ cfg.set("main", "secret", self.args.secret)
60
+
61
+ cfg.write(open(auth.CONFIG_FILE_PATH, "w"))
62
+ os.chmod(auth.CONFIG_FILE_PATH, 0o600)
@@ -0,0 +1,147 @@
1
+ """Module tiktalik_cli.command.command"""
2
+
3
+ import os
4
+ # Copyright (c) 2013 Techstorage sp. z o.o.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
7
+ # this software and associated documentation files (the "Software"), to deal in
8
+ # the Software without restriction, including without limitation the rights to
9
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10
+ # the Software, and to permit persons to whom the Software is furnished to do so,
11
+ # subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ import sys
24
+ from abc import ABC, abstractmethod
25
+ from typing import Optional
26
+ from dataclasses import dataclass
27
+
28
+ from tiktalik import TiktalikAuthConnection
29
+
30
+
31
+ class CommandError(Exception):
32
+ """Command threw an error"""
33
+
34
+
35
+ class CommandAborted(Exception):
36
+ """Command aborted"""
37
+
38
+
39
+ @dataclass
40
+ class ProxyDetails:
41
+ http_proxy: Optional[str]
42
+ https_proxy: Optional[str]
43
+
44
+
45
+ def lookup_proxy_settings() -> ProxyDetails:
46
+ details = ProxyDetails(http_proxy=None, https_proxy=None)
47
+ if os.environ.get("HTTP_PROXY") is not None:
48
+ details.http_proxy = os.environ.get("HTTP_PROXY")
49
+ if os.environ.get("http_proxy") is not None:
50
+ details.http_proxy = os.environ.get("http_proxy")
51
+ if os.environ.get("HTTPS_PROXY") is not None:
52
+ details.https_proxy = os.environ.get("HTTPS_PROXY")
53
+ if os.environ.get("https_proxy") is not None:
54
+ details.https_proxy = os.environ.get("https_proxy")
55
+
56
+ return details
57
+
58
+
59
+ class Command(ABC):
60
+ """Basic command"""
61
+
62
+ def __init__(self, args, keyid, secret, connection_cls):
63
+ self.args = args
64
+ if connection_cls is not None:
65
+ proxy_details = lookup_proxy_settings()
66
+ self.conn = connection_cls(
67
+ keyid,
68
+ secret,
69
+ http_proxy=proxy_details.http_proxy,
70
+ https_proxy=proxy_details.https_proxy,
71
+ )
72
+
73
+ @classmethod
74
+ def add_parser(cls, parser, subparser):
75
+ """Parse command's args"""
76
+ return None
77
+
78
+ @classmethod
79
+ def get_cmd_group_name(cls):
80
+ """Return command group"""
81
+ return "General commands"
82
+
83
+ @abstractmethod
84
+ def execute(self):
85
+ pass
86
+
87
+ @staticmethod
88
+ def yesno(message: str, abort=True) -> bool:
89
+ """Listen for a yes/no answers"""
90
+ print(message)
91
+
92
+ answer = None
93
+ while answer not in ("yes", "no"):
94
+ answer = input("Please answer 'yes' or 'no' > ")
95
+
96
+ if answer == "yes":
97
+ return True
98
+
99
+ if abort:
100
+ print("Aborted")
101
+ sys.exit(1)
102
+ else:
103
+ return False
104
+
105
+
106
+ class GeneralCommand(Command):
107
+ def __init__(self, args, keyid, secret):
108
+ super(GeneralCommand, self).__init__(args, keyid, secret, None)
109
+
110
+ @abstractmethod
111
+ def execute(self):
112
+ pass
113
+
114
+
115
+ class ComputingCommand(Command):
116
+ def __init__(self, args, keyid, secret):
117
+ super(ComputingCommand, self).__init__(
118
+ args, keyid, secret, TiktalikAuthConnection
119
+ )
120
+
121
+ @abstractmethod
122
+ def execute(self):
123
+ pass
124
+
125
+ @classmethod
126
+ def get_cmd_group_name(cls):
127
+ return "Computing commands"
128
+
129
+
130
+ class ComputingImageCommand(ComputingCommand):
131
+ @abstractmethod
132
+ def execute(self):
133
+ pass
134
+
135
+ @classmethod
136
+ def get_cmd_group_name(cls):
137
+ return "Computing image commands"
138
+
139
+
140
+ class ComputingNetworkCommand(ComputingCommand):
141
+ @abstractmethod
142
+ def execute(self):
143
+ pass
144
+
145
+ @classmethod
146
+ def get_cmd_group_name(cls):
147
+ return "Computing network commands"
@@ -0,0 +1,98 @@
1
+ # Copyright (c) 2013 Techstorage sp. z o.o.
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ # this software and associated documentation files (the "Software"), to deal in
5
+ # the Software without restriction, including without limitation the rights to
6
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ # the Software, and to permit persons to whom the Software is furnished to do so,
8
+ # subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
+
20
+ from tiktalik import TiktalikAPIError
21
+
22
+ from .command import ComputingImageCommand, CommandError, Command
23
+
24
+
25
+ class ListImages(ComputingImageCommand):
26
+ @classmethod
27
+ def add_parser(cls, parent, subparser):
28
+ subparser.add_parser(
29
+ "list-images",
30
+ description="List all available VPS Images.",
31
+ parents=[parent],
32
+ )
33
+ return "list-images"
34
+
35
+ def execute(self):
36
+ images = self.conn.list_images()
37
+ for i in images:
38
+ desc = '%s "%s" type=%s' % (i.uuid, i.name, i.type)
39
+ if not i.is_public:
40
+ desc += ", private, %s" % i.create_time
41
+ print(desc)
42
+
43
+
44
+ class RenameImage(ComputingImageCommand):
45
+ @classmethod
46
+ def add_parser(cls, parent, subparser):
47
+ p = subparser.add_parser(
48
+ "rename-image", description="Rename an image.", parents=[parent]
49
+ )
50
+ p.add_argument("uuid", help="Image UUID. This image must belong to you.")
51
+ p.add_argument("name", help="New name for the image.")
52
+
53
+ return "rename-image"
54
+
55
+ def execute(self):
56
+ try:
57
+ self.conn.rename_image(self.args.uuid, self.args.name)
58
+ except TiktalikAPIError as ex:
59
+ if ex.http_status == 400:
60
+ raise CommandError("Invalid image name")
61
+ elif ex.http_status == 401:
62
+ raise CommandError("User unauthenticated")
63
+ elif ex.http_status == 404:
64
+ raise CommandError("Image doesn't exist in your account")
65
+ raise
66
+
67
+ print(("Image %s renamed to %s." % (self.args.uuid, self.args.name)))
68
+
69
+
70
+ class DeleteImage(ComputingImageCommand):
71
+ @classmethod
72
+ def add_parser(cls, parent, subparser):
73
+ p = subparser.add_parser(
74
+ "delete-image", description="Delete an image.", parents=[parent]
75
+ )
76
+ p.add_argument("uuid", help="Image UUID. This image must belong to you.")
77
+ p.add_argument(
78
+ "-f", dest="force", action="store_true", help="Don't confirm the action."
79
+ )
80
+
81
+ return "delete-image"
82
+
83
+ def execute(self):
84
+ confirmed = self.args.force
85
+ if not confirmed:
86
+ confirmed = Command.yesno(
87
+ "Are you sure you want to delete image %s?" % self.args.uuid
88
+ )
89
+
90
+ if confirmed:
91
+ try:
92
+ self.conn.delete_image(self.args.uuid)
93
+ except TiktalikAPIError as ex:
94
+ if ex.http_status == 404:
95
+ raise CommandError("Image doesn't exist in your account")
96
+ raise
97
+
98
+ print(("Image %s deleted." % self.args.uuid))
@@ -0,0 +1,477 @@
1
+ """Module tiktalik_cli.command.instance"""
2
+ # Copyright (c) 2013 Techstorage sp. z o.o.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ # this software and associated documentation files (the "Software"), to deal in
6
+ # the Software without restriction, including without limitation the rights to
7
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ # the Software, and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+
21
+ from tiktalik import Instance, TiktalikAPIError
22
+
23
+ from .command import ComputingCommand, CommandError, Command
24
+ from . import util
25
+
26
+
27
+ class ListInstances(ComputingCommand):
28
+ @classmethod
29
+ def add_parser(cls, parser, subparser):
30
+ p = subparser.add_parser("list", description="List instances", parents=[parser])
31
+ p.add_argument(
32
+ "-a",
33
+ action="store_true",
34
+ dest="actions",
35
+ help="Fetch recent actions for each instance",
36
+ )
37
+ p.add_argument(
38
+ "-c",
39
+ action="store_true",
40
+ dest="cost",
41
+ help="Fetch current hourly cost for each instance",
42
+ )
43
+ p.add_argument(
44
+ "-i",
45
+ action="store_true",
46
+ dest="vpsimage",
47
+ help="Fetch VPS Image details for each instance",
48
+ )
49
+ p.add_argument(
50
+ "-v",
51
+ dest="verbose",
52
+ action="store_true",
53
+ help="Print extra information (flags -a, -i, -t yield more details)",
54
+ )
55
+
56
+ return "list"
57
+
58
+ def execute(self):
59
+ instances = Instance.list_all(
60
+ self.conn,
61
+ actions=self.args.actions,
62
+ cost=self.args.cost,
63
+ vpsimage=self.args.vpsimage,
64
+ )
65
+ for instance in sorted(instances, key=lambda x: x.hostname):
66
+ if not self.args.verbose:
67
+ print(
68
+ (
69
+ "%s (%s) - %s"
70
+ % (
71
+ instance.hostname,
72
+ instance.uuid,
73
+ "Running" if instance.running else "Not running",
74
+ )
75
+ )
76
+ )
77
+ else:
78
+ util.print_instance(instance, verbose=bool(self.args.verbose))
79
+
80
+
81
+ class CreateInstance(ComputingCommand):
82
+ @classmethod
83
+ def add_parser(cls, parent, subparser):
84
+ p = subparser.add_parser(
85
+ "create-instance", description="Create a new instance.", parents=[parent]
86
+ )
87
+ p.add_argument("image_uuid", help="UUID of a VPS Image that should be used.")
88
+ p.add_argument(
89
+ "size",
90
+ help='Instance size (in units). Allowed values: 0.25, 0.5, 1 - 15, "cpuhog", "cpuhog4", "1s", "2s", "4s", "8s" and "16s".',
91
+ )
92
+ p.add_argument("hostname", help="Hostname set at installation time.")
93
+ p.add_argument(
94
+ "-n",
95
+ dest="networks",
96
+ metavar="NETWORK_NAME",
97
+ action="append",
98
+ help="Attach these networks to the new instance. Use the list-networks command to list available networks.",
99
+ )
100
+ p.add_argument(
101
+ "-b",
102
+ dest="batch_mode",
103
+ action="store_true",
104
+ help="Batch mode. Don't confirm the operation.",
105
+ )
106
+ p.add_argument(
107
+ "-d",
108
+ dest="disk_size_gb",
109
+ action="store",
110
+ type=int,
111
+ help="For standard instances must set disk size in GB.",
112
+ )
113
+
114
+ return "create-instance"
115
+
116
+ def execute(self):
117
+ if not self.args.networks:
118
+ raise CommandError("You must specify at least one network")
119
+
120
+ networks = self.conn.list_networks()
121
+
122
+ # Mapping of network names->uuids
123
+ networks = dict((net.name, net.uuid) for net in networks)
124
+
125
+ # Make sure all networks exist
126
+ diff = set(self.args.networks) - set(networks.keys())
127
+ if diff:
128
+ raise CommandError(
129
+ "Some of the networks you specified don't exist: %s" % ", ".join(diff)
130
+ )
131
+
132
+ # List of network uuids instead of names
133
+ networks = [networks[n] for n in self.args.networks]
134
+
135
+ # Validate image existence
136
+ try:
137
+ self.conn.get_image(self.args.image_uuid)
138
+ except TiktalikAPIError as ex:
139
+ if ex.http_status == 404:
140
+ raise CommandError("Image %s not found" % self.args.image_uuid)
141
+
142
+ size = self._parse_instance_size(self.args.size)
143
+
144
+ # For standard instances - must be set disk_size param
145
+ disk_size_gb = None
146
+ if size.endswith("s"):
147
+ if not self.args.disk_size_gb:
148
+ raise CommandError("Disk size not set, see -d param.")
149
+ disk_size_gb = self.args.disk_size_gb
150
+
151
+ if not self.args.batch_mode:
152
+ Command.yesno(
153
+ "Creating new instance with these parameters:\n"
154
+ "Image UUID: %s\nSize: %s\nHostname: %s\nNetworks: %s\n"
155
+ "Is this OK?"
156
+ % (
157
+ self.args.image_uuid,
158
+ size,
159
+ self.args.hostname,
160
+ ", ".join(self.args.networks),
161
+ )
162
+ )
163
+
164
+ self.conn.create_instance(
165
+ self.args.hostname,
166
+ size,
167
+ self.args.image_uuid,
168
+ networks,
169
+ disk_size_gb=disk_size_gb,
170
+ )
171
+
172
+ print(("Instance", self.args.hostname, "is now being installed."))
173
+
174
+ def _parse_instance_size(self, sz):
175
+ """
176
+ Parse instance size passed as string and validate it.
177
+ Valid values are: 0.25, 0.5, integers 1-15, "cpuhog", "cpuhog4", "1s", "2s", "4s", "8s" and "16s".
178
+ Raise CommandError if `sz` is not a valid size.
179
+ """
180
+
181
+ if sz in ("cpuhog", "cpuhog4", "1s", "2s", "4s", "8s", "16s"):
182
+ return sz
183
+
184
+ try:
185
+ sz = float(sz)
186
+ if sz < 1:
187
+ if sz <= 0 or sz not in (0.25, 0.5):
188
+ sz = None
189
+ else:
190
+ sz = int(sz)
191
+ if sz > 15:
192
+ sz = None
193
+ except ValueError:
194
+ sz = None
195
+
196
+ if sz is None:
197
+ raise CommandError(
198
+ 'Instance size must be one of 0.25, 0.5, integral value 1-15, "1s", "2s", "4s", "8s", "16s", "cpuhog" or "cpuhog4".'
199
+ )
200
+
201
+ return str(sz)
202
+
203
+
204
+ class InstanceCommand(ComputingCommand):
205
+ """
206
+ Base class for commands that operate on existing instances, eg. start, stop, info.
207
+ """
208
+
209
+ @classmethod
210
+ def add_common_arguments(cls, parser):
211
+ group = parser.add_mutually_exclusive_group()
212
+ group.add_argument(
213
+ "instance",
214
+ nargs="?",
215
+ default="",
216
+ help="Instance hostname prefix, or instance UUID prefix.",
217
+ )
218
+ group.add_argument(
219
+ "-n",
220
+ dest="hostname",
221
+ help="Instance full hostname. Use -u or `instance' argument if the hostname is not unique.",
222
+ )
223
+ group.add_argument(
224
+ "-u",
225
+ dest="uuid",
226
+ help="Instance full UUID. Can be specified instead of name (-n) or `instance' argument.",
227
+ )
228
+
229
+ def _instance_from_args(self, actions=False, vpsimage=False, cost=False):
230
+ if self.args.hostname and self.args.uuid:
231
+ raise CommandError(
232
+ "Both hostname and UUID can't be specified. Decide on one!"
233
+ )
234
+ if not self.args.hostname and not self.args.uuid and not self.args.instance:
235
+ raise CommandError(
236
+ "Either `instance' argument, hostname (-n) or UUID (-u) must be provided."
237
+ )
238
+
239
+ try:
240
+ # select by hostname/uuid prefix
241
+ if self.args.instance:
242
+ instances = []
243
+ for i in Instance.list_all(self.conn):
244
+ if i.hostname.startswith(self.args.instance):
245
+ instances.append(i)
246
+ elif i.uuid.startswith(self.args.instance):
247
+ instances.append(i)
248
+ if not instances:
249
+ raise CommandError("There is no such instance.")
250
+ if len(instances) > 1:
251
+ print("Matched more than one instance:")
252
+ for i in instances:
253
+ print((" - %s (%s)" % (i.hostname, i.uuid)))
254
+ raise CommandError("Select exactly one instance.")
255
+
256
+ instance = Instance.get_by_uuid(
257
+ self.conn, instances[0].uuid, actions, vpsimage, cost
258
+ )
259
+ # select by full hostname only:
260
+ elif self.args.hostname:
261
+ instances = Instance.get_by_hostname(
262
+ self.conn, self.args.hostname, actions, vpsimage, cost
263
+ )
264
+ if len(instances) > 1:
265
+ msg = ", ".join(i.uuid for i in instances)
266
+ raise CommandError(
267
+ "There are %s instances matching hostname %s: %s"
268
+ % (len(instances), self.args.hostname, msg)
269
+ )
270
+
271
+ instance = instances[0]
272
+ # select by full uuid only:
273
+ else:
274
+ instance = Instance.get_by_uuid(
275
+ self.conn, self.args.uuid, actions, vpsimage, cost
276
+ )
277
+
278
+ return instance
279
+ except TiktalikAPIError as ex:
280
+ if ex.http_status == 404:
281
+ raise CommandError("No such instance.")
282
+ raise
283
+
284
+
285
+ class StartInstance(InstanceCommand):
286
+ @classmethod
287
+ def add_parser(cls, parent, subparser):
288
+ p = subparser.add_parser(
289
+ "start",
290
+ description="Start an instance. Either name or UUID must be specified.",
291
+ parents=[parent],
292
+ )
293
+ InstanceCommand.add_common_arguments(p)
294
+ return "start"
295
+
296
+ def execute(self):
297
+ instance = self._instance_from_args()
298
+ instance.start()
299
+ print(
300
+ (
301
+ "Instance %s (%s) is now being started"
302
+ % (instance.hostname, instance.uuid)
303
+ )
304
+ )
305
+
306
+
307
+ class StopInstance(InstanceCommand):
308
+ @classmethod
309
+ def add_parser(cls, parent, subparser):
310
+ p = subparser.add_parser(
311
+ "stop",
312
+ description="Stop an instance. Send ACPI Shutdown signal (default), or stop forcefully (see -f argument)",
313
+ parents=[parent],
314
+ )
315
+ InstanceCommand.add_common_arguments(p)
316
+ p.add_argument(
317
+ "-f",
318
+ dest="force",
319
+ action="store_true",
320
+ help="Stop the instance forcefully. Do not send gently ACPI Shutdown signal, instead cut the power off.",
321
+ )
322
+
323
+ return "stop"
324
+
325
+ def execute(self):
326
+ instance = self._instance_from_args()
327
+
328
+ if self.args.force:
329
+ instance.force_stop()
330
+ else:
331
+ instance.stop()
332
+
333
+ print(
334
+ (
335
+ "Instance %s (%s) is now being stopped%s"
336
+ % (
337
+ instance.hostname,
338
+ instance.uuid,
339
+ " forcefuly" if self.args.force else "",
340
+ )
341
+ )
342
+ )
343
+
344
+
345
+ class BackupInstance(InstanceCommand):
346
+ @classmethod
347
+ def add_parser(cls, parent, subparser):
348
+ p = subparser.add_parser(
349
+ "backup",
350
+ description="Backup an instance. Either name or UUID must be specified.",
351
+ parents=[parent],
352
+ )
353
+ InstanceCommand.add_common_arguments(p)
354
+ p.add_argument(
355
+ "--set_name",
356
+ type=str,
357
+ help="Set name of your backup",
358
+ )
359
+ return "backup"
360
+
361
+ def execute(self):
362
+ instance = self._instance_from_args()
363
+ if instance.running:
364
+ raise CommandError(
365
+ "Instance is running. Please stop it before starting backup."
366
+ )
367
+ if self.args.set_name:
368
+ instance.backup(self.args.set_name)
369
+ else:
370
+ instance.backup()
371
+ print(
372
+ (
373
+ "Instance %s (%s) is now being backed up"
374
+ % (instance.hostname, instance.uuid)
375
+ )
376
+ )
377
+
378
+
379
+ class DeleteInstance(InstanceCommand):
380
+ @classmethod
381
+ def add_parser(cls, parent, subparser):
382
+ p = subparser.add_parser(
383
+ "delete-instance",
384
+ description="Permanently remove an instance. Either name or UUID must be specified.",
385
+ parents=[parent],
386
+ )
387
+ InstanceCommand.add_common_arguments(p)
388
+ return "delete-instance"
389
+
390
+ def execute(self):
391
+ instance = self._instance_from_args()
392
+
393
+ self.conn.delete_instance(instance.uuid)
394
+ print(
395
+ (
396
+ "Instance %s (%s) is now being removed"
397
+ % (instance.hostname, instance.uuid)
398
+ )
399
+ )
400
+
401
+
402
+ class InstanceInfo(InstanceCommand):
403
+ @classmethod
404
+ def add_parser(cls, parent, subparser):
405
+ p = subparser.add_parser(
406
+ "info", description="Display instance information.", parents=[parent]
407
+ )
408
+ p.add_argument(
409
+ "-a",
410
+ "--all",
411
+ dest="verbose",
412
+ action="store_true",
413
+ help="Print all extra information.",
414
+ )
415
+ InstanceCommand.add_common_arguments(p)
416
+ return "info"
417
+
418
+ def execute(self):
419
+ if not self.args.verbose:
420
+ instance = self._instance_from_args()
421
+ else:
422
+ instance = self._instance_from_args(actions=True, vpsimage=True, cost=True)
423
+ instance.load_block_devices()
424
+ util.print_instance(instance, self.args.verbose)
425
+
426
+
427
+ class AddInterface(InstanceCommand):
428
+ @classmethod
429
+ def add_parser(cls, parent, subparser):
430
+ p = subparser.add_parser(
431
+ "add-interface",
432
+ description="Add a new interface to an instance.",
433
+ parents=[parent],
434
+ )
435
+ p.add_argument(
436
+ "network_uuid",
437
+ help="UUID of a Network that should be attached to this interface",
438
+ )
439
+ p.add_argument("seq", help="Seq number of the interface, eg. 2 maps to eth2")
440
+ InstanceCommand.add_common_arguments(p)
441
+
442
+ return "add-interface"
443
+
444
+ def execute(self):
445
+ instance = self._instance_from_args()
446
+ instance.add_interface(self.args.network_uuid, self.args.seq)
447
+
448
+
449
+ class RemoveInterface(InstanceCommand):
450
+ @classmethod
451
+ def add_parser(cls, parent, subparser):
452
+ p = subparser.add_parser(
453
+ "remove-interface",
454
+ description="Removes network interface from an instance.",
455
+ parents=[parent],
456
+ )
457
+ p.add_argument(
458
+ "seq_or_ip",
459
+ help='Interface name (eg "eth1") or IP address assign to interface to be removed.',
460
+ )
461
+ InstanceCommand.add_common_arguments(p)
462
+
463
+ return "remove-interface"
464
+
465
+ def execute(self):
466
+ instance = self._instance_from_args()
467
+
468
+ seq_str = self.args.seq_or_ip.replace("eth", "")
469
+ iface_uuid = None
470
+ for iface in instance.interfaces:
471
+ if iface.ip == self.args.seq_or_ip or str(iface.seq) == seq_str:
472
+ iface_uuid = iface.uuid
473
+ break
474
+ if not iface_uuid:
475
+ raise CommandError("Cannot find interface by seq nor by IP address.")
476
+
477
+ instance.remove_interface(iface_uuid)
@@ -0,0 +1,74 @@
1
+ """Module tiktalik_cli.command.network"""
2
+ # Copyright (c) 2013 Techstorage sp. z o.o.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ # this software and associated documentation files (the "Software"), to deal in
6
+ # the Software without restriction, including without limitation the rights to
7
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ # the Software, and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+
21
+ from .command import ComputingNetworkCommand
22
+
23
+
24
+ class ListNetworks(ComputingNetworkCommand):
25
+ @classmethod
26
+ def add_parser(cls, parent, subparser):
27
+ subparser.add_parser(
28
+ "list-networks",
29
+ description="List all available networks.",
30
+ parents=[parent],
31
+ )
32
+ return "list-networks"
33
+
34
+ def execute(self):
35
+ networks = self.conn.list_networks()
36
+ for net in networks:
37
+ print(
38
+ (
39
+ "%s %s %s %s, owned by %s"
40
+ % (
41
+ net.name,
42
+ net.uuid,
43
+ net.net,
44
+ "public" if net.public else "private",
45
+ net.owner,
46
+ )
47
+ )
48
+ )
49
+
50
+
51
+ class CreateNetwork(ComputingNetworkCommand):
52
+ @classmethod
53
+ def add_parser(cls, parent, subparser):
54
+ p = subparser.add_parser(
55
+ "create-network", description="Create a new network.", parents=[parent]
56
+ )
57
+ p.add_argument("name", help="Network name - as part of local domain.")
58
+
59
+ return "create-network"
60
+
61
+ def execute(self):
62
+ network = self.conn.create_network(self.args.name)
63
+ print(
64
+ (
65
+ "%s %s %s %s, owned by %s"
66
+ % (
67
+ network.name,
68
+ network.uuid,
69
+ network.net,
70
+ "public" if network.public else "private",
71
+ network.owner,
72
+ )
73
+ )
74
+ )
@@ -0,0 +1,140 @@
1
+ """Module tiktalik_cli.command.util"""
2
+ # Copyright (c) 2013 Techstorage sp. z o.o.
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
5
+ # this software and associated documentation files (the "Software"), to deal in
6
+ # the Software without restriction, including without limitation the rights to
7
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8
+ # the Software, and to permit persons to whom the Software is furnished to do so,
9
+ # subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+
21
+
22
+ def print_iface(n):
23
+ print(
24
+ (
25
+ " eth%i addr: %s mac: %s network: %s"
26
+ % (n.seq, n.ip, n.mac, n.network.name)
27
+ )
28
+ )
29
+
30
+
31
+ def print_action(a):
32
+ s = "%s, started at %s" % (a.description, a.start_time)
33
+ if a.end_time:
34
+ s += ", ended at %s" % a.end_time
35
+ else:
36
+ s = "(In progress: %s%%) %s" % (a.progress, s)
37
+ print((" " + s))
38
+
39
+
40
+ def print_instance(i, verbose=False):
41
+ """
42
+ Helper for printing instance details.
43
+ """
44
+
45
+ print(
46
+ (
47
+ "%s (%s) - %s"
48
+ % (i.hostname, i.uuid, "Running" if i.running else "Not running")
49
+ )
50
+ )
51
+
52
+ if verbose and i.block_devices:
53
+ for b in i.block_devices:
54
+ print((" block device %d: %.1f GB" % (b.seq, b.size_gb)))
55
+
56
+ if not i.interfaces:
57
+ print(" no network interfaces")
58
+ else:
59
+ print(" network interfaces:")
60
+ list(map(print_iface, i.interfaces))
61
+
62
+ print((" default password: %s" % i.default_password))
63
+
64
+ if verbose and i.vpsimage:
65
+ print((" running image %s (%s)" % (i.vpsimage.name, i.vpsimage.uuid)))
66
+
67
+ if verbose and i.actions:
68
+ print(" recent operations:")
69
+ list(map(print_action, i.actions))
70
+
71
+ if verbose and i.gross_cost_per_hour:
72
+ print((" cost per hour: %.5f PLN/h" % i.gross_cost_per_hour))
73
+
74
+
75
+ def print_load_balancer(w):
76
+ """
77
+ Helper for printing LoadBalancer details.
78
+ """
79
+
80
+ print(("%s (%s) %s" % (w.name, w.uuid, w.status)))
81
+ print((" input: %s on %s:%d" % (w.type, w.address, w.port)))
82
+
83
+ if w.type == "HTTP":
84
+ if not w.domains:
85
+ print(" no domains")
86
+ else:
87
+ print(" domains:")
88
+ for d in w.domains:
89
+ print((" %s" % d))
90
+
91
+ if w.monitor:
92
+ print(" health monitor:", end=" ")
93
+ m = w.monitor
94
+ if m.check_type == "tcp":
95
+ print(
96
+ (
97
+ "tcp-connection, interval %0.3f sec, timeout %0.3f sec"
98
+ % (m.interval_ms / 1000.0, m.timeout_ms / 1000.0)
99
+ )
100
+ )
101
+ elif m.check_type == "http":
102
+ print(
103
+ (
104
+ 'http-request, interval %0.3f sec, timeout %0.3f sec, request "%s %s", expected %s'
105
+ % (
106
+ m.interval_ms,
107
+ m.timeout_ms,
108
+ m.http_method,
109
+ m.http_path,
110
+ ",".join(m.http_expect_alive),
111
+ )
112
+ )
113
+ )
114
+ else:
115
+ print("unknown")
116
+
117
+ if not w.backends:
118
+ print(" no backends")
119
+ else:
120
+ print(" backends:")
121
+ for b in w.backends:
122
+ print((" %s:%i, weight=%i (%s)" % (b.ip, b.port, b.weight, b.uuid)))
123
+
124
+ if w.history:
125
+ print(" recent actions:")
126
+ for h in w.history:
127
+ print(
128
+ (
129
+ " %s: (%s %s) %s %s"
130
+ % (
131
+ h.time,
132
+ h.auth,
133
+ h.ip,
134
+ h.action,
135
+ h.arguments if h.arguments else "",
136
+ )
137
+ )
138
+ )
139
+
140
+ print()
tiktalik_cli/main.py ADDED
@@ -0,0 +1,102 @@
1
+ """Module tiktalik_cli.main"""
2
+ #!/usr/bin/env python
3
+ # -*- coding: utf8 -*-
4
+
5
+ # Copyright (c) 2013 Techstorage sp. z o.o.
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy of
8
+ # this software and associated documentation files (the "Software"), to deal in
9
+ # the Software without restriction, including without limitation the rights to
10
+ # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11
+ # the Software, and to permit persons to whom the Software is furnished to do so,
12
+ # subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in all
15
+ # copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19
+ # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20
+ # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21
+ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22
+ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ import argparse
25
+ import textwrap
26
+ import inspect
27
+ import sys
28
+
29
+ from tiktalik import TiktalikAPIError
30
+ from . import command, auth
31
+
32
+
33
+ def main():
34
+ """Main module"""
35
+ parent_parser = argparse.ArgumentParser(add_help=False)
36
+ auth.add_parser_arguments(parent_parser)
37
+
38
+ parser = argparse.ArgumentParser(
39
+ formatter_class=argparse.RawDescriptionHelpFormatter
40
+ )
41
+ subparser = parser.add_subparsers(title="Commands", dest="command")
42
+
43
+ cmd2cls = {} # command name -> command class
44
+ groups = {} # group name -> list of command names
45
+
46
+ # Autodiscover commands; map all commands to their names, as returned by Command.add_parser
47
+ for cls in dir(command):
48
+ cls = getattr(command, cls)
49
+ if inspect.isclass(cls) and issubclass(cls, command.Command):
50
+ name = cls.add_parser(parent_parser, subparser)
51
+ if not name:
52
+ continue
53
+ cmd2cls[name] = cls
54
+ g_name = cls.get_cmd_group_name()
55
+ if g_name not in groups:
56
+ groups[g_name] = []
57
+ groups[g_name].append(name)
58
+
59
+ general_epilog = "Commands by group:\n"
60
+ for g_name in sorted(groups.keys()):
61
+ general_epilog += "\n %s:\n" % g_name
62
+ general_epilog += "".join(" - %s\n" % cmd for cmd in groups[g_name])
63
+ general_epilog += (
64
+ "\nFor more information on a command run "
65
+ "`%(prog)s <command> --help`,\neg. `%(prog)s info --help`\n"
66
+ % {"prog": parser.prog}
67
+ )
68
+ parser.epilog = general_epilog
69
+
70
+ args = parser.parse_args()
71
+
72
+ if args.command is None:
73
+ print(general_epilog)
74
+ sys.exit(1)
75
+
76
+ try:
77
+ if args.command != "init-auth":
78
+ keyid, secret = auth.get_credentials(args)
79
+ else:
80
+ keyid, secret = None, None
81
+
82
+ cls = cmd2cls[args.command]
83
+
84
+ cls(args, keyid, secret).execute()
85
+ except auth.SecurityError:
86
+ msg = (
87
+ """File %s has too liberal access permissions.
88
+
89
+ The file should be readable and writable by the owner only.
90
+ You can fix this by executing:
91
+ """
92
+ % auth.CONFIG_FILE_PATH
93
+ )
94
+
95
+ print("Security error")
96
+ print((textwrap.fill(msg, 76)))
97
+ print()
98
+ print((" chmod 600 %s" % auth.CONFIG_FILE_PATH))
99
+ except (command.CommandError, TiktalikAPIError) as e:
100
+ print((textwrap.fill("Error: " + str(e), 76)))
101
+ except auth.AuthError as e:
102
+ print((textwrap.fill("Error: " + str(e), 76)))
@@ -0,0 +1,77 @@
1
+ Metadata-Version: 2.4
2
+ Name: tiktalik-cli
3
+ Version: 1.10.0
4
+ Summary: Tiktalik Computing command line interface
5
+ Keywords: Tiktalik,CLI,Terminal,VPS
6
+ Author: Techstorage sp. z o.o
7
+ Author-email: Techstorage sp. z o.o <kontakt@tiktalik.com>
8
+ License-Expression: MIT
9
+ Classifier: Programming Language :: Python :: 3 :: Only
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Development Status :: 6 - Mature
15
+ Classifier: Environment :: Console
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Intended Audience :: System Administrators
18
+ Classifier: Intended Audience :: Information Technology
19
+ Classifier: Intended Audience :: End Users/Desktop
20
+ Classifier: Natural Language :: English
21
+ Classifier: Operating System :: POSIX
22
+ Classifier: Operating System :: Microsoft :: Windows
23
+ Classifier: Topic :: Internet
24
+ Classifier: Topic :: Utilities
25
+ Classifier: Topic :: System :: Systems Administration
26
+ Classifier: License :: OSI Approved :: MIT License
27
+ Requires-Dist: tiktalik>=1.8.0
28
+ Requires-Python: >=3.10
29
+ Project-URL: Homepage, https://www.tiktalik.com
30
+ Project-URL: Repository, https://github.com/tiktalik-cloud/tiktalik-cli.git
31
+ Description-Content-Type: text/markdown
32
+
33
+ # Tiktalik Command Line Interface
34
+
35
+ This is a command line interface utility implemented in Python, which enables the
36
+ user to perform core operations on the [Tiktalik Cloud Computing](http://www.tiktalik.com) service.
37
+
38
+ ## Requirements
39
+
40
+ * [tiktalik-python](https://github.com/tiktalik-cloud/tiktalik-python)
41
+ * Python >=3.10
42
+
43
+ Note that package dependencies are automatically installed by pip.
44
+
45
+ ## Installation
46
+
47
+ Install using pip:
48
+
49
+ `$ pip install tiktalik-cli`
50
+
51
+ ## Authentication
52
+
53
+ To use the CLI you need an API key. You can generate one in your
54
+ [admin panel](https://tiktalik.com/panel/#apikeys). The API authentication
55
+ information consists of an *API key* and an *API secret*. You can save this
56
+ information locally by executing:
57
+
58
+ `$ tiktalik init-auth API-KEY API-SECRET`
59
+
60
+ This saves the key and secret to `~/.tiktalik/auth`
61
+
62
+ Alternatively, if you don't want to save your API key, you can use the `--key`
63
+ and `--secret` switches on the commandline.
64
+
65
+ ## Usage
66
+
67
+ The basic usage patterns is:
68
+
69
+ `$ tiktalik COMMAND`
70
+
71
+ You can get a list of commands by running `tiktalik` without arguments.
72
+ To get a help on a specific command, run:
73
+
74
+ `$ tiktalik COMMAND --help`
75
+
76
+ We also have [a tutorial](http://articles.tiktalik.com/content/help/using-tiktalik-command-line-utility/) to quickly get
77
+ you started.
@@ -0,0 +1,14 @@
1
+ tiktalik_cli/__init__.py,sha256=Im5QjN2QMGAnXZXDNhf9Rcs6Cd7S4Nh0uWW3Z3gJ6tI,1162
2
+ tiktalik_cli/auth.py,sha256=8v1JxZSN0aygsCxnZOTGFpG-6AT6TPC9mA8FOQlKMJc,2996
3
+ tiktalik_cli/command/__init__.py,sha256=Fkk-hr6INtFMVh8oB8Eiwi7jhITrCoSqgKcFCVKslM4,2097
4
+ tiktalik_cli/command/auth.py,sha256=NzCQWQ02ssqzL4cEjd24qw-pjxssJF1QGbgz5_bz9IA,2359
5
+ tiktalik_cli/command/command.py,sha256=LDe8Dpo44P5HDmWD75KSQATs23TEAU5xq4bgHA-GhiM,4187
6
+ tiktalik_cli/command/image.py,sha256=JyTamAQHOk1gCzCT04vpxwYUlKeEvgPzx7wARjQV804,3719
7
+ tiktalik_cli/command/instance.py,sha256=805JtvOU5wNhL47NHfb3h0V7qwt7xq61YAx_EpNEgTo,16122
8
+ tiktalik_cli/command/network.py,sha256=BZgq1Ib0_ElhnmI97o1JXFOY9bpgZr-F4knEgdgEKig,2705
9
+ tiktalik_cli/command/util.py,sha256=UIiV9uoQBdWV2TxSFUPnho1A-YJQ_ZBn63fG46wqrIk,4383
10
+ tiktalik_cli/main.py,sha256=29bg1ldSiYXuOtb5aW3isRsfZtx9KCFuuY3_O4ma4pw,3638
11
+ tiktalik_cli-1.10.0.dist-info/WHEEL,sha256=-neZj6nU9KAMg2CnCY6T3w8J53nx1kFGw_9HfoSzM60,79
12
+ tiktalik_cli-1.10.0.dist-info/entry_points.txt,sha256=cnJIQR5oKSib4z5l-iVZqL0iBBf_5-TEEYA3XZ1-mG0,48
13
+ tiktalik_cli-1.10.0.dist-info/METADATA,sha256=mIQnKpsvlyBgx_qMVFetne7hfV5bVPPn2VZfHXqq89o,2609
14
+ tiktalik_cli-1.10.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: uv 0.8.22
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ tiktalik = tiktalik_cli:main
3
+