mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Sometimes the first page does not have any results. Try next page if there's a next token.
Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
parent
9dffea3178
commit
eb71862449
1 changed files with 42 additions and 33 deletions
75
tools/vm.py
75
tools/vm.py
|
@ -720,41 +720,50 @@ class VM:
|
|||
client = boto3.client("ec2", region_name=self.region_name)
|
||||
# Let's search for the launch template corresponding to this AMI
|
||||
launch_template_name = None
|
||||
next_token = ""
|
||||
try:
|
||||
response = response = client.describe_launch_templates(
|
||||
Filters=[
|
||||
{
|
||||
"Name": "tag:spb:is-golden-image-template",
|
||||
"Values": ["true"],
|
||||
},
|
||||
{
|
||||
"Name": "tag:spb:project",
|
||||
"Values": ["salt-project"],
|
||||
},
|
||||
{
|
||||
"Name": "tag:spb:environment",
|
||||
"Values": [environment],
|
||||
},
|
||||
{
|
||||
"Name": "tag:spb:image-id",
|
||||
"Values": [self.config.ami],
|
||||
},
|
||||
]
|
||||
)
|
||||
log.debug(
|
||||
"Search for launch template response:\n%s", pprint.pformat(response)
|
||||
)
|
||||
for details in response.get("LaunchTemplates"):
|
||||
if launch_template_name is not None:
|
||||
log.warning(
|
||||
"Multiple launch templates for the same AMI. This is not "
|
||||
"supposed to happen. Picked the first one listed: %s",
|
||||
response,
|
||||
)
|
||||
break
|
||||
launch_template_name = details["LaunchTemplateName"]
|
||||
while True:
|
||||
response = response = client.describe_launch_templates(
|
||||
Filters=[
|
||||
{
|
||||
"Name": "tag:spb:is-golden-image-template",
|
||||
"Values": ["true"],
|
||||
},
|
||||
{
|
||||
"Name": "tag:spb:project",
|
||||
"Values": ["salt-project"],
|
||||
},
|
||||
{
|
||||
"Name": "tag:spb:environment",
|
||||
"Values": [environment],
|
||||
},
|
||||
{
|
||||
"Name": "tag:spb:image-id",
|
||||
"Values": [self.config.ami],
|
||||
},
|
||||
],
|
||||
NextToken=next_token,
|
||||
)
|
||||
log.debug(
|
||||
"Search for launch template response:\n%s",
|
||||
pprint.pformat(response),
|
||||
)
|
||||
for details in response.get("LaunchTemplates"):
|
||||
if launch_template_name is not None:
|
||||
log.warning(
|
||||
"Multiple launch templates for the same AMI. This is not "
|
||||
"supposed to happen. Picked the first one listed: %s",
|
||||
response,
|
||||
)
|
||||
break
|
||||
launch_template_name = details["LaunchTemplateName"]
|
||||
|
||||
if launch_template_name is None:
|
||||
if launch_template_name is not None:
|
||||
break
|
||||
|
||||
next_token = response.get("NextToken")
|
||||
if next_token:
|
||||
continue
|
||||
self.ctx.error(f"Could not find a launch template for {self.name!r}")
|
||||
self.ctx.exit(1)
|
||||
except ClientError as exc:
|
||||
|
|
Loading…
Add table
Reference in a new issue