xpk 0.0.1__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.
Files changed (92) hide show
  1. xpk/__init__.py +15 -0
  2. xpk/api/__init__.py +15 -0
  3. xpk/api/storage_crd.yaml +52 -0
  4. xpk/commands/__init__.py +15 -0
  5. xpk/commands/batch.py +131 -0
  6. xpk/commands/cluster.py +808 -0
  7. xpk/commands/cluster_gcluster.py +269 -0
  8. xpk/commands/common.py +44 -0
  9. xpk/commands/config.py +29 -0
  10. xpk/commands/info.py +243 -0
  11. xpk/commands/inspector.py +357 -0
  12. xpk/commands/job.py +199 -0
  13. xpk/commands/kind.py +283 -0
  14. xpk/commands/kjob_common.py +44 -0
  15. xpk/commands/run.py +128 -0
  16. xpk/commands/shell.py +140 -0
  17. xpk/commands/storage.py +267 -0
  18. xpk/commands/version.py +27 -0
  19. xpk/commands/workload.py +889 -0
  20. xpk/core/__init__.py +15 -0
  21. xpk/core/blueprint/__init__.py +15 -0
  22. xpk/core/blueprint/blueprint_definitions.py +62 -0
  23. xpk/core/blueprint/blueprint_generator.py +708 -0
  24. xpk/core/capacity.py +185 -0
  25. xpk/core/cluster.py +564 -0
  26. xpk/core/cluster_private.py +200 -0
  27. xpk/core/commands.py +356 -0
  28. xpk/core/config.py +179 -0
  29. xpk/core/docker_container.py +225 -0
  30. xpk/core/docker_image.py +210 -0
  31. xpk/core/docker_manager.py +308 -0
  32. xpk/core/docker_resources.py +350 -0
  33. xpk/core/filestore.py +251 -0
  34. xpk/core/gcloud_context.py +196 -0
  35. xpk/core/gcluster_manager.py +176 -0
  36. xpk/core/gcsfuse.py +50 -0
  37. xpk/core/kjob.py +444 -0
  38. xpk/core/kueue.py +358 -0
  39. xpk/core/monitoring.py +134 -0
  40. xpk/core/nap.py +361 -0
  41. xpk/core/network.py +377 -0
  42. xpk/core/nodepool.py +581 -0
  43. xpk/core/pathways.py +377 -0
  44. xpk/core/ray.py +222 -0
  45. xpk/core/remote_state/__init__.py +15 -0
  46. xpk/core/remote_state/fuse_remote_state.py +99 -0
  47. xpk/core/remote_state/remote_state_client.py +38 -0
  48. xpk/core/resources.py +238 -0
  49. xpk/core/scheduling.py +253 -0
  50. xpk/core/storage.py +581 -0
  51. xpk/core/system_characteristics.py +1432 -0
  52. xpk/core/vertex.py +105 -0
  53. xpk/core/workload.py +341 -0
  54. xpk/core/workload_decorators/__init__.py +15 -0
  55. xpk/core/workload_decorators/rdma_decorator.py +129 -0
  56. xpk/core/workload_decorators/storage_decorator.py +52 -0
  57. xpk/core/workload_decorators/tcpxo_decorator.py +190 -0
  58. xpk/main.py +75 -0
  59. xpk/parser/__init__.py +15 -0
  60. xpk/parser/batch.py +43 -0
  61. xpk/parser/cluster.py +662 -0
  62. xpk/parser/common.py +259 -0
  63. xpk/parser/config.py +49 -0
  64. xpk/parser/core.py +135 -0
  65. xpk/parser/info.py +64 -0
  66. xpk/parser/inspector.py +65 -0
  67. xpk/parser/job.py +147 -0
  68. xpk/parser/kind.py +95 -0
  69. xpk/parser/run.py +47 -0
  70. xpk/parser/shell.py +59 -0
  71. xpk/parser/storage.py +316 -0
  72. xpk/parser/validators.py +39 -0
  73. xpk/parser/version.py +23 -0
  74. xpk/parser/workload.py +726 -0
  75. xpk/templates/__init__.py +15 -0
  76. xpk/templates/storage.yaml +13 -0
  77. xpk/utils/__init__.py +15 -0
  78. xpk/utils/console.py +55 -0
  79. xpk/utils/file.py +82 -0
  80. xpk/utils/gcs_utils.py +125 -0
  81. xpk/utils/kubectl.py +57 -0
  82. xpk/utils/network.py +168 -0
  83. xpk/utils/objects.py +88 -0
  84. xpk/utils/templates.py +28 -0
  85. xpk/utils/validation.py +80 -0
  86. xpk/utils/yaml.py +30 -0
  87. xpk-0.0.1.dist-info/LICENSE +202 -0
  88. xpk-0.0.1.dist-info/METADATA +1498 -0
  89. xpk-0.0.1.dist-info/RECORD +92 -0
  90. xpk-0.0.1.dist-info/WHEEL +5 -0
  91. xpk-0.0.1.dist-info/entry_points.txt +2 -0
  92. xpk-0.0.1.dist-info/top_level.txt +1 -0
