Skip to content

Commit

Permalink
cleanup, prints to logs, comments to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
craigcomstock committed Apr 1, 2024
1 parent 685e41c commit 63a8cd3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,9 @@ To install `cf-remote` so that it reflects any changes in this source directory
```
$ pip install --editable .
```

## cloud_data.py tips

In order to find AWS images for a particular owner to work on cloud_data.py name_pattern list the names for an owner with the following `aws` command:

aws ec2 describe-images --region us-east-2 --owners 801119661308 --query 'Images[*].[Name]' --output text
18 changes: 6 additions & 12 deletions cf_remote/spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def get_cloud_driver(provider, creds, region):

return driver

# the string platform_name should be something of the form platform-version-architecture
# the string platform_name can be platform, platform-version(partial even), or platform-version-architecture
# The data in cloud_data.py aws_image_criteria can have general information for just
# `platform` or include all the components if necessary.
#
Expand All @@ -306,7 +306,7 @@ def get_cloud_driver(provider, creds, region):
def _get_image_criteria(
platform_name
):
print(f'_get_ami({platform_name})')
log.debug("Looking for AWS AMI for platform_name '%s'" % (platform_name))
platform = platform_name.split('-')[0]
if platform == 'ubuntu':
if platform_name.count('-') > 0:
Expand All @@ -317,17 +317,15 @@ def _get_image_criteria(
platform_version = platform_name.count('-') > 0 and platform_name.split('-')[1] or ''
if platform == 'centos' and platform_version == '':
raise ValueError("CentOS platform requires a version. None provided in '%s'" % (platform_name))
print(f'platform_version={platform_version}')
log.debug("Parsed platform_version '%s' from platform_name '%s'" % (platform_version, platform_name))
platform_with_major_version = '-'.join(platform_name.split('-')[0:2])
print(f'platform_with_major_version={platform_with_major_version}')
architecture = platform_name.count('-') > 0 and platform_name.split('-')[-1]
architecture = platform_name.split('-')[-1]
if not (architecture == 'x64' or architecture == 'arm64'):
architecture = 'x64'
# raise ValueError("Architecture must be x64 or arm64. '%s' was provided." % (architecture))
if architecture == 'x64':
architecture = 'x86_64'
print(f'architecture={architecture}')
log.debug("Determined architecture to be '%s'" % (architecture))

# Assign a value to criteria variable based on the given conditions
if platform_with_major_version in aws_image_criteria:
Expand All @@ -337,13 +335,9 @@ def _get_image_criteria(

criteria['architecture'] = architecture
criteria['version'] = platform_version
print(f'CRAIG: _get_image_criteria() returning {criteria}')
log.debug("Determined image criteria: %s" % (criteria))
return criteria

# todo might be nice to have a cf-remote --list-images <platform>
# and we return all images from this and let the caller do the query/sort/take most recent
# workaround for now is to look at owners in cloud_data.py and execute an aws command like:
# aws ec2 describe-images --region us-east-2 --owners 801119661308 --query 'Images[*].[Name]' --output text
def _get_ami(
criteria,
driver # refactor, we have self._driver but not used?
Expand All @@ -361,7 +355,7 @@ def _get_ami(
if len(candidates) == 0:
raise ValueError("No images found for criteria: %s" % (criteria))
selected = sorted(candidates, key=lambda x: x.extra['creation_date'], reverse=True)[0]
print(selected)
log.debug("Selected image %s" % (selected))
return selected.id

def spawn_vm_in_aws(
Expand Down

0 comments on commit 63a8cd3

Please sign in to comment.