Skip to content

Commit 9723d47

Browse files
new: Add --cloud-init flag to image upload plugin (#560)
1 parent e3713c3 commit 9723d47

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

linodecli/plugins/image-upload.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ def call(args, context):
9494
nargs="?",
9595
help="A description for this Image. Blank if omitted.",
9696
)
97+
parser.add_argument(
98+
"--cloud-init",
99+
action="store_true",
100+
help="If given, the new image will be flagged as cloud-init compatible.",
101+
)
97102
parser.add_argument(
98103
"file",
99104
metavar="FILE",
@@ -149,6 +154,9 @@ def call(args, context):
149154
if parsed.description:
150155
call_args += ["--description", parsed.description]
151156

157+
if parsed.cloud_init:
158+
call_args += ["--cloud_init", "true"]
159+
152160
status, resp = context.client.call_operation("images", "upload", call_args)
153161

154162
if status != 200:

tests/integration/image/test_plugin_image_upload.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from tests.integration.helpers import get_random_text
1212

13-
REGION = "us-southeast"
13+
REGION = "us-iad"
1414
BASE_CMD = ["linode-cli", "image-upload", "--region", REGION]
1515

1616
# A minimal gzipped image that will be accepted by the API
@@ -96,3 +96,42 @@ def test_file_upload(
9696
# Delete the image
9797
process = exec_test_command(["linode-cli", "images", "rm", image[0]["id"]])
9898
assert process.returncode == 0
99+
100+
101+
@pytest.mark.skipif(platform == "win32", reason="Test N/A on Windows")
102+
def test_file_upload_cloud_init(
103+
fake_image_file,
104+
):
105+
file_path = fake_image_file
106+
label = f"cli-test-{get_random_text()}"
107+
description = "test description"
108+
109+
# Upload the test image
110+
process = exec_test_command(
111+
BASE_CMD
112+
+ [
113+
"--label",
114+
label,
115+
"--description",
116+
description,
117+
"--cloud-init",
118+
file_path,
119+
]
120+
)
121+
122+
assert process.returncode == 0
123+
124+
# Get the new image from the API
125+
process = exec_test_command(
126+
["linode-cli", "images", "ls", "--json", "--label", label]
127+
)
128+
assert process.returncode == 0
129+
130+
image = json.loads(process.stdout.decode())
131+
132+
assert image[0]["label"] == label
133+
assert "cloud-init" in image[0]["capabilities"]
134+
135+
# Delete the image
136+
process = exec_test_command(["linode-cli", "images", "rm", image[0]["id"]])
137+
assert process.returncode == 0

0 commit comments

Comments
 (0)