xpk/parser/job.py ADDED
@@ -0,0 +1,147 @@
1
+ """
2
+ Copyright 2024 Google LLC
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ https://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ """
16
+
17
+ import argparse
18
+ from ..commands.job import job_info, job_list, job_cancel
19
+
20
+ from .common import add_shared_arguments
21
+ from .validators import name_type
22
+
23
+
24
+ def set_job_parser(job_parser: argparse.ArgumentParser):
25
+ job_subcommands = job_parser.add_subparsers(
26
+ title='job subcommands',
27
+ dest='xpk_job_subcommands',
28
+ help=(
29
+ 'These are commands related to job management. Look at help for'
30
+ ' specific subcommands for more details.'
31
+ ),
32
+ )
33
+ set_job_info_parser(
34
+ job_info_parser=job_subcommands.add_parser(
35
+ 'info', help='Show information about specified job.'
36
+ )
37
+ )
38
+ set_job_list_parser(
39
+ job_list_parser=job_subcommands.add_parser('ls', help='List jobs.')
40
+ )
41
+ set_job_cancel_parser(
42
+ job_cancel_parser=job_subcommands.add_parser(
43
+ 'cancel', help='Cancel job execution.'
44
+ )
45
+ )
46
+
47
+
48
+ def set_job_info_parser(job_info_parser: argparse.ArgumentParser):
49
+ job_info_required_arguments = job_info_parser.add_argument_group(
50
+ 'Required arguments',
51
+ 'The basic information required to identify the job.',
52
+ )
53
+ job_info_optional_arguments = job_info_parser.add_argument_group(
54
+ 'Optional Arguments', 'Arguments optional for job info.'
55
+ )
56
+
57
+ ### Required arguments
58
+ job_info_required_arguments.add_argument(
59
+ '--cluster',
60
+ type=name_type,
61
+ default=None,
62
+ help='The name of the cluster to info jobs on.',
63
+ required=True,
64
+ )
65
+
66
+ job_info_optional_arguments.add_argument(
67
+ '--kind-cluster',
68
+ type=bool,
69
+ action=argparse.BooleanOptionalAction,
70
+ default=False,
71
+ help='Apply command to a local test cluster.',
72
+ )
73
+ job_info_required_arguments.add_argument(
74
+ 'name',
75
+ type=str,
76
+ default=None,
77
+ help='Name of the job.',
78
+ )
79
+ job_info_parser.set_defaults(func=job_info)
80
+ add_shared_arguments(job_info_parser)
81
+
82
+
83
+ def set_job_list_parser(job_list_parser: argparse.ArgumentParser):
84
+ job_list_required_arguments = job_list_parser.add_argument_group(
85
+ 'Required Arguments',
86
+ 'Arguments required for job list.',
87
+ )
88
+ job_list_optional_arguments = job_list_parser.add_argument_group(
89
+ 'Optional Arguments', 'Arguments optional for job list.'
90
+ )
91
+
92
+ ### Required arguments
93
+ job_list_required_arguments.add_argument(
94
+ '--cluster',
95
+ type=name_type,
96
+ default=None,
97
+ help='The name of the cluster to list jobs on.',
98
+ required=True,
99
+ )
100
+
101
+ job_list_optional_arguments.add_argument(
102
+ '--kind-cluster',
103
+ type=bool,
104
+ action=argparse.BooleanOptionalAction,
105
+ default=False,
106
+ help='Apply command to a local test cluster.',
107
+ )
108
+
109
+ job_list_parser.set_defaults(func=job_list)
110
+ add_shared_arguments(job_list_optional_arguments)
111
+
112
+
113
+ def set_job_cancel_parser(job_cancel_parser: argparse.ArgumentParser):
114
+ job_cancel_required_arguments = job_cancel_parser.add_argument_group(
115
+ 'Required Arguments',
116
+ 'Arguments required for job cancel.',
117
+ )
118
+ job_cancel_optional_arguments = job_cancel_parser.add_argument_group(
119
+ 'Optional Arguments', 'Arguments optional for job cancel.'
120
+ )
121
+
122
+ job_cancel_required_arguments.add_argument(
123
+ 'name',
124
+ type=str,
125
+ default=None,
126
+ help='The name of the job to be cancelled.',
127
+ nargs='+',
128
+ )
129
+
130
+ job_cancel_required_arguments.add_argument(
131
+ '--cluster',
132
+ type=name_type,
133
+ default=None,
134
+ help='The name of the cluster to delete the job on.',
135
+ required=True,
136
+ )
137
+
138
+ job_cancel_optional_arguments.add_argument(
139
+ '--kind-cluster',
140
+ type=bool,
141
+ action=argparse.BooleanOptionalAction,
142
+ default=False,
143
+ help='Apply command to a local test cluster.',
144
+ )
145
+
146
+ job_cancel_parser.set_defaults(func=job_cancel)
147
+ add_shared_arguments(job_cancel_optional_arguments)
xpk/parser/kind.py ADDED
@@ -0,0 +1,95 @@
1
+ """
2
+ Copyright 2024 Google LLC
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ https://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ """
16
+
17
+ from ..commands.kind import (
18
+ cluster_create,
19
+ cluster_delete,
20
+ cluster_list,
21
+ )
22
+ from .common import add_global_arguments
23
+ from .validators import name_type
24
+
25
+
26
+ def set_kind_parser(kind_parser):
27
+ cluster_subcommands = kind_parser.add_subparsers(
28
+ title='kind subcommands',
29
+ dest='xpk_kind_subcommands',
30
+ help=(
31
+ 'These are commands related to kind management. Look at help for'
32
+ ' specific subcommands for more details.'
33
+ ),
34
+ )
35
+
36
+ ### "cluster create" command parser ###
37
+ cluster_create_parser = cluster_subcommands.add_parser(
38
+ 'create', help='Create local clusters.'
39
+ )
40
+
41
+ ### Optional Arguments
42
+ cluster_create_parser.add_argument(
43
+ '--cluster',
44
+ type=name_type,
45
+ default='kind',
46
+ help=(
47
+ 'The name of the cluster. Will be used as the prefix for internal'
48
+ ' objects in the cluster.'
49
+ ),
50
+ required=False,
51
+ )
52
+
53
+ cluster_create_parser.add_argument(
54
+ '--k8s-version',
55
+ type=str,
56
+ default='',
57
+ help='The Kubernetes version of the cluster.',
58
+ required=False,
59
+ )
60
+
61
+ add_global_arguments(cluster_create_parser)
62
+ cluster_create_parser.set_defaults(func=cluster_create)
63
+
64
+ ### "cluster delete" command parser ###
65
+ cluster_delete_parser = cluster_subcommands.add_parser(
66
+ 'delete',
67
+ help='Delete cloud clusters.',
68
+ )
69
+
70
+ cluster_delete_required_arguments = cluster_delete_parser.add_argument_group(
71
+ 'Required Arguments',
72
+ 'Arguments required for cluster delete.',
73
+ )
74
+
75
+ ### Required arguments
76
+ cluster_delete_required_arguments.add_argument(
77
+ '--cluster',
78
+ type=name_type,
79
+ default=None,
80
+ help='The name of the cluster to be deleted.',
81
+ required=True,
82
+ )
83
+
84
+ ### Optional Arguments
85
+ add_global_arguments(cluster_delete_parser)
86
+ cluster_delete_parser.set_defaults(func=cluster_delete)
87
+
88
+ # "cluster list" command parser.
89
+ cluster_list_parser = cluster_subcommands.add_parser(
90
+ 'list', help='List cloud clusters.'
91
+ )
92
+
93
+ ### Optional Arguments
94
+ add_global_arguments(cluster_list_parser)
95
+ cluster_list_parser.set_defaults(func=cluster_list)
xpk/parser/run.py ADDED
@@ -0,0 +1,47 @@
1
+ """
2
+ Copyright 2025 Google LLC
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ https://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ """
16
+
17
+ from ..commands.run import run
18
+ from .common import (
19
+ add_shared_arguments,
20
+ add_slurm_arguments,
21
+ add_cluster_arguments,
22
+ add_kind_cluster_arguments,
23
+ )
24
+
25
+
26
+ def set_run_parser(run_parser):
27
+ run_required_arguments = run_parser.add_argument_group(
28
+ 'Required Arguments', 'Arguments required for `run`.'
29
+ )
30
+ run_optional_arguments = run_parser.add_argument_group(
31
+ 'Optional Arguments', 'Arguments optional for `run`.'
32
+ )
33
+
34
+ run_required_arguments.add_argument('script', help='script with task to run')
35
+ run_optional_arguments.add_argument(
36
+ '--timeout',
37
+ type=int,
38
+ default=None,
39
+ help='Amount of time to wait for job in seconds',
40
+ required=False,
41
+ )
42
+
43
+ add_cluster_arguments(run_optional_arguments)
44
+ add_kind_cluster_arguments(run_optional_arguments)
45
+ add_slurm_arguments(run_optional_arguments)
46
+ add_shared_arguments(run_parser)
47
+ run_parser.set_defaults(func=run)
xpk/parser/shell.py ADDED
@@ -0,0 +1,59 @@
1
+ """
2
+ Copyright 2024 Google LLC
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ https://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ """
16
+
17
+ from ..commands.shell import shell, shell_stop
18
+ from .common import (
19
+ add_shared_arguments,
20
+ add_cluster_arguments,
21
+ add_kind_cluster_arguments,
22
+ )
23
+ import argparse
24
+
25
+
26
+ def set_shell_parser(shell_parser: argparse.ArgumentParser) -> None:
27
+ shell_optional_arguments = shell_parser.add_argument_group(
28
+ 'Optional Arguments', 'Arguments optional for shell.'
29
+ )
30
+ add_shared_arguments(shell_optional_arguments)
31
+ shell_parser.set_defaults(func=shell)
32
+
33
+ add_cluster_arguments(shell_optional_arguments)
34
+ add_kind_cluster_arguments(shell_optional_arguments)
35
+
36
+ shell_subcommands = shell_parser.add_subparsers(
37
+ title='shell subcommands',
38
+ dest='xpk_shell_subcommands',
39
+ help=(
40
+ 'These are commands related to interactive shell. Look at help for'
41
+ ' specific subcommands for more details.'
42
+ ),
43
+ )
44
+
45
+ set_shell_stop_parser(
46
+ shell_stop_parser=shell_subcommands.add_parser(
47
+ name='stop', help='Stop the running shell.'
48
+ )
49
+ )
50
+
51
+
52
+ def set_shell_stop_parser(shell_stop_parser: argparse.ArgumentParser):
53
+ shell_stop_optional_arguments = shell_stop_parser.add_argument_group(
54
+ 'Optional Arguments', 'Arguments optional for shell stop.'
55
+ )
56
+ add_shared_arguments(shell_stop_optional_arguments)
57
+ shell_stop_parser.set_defaults(func=shell_stop)
58
+ add_cluster_arguments(shell_stop_parser)
59
+ add_kind_cluster_arguments(shell_stop_optional_arguments)
xpk/parser/storage.py ADDED
@@ -0,0 +1,316 @@
1
+ """
2
+ Copyright 2024 Google LLC
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ https://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ """
16
+
17
+ import argparse
18
+
19
+ from ..commands.storage import (
20
+ storage_attach,
21
+ storage_create,
22
+ storage_delete,
23
+ storage_detach,
24
+ storage_list,
25
+ )
26
+ from .common import (
27
+ add_cluster_arguments,
28
+ add_kind_cluster_arguments,
29
+ add_shared_arguments,
30
+ )
31
+
32
+
33
+ def set_storage_parser(storage_parser: argparse.ArgumentParser) -> None:
34
+ storage_subcommands = storage_parser.add_subparsers(
35
+ title='storage subcommands',
36
+ dest='xpk_storage_subcommands',
37
+ help=(
38
+ 'These are commands related to storage management. Look at help for'
39
+ ' specific subcommands for more details.'
40
+ ),
41
+ )
42
+ add_storage_attach_parser(storage_subcommands)
43
+ add_storage_list_parser(storage_subcommands)
44
+ add_storage_detach_parser(storage_subcommands)
45
+ add_storage_create_parser(storage_subcommands)
46
+ add_storage_delete_parser(storage_subcommands)
47
+
48
+
49
+ def add_storage_attach_parser(
50
+ storage_subcommands_parser: argparse.ArgumentParser,
51
+ ) -> None:
52
+
53
+ storage_attach_parser: argparse.ArgumentParser = (
54
+ storage_subcommands_parser.add_parser(
55
+ 'attach', help='attach XPK Storage.'
56
+ )
57
+ )
58
+ storage_attach_parser.set_defaults(func=storage_attach)
59
+ req_args = storage_attach_parser.add_argument_group(
60
+ 'Required Arguments',
61
+ 'Arguments required for storage attach.',
62
+ )
63
+ add_shared_arguments(req_args)
64
+ req_args.add_argument(
65
+ 'name',
66
+ type=str,
67
+ help='The name of storage',
68
+ )
69
+ req_args.add_argument(
70
+ '--type',
71
+ type=str,
72
+ help=(
73
+ 'The type of storage. Currently supported types: ["gcsfuse",'
74
+ ' "gcpfilestore"]'
75
+ ),
76
+ choices=['gcsfuse', 'gcpfilestore'],
77
+ required=True,
78
+ )
79
+ add_cluster_arguments(req_args, required=True)
80
+ req_args.add_argument(
81
+ '--auto-mount',
82
+ type=lambda v: v.lower() == 'true',
83
+ default=True,
84
+ required=True,
85
+ help='If true all workloads will have this storage mounted by default',
86
+ )
87
+ req_args.add_argument(
88
+ '--mount-point',
89
+ type=str,
90
+ required=True,
91
+ help='Path on which a given storage should be mounted for a workload',
92
+ )
93
+ req_args.add_argument(
94
+ '--readonly',
95
+ type=lambda v: v.lower() == 'true',
96
+ required=True,
97
+ help='If true workloads can only read from storage',
98
+ )
99
+
100
+ gcsfuse_args = storage_attach_parser.add_argument_group(
101
+ 'FUSE arguments',
102
+ 'Arguments used when --type=gcsfuse',
103
+ )
104
+ gcsfuse_args.add_argument(
105
+ '--size',
106
+ type=int,
107
+ help='The size of the volume to attach in gigabytes.',
108
+ )
109
+ gcsfuse_args.add_argument(
110
+ '--bucket',
111
+ type=str,
112
+ help=(
113
+ '(optional) Name of the bucket. If not set, then the "name" parameter'
114
+ ' is infered as a bucket name.'
115
+ ),
116
+ )
117
+
118
+ gcpfilestore_args = storage_attach_parser.add_argument_group(
119
+ 'Filestore arguments',
120
+ 'Arguments used when --type=gcpfilestore',
121
+ )
122
+ gcpfilestore_args.add_argument(
123
+ '--vol',
124
+ type=str,
125
+ help='(optional) The name of the volume to create. Default: "default"',
126
+ default='default',
127
+ )
128
+ gcpfilestore_args.add_argument(
129
+ '--access-mode',
130
+ type=str,
131
+ choices=['ReadWriteOnce', 'ReadOnlyMany', 'ReadWriteMany'],
132
+ help=(
133
+ '(optional) Access mode of created filestore instance. Default:'
134
+ ' "ReadWriteMany"'
135
+ ),
136
+ default='ReadWriteMany',
137
+ )
138
+ gcpfilestore_args.add_argument(
139
+ '--instance',
140
+ type=str,
141
+ help=(
142
+ '(optional) Name of the filestore instance. If not set, then the'
143
+ ' "name" parameter is infered as an instance name.'
144
+ ),
145
+ )
146
+
147
+ opt_args = storage_attach_parser.add_argument_group(
148
+ 'Optional Arguments',
149
+ 'Optional arguments for storage create.',
150
+ )
151
+ add_kind_cluster_arguments(opt_args)
152
+
153
+
154
+ def add_storage_create_parser(
155
+ storage_subcommands_parser: argparse.ArgumentParser,
156
+ ) -> None:
157
+ storage_create_parser: argparse.ArgumentParser = (
158
+ storage_subcommands_parser.add_parser(
159
+ 'create', help='create XPK Storage.'
160
+ )
161
+ )
162
+ storage_create_parser.set_defaults(func=storage_create)
163
+ req_args = storage_create_parser.add_argument_group(
164
+ 'Required Arguments',
165
+ 'Arguments required for storage create.',
166
+ )
167
+ add_shared_arguments(req_args)
168
+ req_args.add_argument(
169
+ 'name',
170
+ type=str,
171
+ help='The name of storage',
172
+ )
173
+ req_args.add_argument(
174
+ '--size',
175
+ type=str,
176
+ help=(
177
+ 'The size of the volume to create in gigabytes or terabytes. If no'
178
+ ' unit is specified, gigabytes are assumed.'
179
+ ),
180
+ required=True,
181
+ )
182
+
183
+ req_args.add_argument(
184
+ '--type',
185
+ type=str,
186
+ help='The type of storage. Currently supported types: ["gcpfilestore"]',
187
+ choices=['gcpfilestore'],
188
+ required=True,
189
+ )
190
+ add_cluster_arguments(req_args, required=True)
191
+ req_args.add_argument(
192
+ '--mount-point',
193
+ type=str,
194
+ required=True,
195
+ )
196
+ req_args.add_argument(
197
+ '--readonly', type=lambda v: v.lower() == 'true', required=True
198
+ )
199
+
200
+ opt_args = storage_create_parser.add_argument_group(
201
+ 'Optional Arguments',
202
+ 'Optional arguments for storage create.',
203
+ )
204
+ opt_args.add_argument(
205
+ '--instance',
206
+ type=str,
207
+ help=(
208
+ '(optional) Name of the filestore instance. If not set, then the'
209
+ ' "name" parameter is infered as an instance name.'
210
+ ),
211
+ )
212
+ opt_args.add_argument(
213
+ '--vol',
214
+ type=str,
215
+ help='The name of the volume to create',
216
+ required=True,
217
+ default='default',
218
+ )
219
+ opt_args.add_argument(
220
+ '--tier',
221
+ type=str,
222
+ help=(
223
+ 'The tier of the filestore to create. Possible values are:'
224
+ ' [BASIC_HDD, BASIC_SSD, ZONAL, REGIONAL, ENTERPRISE]'
225
+ ),
226
+ choices=['BASIC_HDD', 'BASIC_SSD', 'ZONAL', 'REGIONAL', 'ENTERPRISE'],
227
+ default='REGIONAL',
228
+ )
229
+ opt_args.add_argument(
230
+ '--auto-mount',
231
+ type=lambda v: v.lower() == 'true',
232
+ default=True,
233
+ )
234
+ opt_args.add_argument(
235
+ '--access-mode',
236
+ type=str,
237
+ choices=['ReadWriteOnce', 'ReadOnlyMany', 'ReadWriteMany'],
238
+ help='Access mode of created filestore instance',
239
+ default='ReadWriteMany',
240
+ )
241
+
242
+ add_kind_cluster_arguments(opt_args)
243
+
244
+
245
+ def add_storage_list_parser(
246
+ storage_subcommands_parser: argparse.ArgumentParser,
247
+ ):
248
+ storage_list_parser: argparse.ArgumentParser = (
249
+ storage_subcommands_parser.add_parser('list', help='List XPK Storages.')
250
+ )
251
+ storage_list_parser.set_defaults(func=storage_list)
252
+ add_shared_arguments(storage_list_parser)
253
+ req_args = storage_list_parser.add_argument_group(
254
+ 'Required Arguments',
255
+ 'Arguments required for storage list.',
256
+ )
257
+ req_args.add_argument(
258
+ '--cluster',
259
+ type=str,
260
+ )
261
+
262
+
263
+ def add_storage_detach_parser(
264
+ storage_subcommands_parser: argparse.ArgumentParser,
265
+ ):
266
+ storage_detach_parser: argparse.ArgumentParser = (
267
+ storage_subcommands_parser.add_parser(
268
+ 'detach', help='Detach XPK Storage.'
269
+ )
270
+ )
271
+ storage_detach_parser.set_defaults(func=storage_detach)
272
+ add_shared_arguments(storage_detach_parser)
273
+
274
+ req_args = storage_detach_parser.add_argument_group(
275
+ 'Required Arguments',
276
+ 'Arguments required for storage detach.',
277
+ )
278
+ req_args.add_argument('name', type=str)
279
+ add_cluster_arguments(req_args, required=True)
280
+
281
+ opt_args = storage_detach_parser.add_argument_group(
282
+ 'Optional Arguments',
283
+ 'Optional arguments for storage delete.',
284
+ )
285
+ add_kind_cluster_arguments(opt_args)
286
+
287
+
288
+ def add_storage_delete_parser(
289
+ storage_subcommands_parser: argparse.ArgumentParser,
290
+ ):
291
+ storage_delete_parser: argparse.ArgumentParser = (
292
+ storage_subcommands_parser.add_parser(
293
+ 'delete', help='Delete XPK Storage.'
294
+ )
295
+ )
296
+ storage_delete_parser.set_defaults(func=storage_delete)
297
+ add_shared_arguments(storage_delete_parser)
298
+
299
+ req_args = storage_delete_parser.add_argument_group(
300
+ 'Required Arguments',
301
+ 'Arguments required for storage delete.',
302
+ )
303
+ req_args.add_argument('name', type=str)
304
+ add_cluster_arguments(req_args, required=True)
305
+
306
+ opt_args = storage_delete_parser.add_argument_group(
307
+ 'Optional Arguments',
308
+ 'Optional arguments for storage delete.',
309
+ )
310
+ opt_args.add_argument(
311
+ '--force',
312
+ '-f',
313
+ action='store_true',
314
+ help='Force filestore instance deletion even if it has attached storages',
315
+ )
316
+ add_kind_cluster_arguments(opt_args)
@@ -0,0 +1,39 @@
1
+ """
2
+ Copyright 2024 Google LLC
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ https://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ """
16
+
17
+ import argparse
18
+ import os
19
+ import re
20
+
21
+
22
+ def name_type(value, pat=re.compile(r'[a-z]([-a-z0-9]*[a-z0-9])?')):
23
+ """Validate that the name matches the expected pattern."""
24
+ match = pat.fullmatch(value)
25
+ if not match or len(match.group(0)) > 40:
26
+ raise argparse.ArgumentTypeError(
27
+ 'Name must be less than 40 characters and match the pattern'
28
+ f' `{pat.pattern}`'
29
+ f' Name is currently {value}'
30
+ )
31
+ return value
32
+
33
+
34
+ def directory_path_type(value):
35
+ if not os.path.isdir(value):
36
+ raise argparse.ArgumentTypeError(
37
+ f'Directory path is invalid. User provided path was {value}'
38
+ )
39
+ return value