~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/devscripts/ec2test/credentials.py

  • Committer: Julian Edwards
  • Date: 2011-07-28 20:46:18 UTC
  • mfrom: (13553 devel)
  • mto: This revision was merged to the branch mainline in revision 13555.
  • Revision ID: julian.edwards@canonical.com-20110728204618-tivj2wx2oa9s32bx
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
import os
13
13
 
14
14
import boto
15
 
import boto.ec2
16
15
from bzrlib.errors import BzrCommandError
17
 
from devscripts.ec2test import instance
18
16
from devscripts.ec2test.account import EC2Account
19
17
 
20
18
 
23
21
 
24
22
    _fmt = (
25
23
        "Please put your aws access key identifier and secret access "
26
 
        "key identifier in %(filename)s. (On two lines).  %(extra)s")
 
24
        "key identifier in %(filename)s. (On two lines).  %(extra)s" )
27
25
 
28
26
    def __init__(self, filename, extra=None):
29
27
        super(CredentialsError, self).__init__(filename=filename, extra=extra)
34
32
 
35
33
    DEFAULT_CREDENTIALS_FILE = '~/.ec2/aws_id'
36
34
 
37
 
    def __init__(self, identifier, secret, region_name):
 
35
    def __init__(self, identifier, secret):
38
36
        self.identifier = identifier
39
37
        self.secret = secret
40
 
        self.region_name = region_name or instance.DEFAULT_REGION
41
38
 
42
39
    @classmethod
43
 
    def load_from_file(cls, filename=None, region_name=None):
 
40
    def load_from_file(cls, filename=None):
44
41
        """Load the EC2 credentials from 'filename'."""
45
42
        if filename is None:
46
43
            filename = os.path.expanduser(cls.DEFAULT_CREDENTIALS_FILE)
53
50
            secret = aws_file.readline().strip()
54
51
        finally:
55
52
            aws_file.close()
56
 
        return cls(identifier, secret, region_name)
 
53
        return cls(identifier, secret)
57
54
 
58
55
    def connect(self, name):
59
56
        """Connect to EC2 with these credentials.
60
57
 
61
 
        :param name: Arbitrary local name for the object.
 
58
        :param name: ???
62
59
        :return: An `EC2Account` connected to EC2 with these credentials.
63
60
        """
64
 
        conn = boto.ec2.connect_to_region(
65
 
            self.region_name,
66
 
            aws_access_key_id=self.identifier,
67
 
            aws_secret_access_key=self.secret)
 
61
        conn = boto.connect_ec2(self.identifier, self.secret)
68
62
        return EC2Account(name, conn)
69
63
 
70
64
    def connect_s3(self):