Skip to content
This repository has been archived by the owner on Aug 9, 2024. It is now read-only.

Commit

Permalink
Use new-style of accessing ec2 drivers.
Browse files Browse the repository at this point in the history
According to the libcloud docs, the way you're supposed to access these
provider/driver objects changed in 0.14.0 and this is the way you're
supposed to do it now.  I tested this method by hand and was able to
create and destroy a temporary keypair in the eu-central-1 region, so..
I think it should work.

Please eyeball for typos as I haven't been able to test the full fedimg
cycle yet.

See https://libcloud.readthedocs.org/en/latest/upgrade_notes.html#amazon-ec2-compute-driver-changes
  • Loading branch information
ralphbean committed Oct 16, 2015
1 parent 677410c commit 9c230af
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
13 changes: 7 additions & 6 deletions fedimg/services/ec2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file is part of fedimg.
# Copyright (C) 2014 Red Hat, Inc.
# Copyright (C) 2014-2015 Red Hat, Inc.
#
# fedimg is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
Expand All @@ -17,6 +17,7 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# Authors: David Gay <dgay@redhat.com>
# Ralph Bean <rbean@redhat.com>
#

import logging
Expand All @@ -35,7 +36,7 @@
import fedimg
import fedimg.messenger
from fedimg.util import get_file_arch
from fedimg.util import region_to_provider, ssh_connection_works
from fedimg.util import region_to_driver, ssh_connection_works


class EC2ServiceException(Exception):
Expand Down Expand Up @@ -94,7 +95,7 @@ def __init__(self, raw_url, virt_type='hvm', vol_type='standard'):
attrs = line.strip().split('|')

info = {'region': attrs[0],
'prov': region_to_provider(attrs[0]),
'driver': region_to_driver(attrs[0]),
'os': attrs[1],
'ver': attrs[2],
'arch': attrs[3],
Expand Down Expand Up @@ -163,7 +164,7 @@ def upload(self):

try:
# Connect to the region through the appropriate libcloud driver
cls = get_driver(ami['prov'])
cls = ami['driver']
driver = cls(fedimg.AWS_ACCESS_ID, fedimg.AWS_SECRET_KEY)

# select the desired node attributes
Expand Down Expand Up @@ -578,7 +579,7 @@ def upload(self):

# Connect to the libcloud EC2 driver for the region we
# want to copy into
alt_cls = get_driver(ami['prov'])
alt_cls = ami['driver']
alt_driver = alt_cls(fedimg.AWS_ACCESS_ID,
fedimg.AWS_SECRET_KEY)

Expand Down Expand Up @@ -648,7 +649,7 @@ def upload(self):

for image in copied_images:
ami = self.test_amis[copied_images.index(image)]
alt_cls = get_driver(ami['prov'])
alt_cls = ami['driver']
alt_driver = alt_cls(fedimg.AWS_ACCESS_ID,
fedimg.AWS_SECRET_KEY)

Expand Down
16 changes: 6 additions & 10 deletions fedimg/util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file is part of fedimg.
# Copyright (C) 2014 Red Hat, Inc.
# Copyright (C) 2014-2015 Red Hat, Inc.
#
# fedimg is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
Expand All @@ -17,17 +17,20 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# Authors: David Gay <dgay@redhat.com>
# Ralph Bean <rbean@redhat.com>
#

"""
Utility functions for fedimg.
"""

import functools
import socket
import subprocess

import paramiko
from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

import fedimg

Expand Down Expand Up @@ -77,15 +80,8 @@ def virt_types_from_url(url):
def region_to_provider(region):
""" Takes a region name (ex. 'eu-west-1') and returns
the appropriate libcloud provider value. """
providers = {'ap-northeast-1': Provider.EC2_AP_NORTHEAST,
'ap-southeast-1': Provider.EC2_AP_SOUTHEAST,
'ap-southeast-2': Provider.EC2_AP_SOUTHEAST2,
'eu-west-1': Provider.EC2_EU_WEST,
'sa-east-1': Provider.EC2_SA_EAST,
'us-east-1': Provider.EC2_US_EAST,
'us-west-1': Provider.EC2_US_WEST,
'us-west-2': Provider.EC2_US_WEST_OREGON}
return providers[region]
cls = get_driver(Provider.EC2)
return functools.partial(cls, region=region)


def ssh_connection_works(username, ip, keypath):
Expand Down

0 comments on commit 9c230af

Please sign in to comment.