-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Spawn virtual machines using nodepool images on ci.centos.org
We are going to be uploading nodepool images to the rdo-centos tenant in RDO cloud. Since nodepool isn't going to be the one spawning the virtual machines, we need to update our create-vm script so it knows which image to use. Change-Id: I85e3eed1436f7de3bae2d01a0b4adf23f1a0973c Depends-On: I1236e01fe54309d5b59f28be21abe9da1c8695fa
- Loading branch information
David Moreau Simard
authored and
Gerrit Code Review
committed
May 11, 2018
1 parent
516411b
commit cbc0ea2
Showing
2 changed files
with
68 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/env python | ||
# Copyright Red Hat, Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
|
||
# Returns the latest nodepool image matching a pattern from a cloud | ||
|
||
import argparse | ||
import shade | ||
import sys | ||
|
||
|
||
def get_args(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('cloud', help='name of the cloud in clouds.yaml') | ||
parser.add_argument('--pattern', help='image name pattern to look for', | ||
default='template-rdo-centos-7') | ||
args = parser.parse_args() | ||
return args | ||
|
||
|
||
def main(): | ||
args = get_args() | ||
cloud = shade.openstack_cloud(cloud=args.cloud) | ||
|
||
# List all images | ||
images = cloud.list_images() | ||
|
||
# From those images, only pick the ones that have been uploaded by nodepool | ||
# and match our pattern | ||
nodepool_images = [ | ||
image | ||
for image in images | ||
if 'nodepool_build_id' in image['properties'] and | ||
args.pattern in image['name'] | ||
] | ||
|
||
if nodepool_images: | ||
# If there are any matches, alphabetically sort them by name | ||
# This allows us to easily get the latest image since nodepool suffixes | ||
# a unix timestamp at the end after the pattern. | ||
nodepool_images = sorted(nodepool_images, key=lambda k: k['name']) | ||
print(nodepool_images[-1]['name']) | ||
sys.exit(0) | ||
else: | ||
sys.exit(1) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |