Skip to content

Commit 3f39f6f

Browse files
authoredOct 5, 2018
Merge pull request #336 from mshriver/update-boto-imports
[RFR] Narrow boto/boto3 imports for EC2 module
2 parents d8e8d17 + 8bd76ce commit 3f39f6f

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed
 

‎requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ dateparser
88
enum34; python_version == '2.7'
99
fauxfactory>=2.0.7
1010
google-api-python-client
11+
google-compute-engine
1112
inflection
1213
miq-version>=0.1.6
1314
oauth2client

‎wrapanapi/systems/ec2.py

+15-12
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@
55
import re
66
from datetime import datetime
77

8-
import boto
9-
from boto import sqs
8+
import pytz
9+
from boto import sqs, UserAgent
10+
from boto.sqs import connection as _sqs_connection # can't reference connection from sqs module
1011
from boto.ec2 import EC2Connection, elb, get_region
1112
from boto.ec2.elb import ELBConnection
12-
from boto.sqs import connection
13-
import boto3
13+
from boto.exception import BotoServerError
1414
from botocore.config import Config
1515
from botocore.exceptions import ClientError
16-
import pytz
16+
from boto3 import (
17+
resource as boto3resource,
18+
client as boto3client
19+
)
1720

1821
from wrapanapi.entities import (Instance, Stack, StackMixin, Template,
1922
TemplateMixin, VmMixin, VmState)
@@ -253,7 +256,7 @@ def refresh(self):
253256
"""
254257
try:
255258
self.raw = self._api.describe_stacks(StackName=self._uuid)['Stacks'][0]
256-
except boto.exception.BotoServerError as error:
259+
except BotoServerError as error:
257260
if error.status == 404:
258261
raise NotFoundError('stack {}'.format(self._uuid))
259262
else:
@@ -385,7 +388,7 @@ def __init__(self, **kwargs):
385388
self._region = get_region(self._region_name)
386389
self.api = EC2Connection(self._username, self._password, region=self._region)
387390

388-
self.sqs_connection = connection.SQSConnection(
391+
self.sqs_connection = _sqs_connection.SQSConnection(
389392
self._username, self._password, region=_regions(
390393
regionmodule=sqs, regionname=self._region_name)
391394
)
@@ -395,23 +398,23 @@ def __init__(self, **kwargs):
395398
regionmodule=elb, regionname=self._region_name)
396399
)
397400

398-
self.s3_connection = boto3.resource(
401+
self.s3_connection = boto3resource(
399402
's3', aws_access_key_id=self._username, aws_secret_access_key=self._password,
400403
region_name=self._region_name, config=connection_config
401404
)
402405

403-
self.ec2_connection = boto3.client(
406+
self.ec2_connection = boto3client(
404407
'ec2', aws_access_key_id=self._username, aws_secret_access_key=self._password,
405408
region_name=self._region_name, config=connection_config
406409
)
407410

408-
self.cloudformation_connection = boto3.client(
411+
self.cloudformation_connection = boto3client(
409412
'cloudformation', aws_access_key_id=self._username,
410413
aws_secret_access_key=self._password, region_name=self._region_name,
411414
config=connection_config
412415
)
413416

414-
self.sns_connection = boto3.client('sns', region_name=self._region_name)
417+
self.sns_connection = boto3client('sns', region_name=self._region_name)
415418

416419
self.kwargs = kwargs
417420

@@ -438,7 +441,7 @@ def disconnect(self):
438441

439442
def info(self):
440443
"""Returns the current versions of boto and the EC2 API being used"""
441-
return '%s %s' % (boto.UserAgent, self.api.APIVersion)
444+
return '%s %s' % (UserAgent, self.api.APIVersion)
442445

443446
def _get_instances(self, **kwargs):
444447
"""

0 commit comments

Comments
 (0)
Please sign in to comment.