Class: PuppetX::Practicalclouds::Awsaccess
- Inherits:
-
Object
- Object
- PuppetX::Practicalclouds::Awsaccess
- Defined in:
- lib/puppet_x/practicalclouds/connection.rb
Constant Summary collapse
- @@credentials =
{}
- @@connections =
{}
Class Method Summary collapse
-
.connect(reg, name) ⇒ Object
Connect to an AWS region using a specific credential.
-
.regions(name) ⇒ Object
return a list of regions from an aws credential.
Class Method Details
.connect(reg, name) ⇒ Object
Connect to an AWS region using a specific credential
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/puppet_x/practicalclouds/connection.rb', line 26 def self.connect(reg,name) # return an existing connection... if (@@connections[reg]) if (@@connections[reg][name]) return @@connections[reg][name] end end # make sure we have the credentials loaded and make a new connection if (@@credentials == {}) @@credentials = PuppetX::Practicalclouds::Storable::load('awsaccess') end if (@@credentials[name]) if (@@credentials[name][:regions] && !@@credentials[name][:regions].member?(reg)) raise "Sorry, Awsaccess '#{name}' is not allowed in region '#{reg}'" elsif (!@@credentials[name][:aws_access_key_id] || !@@credentials[name][:aws_secret_access_key]) raise "Sorry, You must have both an aws_access_key_id and aws_secret_access_key in your awsaccess object" else # open the connection to AWS @@connections[reg] = {} if (!@@connections[reg]) @@connections[reg][name] = Fog::Compute.new(:provider => 'aws', :aws_access_key_id => @@credentials[name][:aws_access_key_id], :aws_secret_access_key => @@credentials[name][:aws_secret_access_key], :region => reg) raise "Sorry, I could not create a connection to '#{region}' with awsaccess object '#{name}'" if (!@@connections[reg][name]) return @@connections[reg][name] end else raise "Sorry, awsaccess object '#{name}' does not exist!" end end |
.regions(name) ⇒ Object
return a list of regions from an aws credential
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/puppet_x/practicalclouds/connection.rb', line 14 def self.regions(name) if (@@credentials == {}) @@credentials = PuppetX::Practicalclouds::Storable::load('awsaccess') end if (@@credentials[name]) return (@@credentials[name][:regions]) ? @@credentials[name][:regions] : [] else raise "Sorry, awsaccess credential '#{name}' does not exist!" end end |