miasma-rackspace 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e13195283606784eb289f722ea0382af4fa5df65
4
+ data.tar.gz: 7e1de23024e56effc4e8ec5d1c02d229a6a03ccc
5
+ SHA512:
6
+ metadata.gz: 499abdcaa9e864dfd5a91dcb83a488a6e9b2ec565c422ff70bacca19665806f76cd507af33766d6267a6c6c115d2f8f75161a49f574d2604e77da810494bd987
7
+ data.tar.gz: 64eecfc7e0a26c1a3339f53d2119e4254bffd17f3fca9470dbc289fea8f212e427ea10333150a2b48d12bd95ac844f65c7a4e2304571f40edec297d3500a9ce1
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ ## v0.1.0
2
+ * Initial release
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2014 Chris Roberts
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # Miasma Rackspace
2
+
3
+ Rackspace API plugin for the miasma cloud library
4
+
5
+ ## Current support matrix
6
+
7
+ |Model |Create|Read|Update|Delete|
8
+ |--------------|------|----|------|------|
9
+ |AutoScale | X | X | | |
10
+ |BlockStorage | | | | |
11
+ |Compute | X | X | | X |
12
+ |DNS | | | | |
13
+ |LoadBalancer | | X | | |
14
+ |Network | | | | |
15
+ |Orchestration | X | X | X | X |
16
+ |Queues | | | | |
17
+ |Storage | | | | |
18
+
19
+ ## Info
20
+ * Repository: https://github.com/miasma-rb/miasma-rackspace
@@ -0,0 +1,85 @@
1
+ require 'miasma'
2
+
3
+ module Miasma
4
+ module Models
5
+ class AutoScale
6
+ class Rackspace < AutoScale
7
+
8
+ include Contrib::OpenStackApiCore::ApiCommon
9
+ include Contrib::RackspaceApiCore::ApiCommon
10
+
11
+ # Save auto scale group
12
+ #
13
+ # @param group [Models::AutoScale::Group]
14
+ # @return [Models::AutoScale::Group]
15
+ def group_save(group)
16
+ raise NotImplementedError
17
+ end
18
+
19
+ # Reload the group data from the API
20
+ #
21
+ # @param group [Models::AutoScale::Group]
22
+ # @return [Models::AutoScale::Group]
23
+ def group_reload(group)
24
+ if(group.persisted?)
25
+ result = request(
26
+ :method => :get,
27
+ :path => "/groups/#{group.id}",
28
+ :expects => 200
29
+ )
30
+ grp = result.get(:body, :group)
31
+ group.load_data(
32
+ :name => grp.get('groupConfiguration', :name),
33
+ :minimum_size => grp.get('groupConfiguration', 'minEntities'),
34
+ :maximum_size => grp.get('groupConfiguration', 'maxEntities'),
35
+ :desired_size => grp.get(:state, 'desiredCapacity'),
36
+ :current_size => grp.get(:state, 'activeCapacity'),
37
+ :servers => grp.get(:state, :active).map{|s| AutoScale::Group::Server.new(self, :id => s[:id])}
38
+ ).valid_state
39
+ else
40
+ group
41
+ end
42
+ end
43
+
44
+ # Delete auto scale group
45
+ #
46
+ # @param group [Models::AutoScale::Group]
47
+ # @return [TrueClass, FalseClass]
48
+ def group_destroy(group)
49
+ if(group.persisted?)
50
+ request(
51
+ :path => "/groups/#{group.id}",
52
+ :method => :delete,
53
+ :expects => 204
54
+ )
55
+ true
56
+ else
57
+ false
58
+ end
59
+ end
60
+
61
+ # Return all auto scale groups
62
+ #
63
+ # @param options [Hash] filter
64
+ # @return [Array<Models::AutoScale::Group>]
65
+ def group_all(options={})
66
+ result = request(
67
+ :method => :get,
68
+ :path => '/groups',
69
+ :expects => 200
70
+ )
71
+ result.fetch(:body, 'groups', []).map do |lb|
72
+ Group.new(
73
+ self,
74
+ :id => lb[:id],
75
+ :name => lb.get(:state, :name),
76
+ :current_size => lb.get(:state, 'activeCapacity'),
77
+ :desired_size => lb.get(:state, 'desiredCapacity')
78
+ ).valid_state
79
+ end
80
+ end
81
+
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,13 @@
1
+ require 'miasma'
2
+
3
+ module Miasma
4
+ module Models
5
+ class Compute
6
+ class Rackspace < OpenStack
7
+
8
+ include Contrib::RackspaceApiCore::ApiCommon
9
+
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,118 @@
1
+ require 'miasma'
2
+
3
+ module Miasma
4
+ module Models
5
+ class LoadBalancer
6
+ class Rackspace < LoadBalancer
7
+
8
+ include Contrib::OpenStackApiCore::ApiCommon
9
+ include Contrib::RackspaceApiCore::ApiCommon
10
+
11
+ # Save load balancer
12
+ #
13
+ # @param balancer [Models::LoadBalancer::Balancer]
14
+ # @return [Models::LoadBalancer::Balancer]
15
+ def balancer_save(balancer)
16
+ raise NotImplementedError
17
+ end
18
+
19
+ # Reload the balancer data from the API
20
+ #
21
+ # @param balancer [Models::LoadBalancer::Balancer]
22
+ # @return [Models::LoadBalancer::Balancer]
23
+ def balancer_reload(balancer)
24
+ if(balancer.persisted?)
25
+ result = request(
26
+ :path => "/loadbalancers/#{balancer.id}",
27
+ :method => :get,
28
+ :expects => 200
29
+ )
30
+ lb = result.get(:body, 'loadBalancer')
31
+ balancer.load_data(
32
+ :name => lb[:name],
33
+ :name => lb[:name],
34
+ :state => lb[:status] == 'ACTIVE' ? :active : :pending,
35
+ :status => lb[:status],
36
+ :created => lb.get(:created, :time),
37
+ :updated => lb.get(:updated, :time),
38
+ :public_addresses => lb['virtualIps'].map{|addr|
39
+ if(addr[:type] == 'PUBLIC')
40
+ Balancer::Address.new(
41
+ :address => addr[:address],
42
+ :version => addr['ipVersion'].sub('IPV', '').to_i
43
+ )
44
+ end
45
+ }.compact,
46
+ :private_addresses => lb['virtualIps'].map{|addr|
47
+ if(addr[:type] != 'PUBLIC')
48
+ Balancer::Address.new(
49
+ :address => addr[:address],
50
+ :version => addr['ipVersion'].sub('IPV', '').to_i
51
+ )
52
+ end
53
+ }.compact,
54
+ :servers => lb.fetch('nodes', []).map{|s|
55
+ srv = self.api_for(:compute).servers.all.detect do |csrv|
56
+ csrv.addresses.map(&:address).include?(s[:address])
57
+ end
58
+ if(srv)
59
+ Balancer::Server.new(self.api_for(:compute), :id => srv.id)
60
+ end
61
+ }.compact
62
+ ).valid_state
63
+ else
64
+ balancer
65
+ end
66
+ end
67
+
68
+ # Delete load balancer
69
+ #
70
+ # @param balancer [Models::LoadBalancer::Balancer]
71
+ # @return [TrueClass, FalseClass]
72
+ def balancer_destroy(balancer)
73
+ raise NotImplementedError
74
+ end
75
+
76
+ # Return all load balancers
77
+ #
78
+ # @param options [Hash] filter
79
+ # @return [Array<Models::LoadBalancer::Balancer>]
80
+ def balancer_all(options={})
81
+ result = request(
82
+ :path => '/loadbalancers',
83
+ :method => :get,
84
+ :expects => 200
85
+ )
86
+ result.fetch(:body, 'loadBalancers', []).map do |lb|
87
+ Balancer.new(
88
+ self,
89
+ :id => lb[:id],
90
+ :name => lb[:name],
91
+ :state => lb[:status] == 'ACTIVE' ? :active : :pending,
92
+ :status => lb[:status],
93
+ :created => lb.get(:created, :time),
94
+ :updated => lb.get(:updated, :time),
95
+ :public_addresses => lb['virtualIps'].map{|addr|
96
+ if(addr[:type] == 'PUBLIC')
97
+ Balancer::Address.new(
98
+ :address => addr[:address],
99
+ :version => addr['ipVersion'].sub('IPV', '').to_i
100
+ )
101
+ end
102
+ }.compact,
103
+ :private_addresses => lb['virtualIps'].map{|addr|
104
+ if(addr[:type] != 'PUBLIC')
105
+ Balancer::Address.new(
106
+ :address => addr[:address],
107
+ :version => addr['ipVersion'].sub('IPV', '').to_i
108
+ )
109
+ end
110
+ }.compact
111
+ ).valid_state
112
+ end
113
+ end
114
+
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,25 @@
1
+ require 'miasma'
2
+
3
+ module Miasma
4
+ module Models
5
+ class Orchestration
6
+ class Rackspace < OpenStack
7
+
8
+ include Contrib::RackspaceApiCore::ApiCommon
9
+
10
+ # @return [Smash] external to internal resource mapping
11
+ RESOURCE_MAPPING = Smash.new(
12
+ 'Rackspace::Cloud::Server' => Smash.new(
13
+ :api => :compute,
14
+ :collection => :servers
15
+ ),
16
+ 'Rackspace::AutoScale::Group' => Smash.new(
17
+ :api => :auto_scale,
18
+ :collection => :groups
19
+ )
20
+ )
21
+
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,112 @@
1
+ require 'miasma'
2
+ require 'miasma/contrib/open_stack'
3
+
4
+ module Miasma
5
+ module Contrib
6
+
7
+ # Rackspace API core helper
8
+ class RackspaceApiCore < OpenStackApiCore
9
+
10
+ # Authentication helper class
11
+ class Authenticate < OpenStackApiCore::Authenticate
12
+ # Authentication implementation compatible for v2
13
+ class Version2 < OpenStackApiCore::Authenticate::Version2
14
+
15
+ # @return [Smash] authentication request body
16
+ def authentication_request
17
+ Smash.new(
18
+ 'RAX-KSKEY:apiKeyCredentials' => Smash.new(
19
+ 'username' => credentials[:open_stack_username],
20
+ 'apiKey' => credentials[:open_stack_token]
21
+ )
22
+ )
23
+ end
24
+
25
+ end
26
+ end
27
+
28
+ # Common API methods
29
+ module ApiCommon
30
+
31
+ # Set attributes into model
32
+ #
33
+ # @param klass [Class]
34
+ def self.included(klass)
35
+ klass.attributes.clear
36
+
37
+ klass.class_eval do
38
+ attribute :rackspace_api_key, String, :required => true
39
+ attribute :rackspace_username, String, :required => true
40
+ attribute :rackspace_region, String, :required => true
41
+
42
+ # @return [Miasma::Contrib::RackspaceApiCore]
43
+ def open_stack_api
44
+ key = "miasma_rackspace_api_#{attributes.checksum}".to_sym
45
+ memoize(key, :direct) do
46
+ Miasma::Contrib::RackspaceApiCore.new(attributes)
47
+ end
48
+ end
49
+
50
+ # @return [String]
51
+ def open_stack_region
52
+ rackspace_region
53
+ end
54
+
55
+ end
56
+ end
57
+
58
+
59
+ end
60
+
61
+ # @return [Smash] Authentication endpoints
62
+ AUTH_ENDPOINT = Smash.new(
63
+ :us => 'https://identity.api.rackspacecloud.com/v2.0',
64
+ :uk => 'https://lon.identity.api.rackspacecloud.com/v2.0'
65
+ )
66
+
67
+ # @return [Smash] Mapping to external service name
68
+ # @note ["cloudFilesCDN", "cloudFiles", "cloudBlockStorage",
69
+ # "cloudImages", "cloudQueues", "cloudBigData",
70
+ # "cloudOrchestration", "cloudServersOpenStack", "autoscale",
71
+ # "cloudDatabases", "cloudBackup", "cloudMetrics",
72
+ # "cloudLoadBalancers", "cloudNetworks", "cloudFeeds",
73
+ # "cloudMonitoring", "cloudDNS"]
74
+
75
+ API_MAP = Smash.new(
76
+ 'compute' => 'cloudServersOpenStack',
77
+ 'orchestration' => 'cloudOrchestration',
78
+ 'auto_scale' => 'autoscale',
79
+ 'load_balancer' => 'cloudLoadBalancers'
80
+ )
81
+
82
+ # Create a new api instance
83
+ #
84
+ # @param creds [Smash] credential hash
85
+ # @return [self]
86
+ def initialize(creds)
87
+ if(creds[:rackspace_region].to_s == 'lon')
88
+ endpoint = AUTH_ENDPOINT[:uk]
89
+ else
90
+ endpoint = AUTH_ENDPOINT[:us]
91
+ end
92
+ super Smash.new(
93
+ :open_stack_username => creds[:rackspace_username],
94
+ :open_stack_token => creds[:rackspace_api_key],
95
+ :open_stack_region => creds[:rackspace_region],
96
+ :open_stack_identity_url => endpoint
97
+ )
98
+ end
99
+
100
+ # @return [String] ID of account
101
+ def account_id
102
+ identity.token[:tenant][:id]
103
+ end
104
+
105
+ end
106
+ end
107
+
108
+ Models::Compute.autoload :Rackspace, 'miasma/contrib/rackspace/compute'
109
+ Models::Orchestration.autoload :Rackspace, 'miasma/contrib/rackspace/orchestration'
110
+ Models::AutoScale.autoload :Rackspace, 'miasma/contrib/rackspace/auto_scale'
111
+ Models::LoadBalancer.autoload :Rackspace, 'miasma/contrib/rackspace/load_balancer'
112
+ end
@@ -0,0 +1,4 @@
1
+ module MiasmaRackspace
2
+ # Current library version
3
+ VERSION = Gem::Version.new('0.1.0')
4
+ end
@@ -0,0 +1,2 @@
1
+ require 'miasma'
2
+ require 'miasma-rackspace/version'
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__)) + '/lib/'
2
+ require 'miasma-rackspace/version'
3
+ Gem::Specification.new do |s|
4
+ s.name = 'miasma-rackspace'
5
+ s.version = MiasmaRackspace::VERSION.version
6
+ s.summary = 'Smoggy Rackspace API'
7
+ s.author = 'Chris Roberts'
8
+ s.email = 'code@chrisroberts.org'
9
+ s.homepage = 'https://github.com/miasma-rb/miasma-rackspace'
10
+ s.description = 'Smoggy Rackspace API'
11
+ s.license = 'Apache 2.0'
12
+ s.require_path = 'lib'
13
+ s.add_dependency 'miasma'
14
+ s.add_dependency 'miasma-open-stack'
15
+ s.files = Dir['lib/**/*'] + %w(miasma-rackspace.gemspec README.md CHANGELOG.md LICENSE)
16
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: miasma-rackspace
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Roberts
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: miasma
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: miasma-open-stack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Smoggy Rackspace API
42
+ email: code@chrisroberts.org
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - CHANGELOG.md
48
+ - LICENSE
49
+ - README.md
50
+ - lib/miasma-rackspace.rb
51
+ - lib/miasma-rackspace/version.rb
52
+ - lib/miasma/contrib/rackspace.rb
53
+ - lib/miasma/contrib/rackspace/auto_scale.rb
54
+ - lib/miasma/contrib/rackspace/compute.rb
55
+ - lib/miasma/contrib/rackspace/load_balancer.rb
56
+ - lib/miasma/contrib/rackspace/orchestration.rb
57
+ - miasma-rackspace.gemspec
58
+ homepage: https://github.com/miasma-rb/miasma-rackspace
59
+ licenses:
60
+ - Apache 2.0
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.2.2
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Smoggy Rackspace API
82
+ test_files: []
83
+ has_rdoc: