Skip to content

Commit 0857e40

Browse files
Merge pull request #442 from linode/dev
v0.54.0
2 parents 23a4480 + aefee9a commit 0857e40

37 files changed

+1171
-1096
lines changed

.github/workflows/oci-build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ jobs:
99
runs-on: ubuntu-latest
1010
steps:
1111
- name: Clone Repository
12-
uses: actions/checkout@e2f20e631ae6d7dd3b768f56a5d2af784dd54791 # pin@v2
12+
uses: actions/checkout@v3
1313

1414
- name: setup python 3
15-
uses: actions/setup-python@75f3110429a8c05be0e1bf360334e4cced2b63fa # pin@v2
15+
uses: actions/setup-python@v4
1616
with:
1717
python-version: '3.x'
1818

.github/workflows/publish-pypi.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- name: Checkout
11-
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # pin@v3
11+
uses: actions/checkout@v3
1212

1313
- name: Update system packages
1414
run: sudo apt-get update -y
@@ -17,7 +17,7 @@ jobs:
1717
run: sudo apt-get install -y build-essential
1818

1919
- name: Setup Python
20-
uses: actions/setup-python@75f3110429a8c05be0e1bf360334e4cced2b63fa # pin@v2
20+
uses: actions/setup-python@v4
2121
with:
2222
python-version: '3.x'
2323

.github/workflows/pull-request.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ jobs:
1313
uses: actions/setup-python@v4
1414
with:
1515
python-version: '3.x'
16-
16+
- name: install boto3
17+
run: pip3 install boto3
1718
- name: install dependencies
1819
run: pip3 install -r requirements-dev.txt -r requirements.txt
1920

MANIFEST.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
include linodecli/data-3
22
include linodecli/oauth-landing-page.html
33
include linode-cli.sh
4-
include baked_version
4+
include baked_version
5+
include requirements.txt

README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ Suppressing Defaults
180180
""""""""""""""""""""
181181

182182
If you configured default values for ``image``, ``authorized_users``, ``region``,
183-
and Linode ``type``, they will be sent for all requests that accept them if you
184-
do not specify a different value. If you want to send a request *without* these
183+
database ``engine``, and Linode ``type``, they will be sent for all requests that accept them
184+
if you do not specify a different value. If you want to send a request *without* these
185185
arguments, you must invoke the CLI with the ``--no-defaults`` option.
186186

187187
For example, to create a Linode with no ``image`` after a default Image has been
@@ -474,7 +474,7 @@ added to Linode's OpenAPI spec:
474474
|x-linode-cli-skip | path | If present and truthy, this method will not be available in the CLI. |
475475
+-----------------------------+-------------+-------------------------------------------------------------------------------------------+
476476
+x-linode-cli-allowed-defaults| requestBody | Tells the CLI what configured defaults apply to this request. Valid defaults are "region",|
477-
+ | | "image", "authorized_users", and "type". |
477+
+ | | "image", "authorized_users", "engine", and "type". |
478478
+-----------------------------+-------------+-------------------------------------------------------------------------------------------+
479479
+x-linode-cli-nested-list | content-type| Tells the CLI to flatten a single object into multiple table rows based on the keys |
480480
| | | included in this value. Values should be comma-delimited JSON paths, and must all be |

linodecli/api_request.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ def _build_request_body(ctx, operation, parsed_args) -> Optional[str]:
100100

101101
# Merge defaults into body if applicable
102102
if ctx.defaults:
103-
parsed_args = ctx.config.update(parsed_args, operation.allowed_defaults)
103+
parsed_args = ctx.config.update(
104+
parsed_args, operation.allowed_defaults, operation.action
105+
)
104106

105107
to_json = {k: v for k, v in vars(parsed_args).items() if v is not None}
106108

linodecli/configuration/__init__.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def plugin_get_value(self, key):
212212
# might be better to move this to argparsing during refactor and just have
213213
# configuration return defaults or keys or something
214214
def update(
215-
self, namespace, allowed_defaults
215+
self, namespace, allowed_defaults, action=None
216216
): # pylint: disable=too-many-branches
217217
"""
218218
This updates a Namespace (as returned by ArgumentParser) with config values
@@ -242,6 +242,17 @@ def update(
242242
continue
243243
if self.config.has_option(username, key):
244244
value = self.config.get(username, key)
245+
# different types of database creation use different endpoints,
246+
# so we need to set the default engine value based on the type
247+
elif key == "engine":
248+
if action == "mysql-create" and self.config.has_option(
249+
username, "mysql_engine"
250+
):
251+
value = self.config.get(username, "mysql_engine")
252+
elif action == "postgresql-create" and self.config.has_option(
253+
username, "postgresql_engine"
254+
):
255+
value = self.config.get(username, "postgresql_engine")
245256
else:
246257
value = ns_dict[key]
247258
if not value:
@@ -275,7 +286,7 @@ def write_config(self):
275286

276287
def configure(
277288
self,
278-
): # pylint: disable=too-many-branches,too-many-statements
289+
): # pylint: disable=too-many-branches,too-many-statements,too-many-locals
279290
"""
280291
This assumes we're running interactively, and prompts the user
281292
for a series of defaults in order to make future CLI calls
@@ -336,6 +347,15 @@ def configure(
336347
images = [
337348
i["id"] for i in _do_get_request(self.base_url, "/images")["data"]
338349
]
350+
engines_list = _do_get_request(self.base_url, "/databases/engines")[
351+
"data"
352+
]
353+
mysql_engines = [
354+
e["id"] for e in engines_list if e["engine"] == "mysql"
355+
]
356+
postgresql_engines = [
357+
e["id"] for e in engines_list if e["engine"] == "postgresql"
358+
]
339359

340360
is_full_access = _check_full_access(self.base_url, token)
341361

@@ -378,6 +398,20 @@ def configure(
378398
"Please select a valid Image, or press Enter to skip",
379399
)
380400

401+
config["mysql_engine"] = _default_thing_input(
402+
"Default Engine to create a Managed MySQL Database.",
403+
mysql_engines,
404+
"Default Engine (Optional): ",
405+
"Please select a valid MySQL Database Engine, or press Enter to skip",
406+
)
407+
408+
config["postgresql_engine"] = _default_thing_input(
409+
"Default Engine to create a Managed PostgreSQL Database.",
410+
postgresql_engines,
411+
"Default Engine (Optional): ",
412+
"Please select a valid PostgreSQL Database Engine, or press Enter to skip",
413+
)
414+
381415
if auth_users:
382416
config["authorized_users"] = _default_thing_input(
383417
"Select the user that should be given default SSH access to new Linodes.",

linodecli/configuration/helpers.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def _default_thing_input(
118118
return ret
119119

120120

121-
def _handle_no_default_user(self):
121+
def _handle_no_default_user(self): # pylint: disable=too-many-branches
122122
"""
123123
Handle the case that there is no default user in the config
124124
"""
@@ -167,6 +167,20 @@ def _handle_no_default_user(self):
167167
username, "image", self.config.get("DEFAULT", "image")
168168
)
169169

170+
if self.config.has_option("DEFAULT", "mysql_engine"):
171+
self.config.set(
172+
username,
173+
"mysql_engine",
174+
self.config.get("DEFAULT", "mysql_engine"),
175+
)
176+
177+
if self.config.has_option("DEFAULT", "postgresql_engine"):
178+
self.config.set(
179+
username,
180+
"postgresql_engine",
181+
self.config.get("DEFAULT", "postgresql_engine"),
182+
)
183+
170184
if self.config.has_option("DEFAULT", "authorized_keys"):
171185
self.config.set(
172186
username,

0 commit comments

Comments
 (0)