cyoi 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZDFmMTk5ZDdlZDU4NWRiNDk0YmMyODRhZTI2ODhkMmViOWNjMWI5MA==
5
+ data.tar.gz: !binary |-
6
+ MjA0ODI5M2QxOWQ3ZjI0MjI0ZmQzMzljYjA3NTUxYmU4MDcyYzM3YQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZWRmZTE2NGRhN2VjNzJhOWJhYWU1NDQ5YWVjNmIzMDE0MDIzNDg5Y2M1ODQw
10
+ NzMzYzg2Y2Q1ZWI0ZTE3NmZjNDFmNTE5ZjExMDZlOWQzZjU1YjhmZDljYWE0
11
+ YWY4MWIxOWQ4ZTUyZTU0MzBmZTZiMmNkYTJiOGI4NDNjNjM0YzE=
12
+ data.tar.gz: !binary |-
13
+ MjY2YjFjOTM1MDE2YzEwNDgwNTIwMDE3MmJjZTkzNDVjNzhmMWI5MDQ4MDVl
14
+ ODRlYWYzNzQwMjJjNjRkOGU2NTAxZDZhZTEyM2U4Mzk4NTYxYjFmZGI3MThh
15
+ MmE1YWI4OWE0NzkxNTJlYzM4MDQ2MTNlMWE1ODk2NzljYTM3NWM=
@@ -2,6 +2,10 @@
2
2
 
3
3
  Cyoi (choose-your-own-infrastructure) is a library to ask an end-user to choose an infrastructure (AWS, OpenStack, etc), region, and login credentials.
4
4
 
5
+ ## v0.5
6
+
7
+ * OpenStack implementation completed by Ferdy!
8
+
5
9
  ## v0.4
6
10
 
7
11
  * switch to using readwritesettings instead of fork of settingslogic
@@ -0,0 +1,44 @@
1
+ module Cyoi::Cli::Addresses; end
2
+ class Cyoi::Cli::Addresses::AddressCliOpenstack
3
+ attr_reader :provider_client
4
+ attr_reader :attributes
5
+ attr_reader :hl
6
+
7
+ def initialize(provider_client, attributes, highline)
8
+ @provider_client = provider_client
9
+ @hl = highline
10
+ @attributes = attributes.is_a?(Hash) ? ReadWriteSettings.new(attributes) : attributes
11
+ raise "@attributes must be ReadWriteSettings (or Hash)" unless @attributes.is_a?(ReadWriteSettings)
12
+ end
13
+
14
+ def perform_and_return_attributes
15
+ unless valid_address?
16
+ provision_address
17
+ end
18
+ export_attributes
19
+ end
20
+
21
+ # helper to export the complete nested attributes.
22
+ def export_attributes
23
+ attributes.to_nested_hash
24
+ end
25
+
26
+
27
+ def valid_address?
28
+ attributes["ip"]
29
+ end
30
+
31
+ def display_confirmation
32
+ puts "\n"
33
+ puts "Confirming: Using address #{attributes.ip}"
34
+ end
35
+
36
+ protected
37
+ def provision_address
38
+ print "Acquiring a public IP address... "
39
+ attributes["ip"] = provider_client.provision_public_ip_address
40
+ puts attributes.ip
41
+ end
42
+ end
43
+
44
+ Cyoi::Cli::Address.register_address_cli("openstack", Cyoi::Cli::Addresses::AddressCliOpenstack)
@@ -0,0 +1,58 @@
1
+ class Cyoi::Cli::KeyPair; end
2
+ class Cyoi::Cli::KeyPair::KeyPairCliOpenstack
3
+ attr_reader :provider_client
4
+ attr_reader :attributes
5
+ attr_reader :hl
6
+
7
+ def initialize(provider_client, attributes, highline)
8
+ @provider_client = provider_client
9
+ @hl = highline
10
+ @attributes = attributes.is_a?(Hash) ? ReadWriteSettings.new(attributes) : attributes
11
+ raise "@attributes must be ReadWriteSettings (or Hash)" unless @attributes.is_a?(ReadWriteSettings)
12
+ raise "@attributes.name must be set" unless @attributes["name"]
13
+ end
14
+
15
+ def perform_and_return_attributes
16
+ unless valid?
17
+ destroy_existing_key_pair
18
+ provision_key_pair
19
+ end
20
+ export_attributes
21
+ end
22
+
23
+ # helper to export the complete nested attributes.
24
+ def export_attributes
25
+ attributes.to_nested_hash
26
+ end
27
+
28
+ def valid?
29
+ attributes["name"] && attributes["fingerprint"] && attributes["private_key"] &&
30
+ provider_client.valid_key_pair_fingerprint?(key_pair_name, attributes.fingerprint)
31
+ end
32
+
33
+ def display_confirmation
34
+ puts "\n"
35
+ puts "Confirming: Using key pair #{key_pair_name}"
36
+ end
37
+
38
+ def key_pair_name
39
+ attributes.name
40
+ end
41
+
42
+ protected
43
+ def destroy_existing_key_pair
44
+ provider_client.delete_key_pair_if_exists(key_pair_name)
45
+ end
46
+
47
+ # provisions key pair from OpenStack and returns fog object KeyPair
48
+ def provision_key_pair
49
+ print "Acquiring a key pair #{key_pair_name}... "
50
+ if key_pair = provider_client.create_key_pair(key_pair_name)
51
+ attributes["fingerprint"] = key_pair.fingerprint
52
+ attributes["private_key"] = key_pair.private_key
53
+ puts "done"
54
+ end
55
+ end
56
+ end
57
+
58
+ Cyoi::Cli::KeyPair.register_key_pair_cli("openstack", Cyoi::Cli::KeyPair::KeyPairCliOpenstack)
@@ -4,7 +4,6 @@ class Cyoi::Cli::Providers::ProviderCliOpenStack < Cyoi::Cli::Providers::Provide
4
4
  unless valid_infrastructure?
5
5
  puts "\nUsing provider OpenStack\n"
6
6
  setup_credentials
7
- choose_region
8
7
  end
9
8
  export_attributes
10
9
  end
@@ -17,11 +16,8 @@ class Cyoi::Cli::Providers::ProviderCliOpenStack < Cyoi::Cli::Providers::Provide
17
16
  credentials["openstack_api_key"] = hl.ask("Password: ").to_s unless credentials.exists?("openstack_api_key")
18
17
  credentials["openstack_tenant"] = hl.ask("Tenant: ").to_s unless credentials.exists?("openstack_tenant")
19
18
  credentials["openstack_auth_url"] = hl.ask("Authorization Token URL: ").to_s unless credentials.exists?("openstack_auth_url")
20
- end
21
-
22
- def choose_region
23
- puts "\n"
24
- attributes["region"] = hl.ask("OpenStack Region (optional): ").to_s
19
+ credentials["openstack_auth_url"] = credentials["openstack_auth_url"] + "/tokens" unless credentials["openstack_auth_url"].match(/\/tokens$/)
20
+ credentials["openstack_region"] = hl.ask("OpenStack Region (optional): ").to_s unless credentials.exists?("openstack_region")
25
21
  end
26
22
 
27
23
  def valid_infrastructure?
@@ -34,11 +30,7 @@ class Cyoi::Cli::Providers::ProviderCliOpenStack < Cyoi::Cli::Providers::Provide
34
30
 
35
31
  def display_confirmation
36
32
  puts "\n"
37
- if attributes.region.size > 0
38
- puts "Confirming: Using OpenStack/#{attributes.region}"
39
- else
40
- puts "Confirming: Using OpenStack"
41
- end
33
+ puts "Confirming: Using OpenStack"
42
34
  end
43
35
  end
44
36
 
@@ -9,7 +9,8 @@ class Cyoi::Providers::Clients::OpenStackProviderClient < Cyoi::Providers::Clien
9
9
  # @return [String] provisions a new public IP address in target region
10
10
  # TODO nil if none available
11
11
  def provision_public_ip_address(options={})
12
- address = fog_compute.addresses.create
12
+ pool = fog_compute.addresses.get_address_pools.first
13
+ address = fog_compute.addresses.create(:pool => pool["name"])
13
14
  address.ip
14
15
  # TODO catch error and return nil
15
16
  end
@@ -24,6 +25,16 @@ class Cyoi::Providers::Clients::OpenStackProviderClient < Cyoi::Providers::Clien
24
25
  sg.rules
25
26
  end
26
27
 
28
+ # Hook method for FogProviderClient#create_security_group
29
+ def port_open?(ip_permissions, port_range, protocol, ip_range)
30
+ ip_permissions && ip_permissions.find do |ip|
31
+ ip["ip_protocol"] == protocol \
32
+ && ip["ip_range"].select { |range| range["cidr"] == ip_range } \
33
+ && ip["from_port"] <= port_range.min \
34
+ && ip["to_port"] >= port_range.max
35
+ end
36
+ end
37
+
27
38
  # Hook method for FogProviderClient#create_security_group
28
39
  def authorize_port_range(sg, port_range, protocol, ip_range)
29
40
  sg.create_security_group_rule(port_range.min, port_range.max, protocol, ip_range)
@@ -53,8 +64,8 @@ class Cyoi::Providers::Clients::OpenStackProviderClient < Cyoi::Providers::Clien
53
64
  def setup_fog_connection
54
65
  configuration = Fog.symbolize_credentials(attributes.credentials)
55
66
  configuration[:provider] = "OpenStack"
56
- unless attributes.region == openstack_constants.no_region_code
57
- configuration[:openstack_region] = attributes.region
67
+ if attributes.credentials.openstack_region && attributes.credentials.openstack_region.empty?
68
+ configuration.delete(:openstack_region)
58
69
  end
59
70
  @fog_compute = Fog::Compute.new(configuration)
60
71
  end
@@ -5,8 +5,4 @@ module Cyoi; module Providers; module Constants; end; end; end
5
5
  module Cyoi::Providers::Constants::OpenStackConstants
6
6
  extend self
7
7
 
8
- # explicit value representing "no region requested"
9
- def no_region_code
10
- "no-region-requested"
11
- end
12
8
  end
@@ -1,3 +1,3 @@
1
1
  module Cyoi
2
- VERSION = "0.4.2"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -0,0 +1,42 @@
1
+ describe "cyoi address openstack" do
2
+ include Cyoi::Cli::Helpers::Settings
3
+ include SettingsHelper
4
+ include Aruba::Api
5
+ before { @settings_dir = File.expand_path("~/.cyoi_client_lib") }
6
+
7
+ it "fails nicely if provider.name missing" do
8
+ run_interactive(unescape("cyoi address #{settings_dir}"))
9
+ assert_failing_with("Please run 'cyoi provider' first")
10
+ end
11
+
12
+ describe "provider setup and" do
13
+ before do
14
+ setting "provider.name", "openstack"
15
+ setting "provider.credentials.openstack_username", "USERNAME"
16
+ setting "provider.credentials.openstack_api_key", "PASSWORD"
17
+ setting "provider.credentials.openstack_tenant", "TENANT"
18
+ setting "provider.credentials.openstack_auth_url", "TOKENURL"
19
+ setting "provider.credentials.openstack_region", "REGION"
20
+ end
21
+
22
+ it "address aleady assigned" do
23
+ pending("Fog::Compute::OpenStack.list_address_pools does not provide a mock test")
24
+ setting "provider.name", "openstack"
25
+ setting "provider.credentials.openstack_username", "USERNAME"
26
+ setting "provider.credentials.openstack_api_key", "PASSWORD"
27
+ setting "provider.credentials.openstack_tenant", "TENANT"
28
+ setting "provider.credentials.openstack_auth_url", "TOKENURL"
29
+ setting "provider.credentials.openstack_region", "REGION"
30
+ setting "address.ip", "1.2.3.4"
31
+ run_interactive(unescape("cyoi address #{settings_dir}"))
32
+ assert_passing_with("Confirming: Using address 1.2.3.4")
33
+ end
34
+
35
+ it "address is provisioned from OpenStack" do
36
+ pending("Fog::Compute::OpenStack.list_address_pools does not provide a mock test")
37
+ run_interactive(unescape("cyoi address #{settings_dir}"))
38
+ assert_passing_with("Confirming: Using address")
39
+ end
40
+ end
41
+
42
+ end
@@ -0,0 +1,33 @@
1
+ describe "cyoi key_pair openstack" do
2
+ include Cyoi::Cli::Helpers::Settings
3
+ include SettingsHelper
4
+ include Aruba::Api
5
+ before { @settings_dir = File.expand_path("~/.cyoi_client_lib") }
6
+
7
+ it "fails nicely if provider.name missing" do
8
+ run_interactive(unescape("cyoi key_pair testname #{settings_dir}"))
9
+ assert_failing_with("Please run 'cyoi provider' first")
10
+ end
11
+
12
+ describe "name & provider setup and" do
13
+ before do
14
+ setting "provider.name", "openstack"
15
+ setting "provider.credentials.openstack_username", "USERNAME"
16
+ setting "provider.credentials.openstack_api_key", "PASSWORD"
17
+ setting "provider.credentials.openstack_tenant", "TENANT"
18
+ setting "provider.credentials.openstack_auth_url", "TOKENURL"
19
+ setting "provider.credentials.openstack_region", "REGION"
20
+ setting "name", "test-bosh"
21
+ end
22
+
23
+ it "create new key pair (didn't already exist in OpenStack)" do
24
+ run_interactive(unescape("cyoi key_pair testname #{settings_dir}"))
25
+ assert_passing_with(<<-OUT)
26
+ Acquiring a key pair testname... done
27
+
28
+ Confirming: Using key pair testname
29
+ OUT
30
+ end
31
+ end
32
+
33
+ end
@@ -10,9 +10,9 @@ describe "cyoi provider openstack" do
10
10
  setting "provider.credentials.openstack_api_key", "PASSWORD"
11
11
  setting "provider.credentials.openstack_tenant", "TENANT"
12
12
  setting "provider.credentials.openstack_auth_url", "TOKENURL"
13
- setting "provider.region", "us-west"
13
+ setting "provider.credentials.openstack_region", "REGION"
14
14
  run_interactive(unescape("cyoi provider #{settings_dir}"))
15
- assert_passing_with("Confirming: Using OpenStack/us-west")
15
+ assert_passing_with("Confirming: Using OpenStack")
16
16
  end
17
17
 
18
18
  it "prompts for everything (no region)" do
@@ -30,8 +30,7 @@ describe "cyoi provider openstack" do
30
30
  Choose your infrastructure:
31
31
  Using provider OpenStack
32
32
 
33
- Username: Password: Tenant: Authorization Token URL:
34
- OpenStack Region (optional):
33
+ Username: Password: Tenant: Authorization Token URL: OpenStack Region (optional):
35
34
  Confirming: Using OpenStack
36
35
  OUT
37
36
 
@@ -41,9 +40,9 @@ Confirming: Using OpenStack
41
40
  "name" => "openstack",
42
41
  "credentials"=>{
43
42
  "openstack_username"=>"USERNAME", "openstack_api_key"=>"PASSWORD",
44
- "openstack_tenant"=>"TENANT", "openstack_auth_url"=>"TOKENURL"
43
+ "openstack_tenant"=>"TENANT", "openstack_auth_url"=>"TOKENURL/tokens",
44
+ "openstack_region"=>""
45
45
  },
46
- "region" => "",
47
46
  }
48
47
  }
49
48
  end
@@ -63,9 +62,8 @@ Confirming: Using OpenStack
63
62
  Choose your infrastructure:
64
63
  Using provider OpenStack
65
64
 
66
- Username: Password: Tenant: Authorization Token URL:
67
- OpenStack Region (optional):
68
- Confirming: Using OpenStack/REGION
65
+ Username: Password: Tenant: Authorization Token URL: OpenStack Region (optional):
66
+ Confirming: Using OpenStack
69
67
  OUT
70
68
  end
71
69
 
@@ -86,9 +84,8 @@ Auto-detected infrastructure API credentials at ~/.fog (override with $FOG)
86
84
  Choose an auto-detected infrastructure:
87
85
  Using provider OpenStack
88
86
 
89
-
90
87
  OpenStack Region (optional):
91
- Confirming: Using OpenStack/REGION
88
+ Confirming: Using OpenStack
92
89
  OUT
93
90
  end
94
91
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cyoi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
5
- prerelease:
4
+ version: 0.5.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Dr Nic Williams
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-21 00:00:00.000000000 Z
11
+ date: 2013-05-22 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: fog
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ! '>='
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: highline
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: readwritesettings
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: bundler
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rake
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ! '>='
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ! '>='
92
81
  - !ruby/object:Gem::Version
@@ -94,7 +83,6 @@ dependencies:
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: rspec
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
87
  - - ! '>='
100
88
  - !ruby/object:Gem::Version
@@ -102,7 +90,6 @@ dependencies:
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
94
  - - ! '>='
108
95
  - !ruby/object:Gem::Version
@@ -110,7 +97,6 @@ dependencies:
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: aruba
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
101
  - - ! '>='
116
102
  - !ruby/object:Gem::Version
@@ -118,7 +104,6 @@ dependencies:
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
108
  - - ! '>='
124
109
  - !ruby/object:Gem::Version
@@ -155,7 +140,9 @@ files:
155
140
  - lib/cyoi/cli/key_pair.rb
156
141
  - lib/cyoi/cli/provider.rb
157
142
  - lib/cyoi/cli/provider_addresses/address_cli_aws.rb
143
+ - lib/cyoi/cli/provider_addresses/address_cli_openstack.rb
158
144
  - lib/cyoi/cli/provider_key_pair/key_pair_aws.rb
145
+ - lib/cyoi/cli/provider_key_pair/key_pair_openstack.rb
159
146
  - lib/cyoi/cli/providers/provider_cli.rb
160
147
  - lib/cyoi/cli/providers/provider_cli_aws.rb
161
148
  - lib/cyoi/cli/providers/provider_cli_openstack.rb
@@ -169,7 +156,9 @@ files:
169
156
  - lib/cyoi/version.rb
170
157
  - spec/.DS_Store
171
158
  - spec/integration/cli/address/address_aws_spec.rb
159
+ - spec/integration/cli/address/address_openstack_spec.rb
172
160
  - spec/integration/cli/key_pair/key_pair_aws_spec.rb
161
+ - spec/integration/cli/key_pair/key_pair_openstack_spec.rb
173
162
  - spec/integration/cli/provider/provider_aws_spec.rb
174
163
  - spec/integration/cli/provider/provider_openstack_spec.rb
175
164
  - spec/spec_helper.rb
@@ -180,33 +169,26 @@ files:
180
169
  homepage: https://github.com/drnic/cyoi
181
170
  licenses:
182
171
  - MIT
172
+ metadata: {}
183
173
  post_install_message:
184
174
  rdoc_options: []
185
175
  require_paths:
186
176
  - lib
187
177
  required_ruby_version: !ruby/object:Gem::Requirement
188
- none: false
189
178
  requirements:
190
179
  - - ! '>='
191
180
  - !ruby/object:Gem::Version
192
181
  version: '0'
193
- segments:
194
- - 0
195
- hash: -4128619338422380975
196
182
  required_rubygems_version: !ruby/object:Gem::Requirement
197
- none: false
198
183
  requirements:
199
184
  - - ! '>='
200
185
  - !ruby/object:Gem::Version
201
186
  version: '0'
202
- segments:
203
- - 0
204
- hash: -4128619338422380975
205
187
  requirements: []
206
188
  rubyforge_project:
207
- rubygems_version: 1.8.25
189
+ rubygems_version: 2.0.3
208
190
  signing_key:
209
- specification_version: 3
191
+ specification_version: 4
210
192
  summary: A library to ask an end-user to choose an infrastructure (AWS, OpenStack,
211
193
  etc), region, and login credentials. This library was extracted from [inception-server](https://github.com/drnic/inception-server)
212
194
  for reuse by [bosh-bootstrap](https://github.com/StarkAndWayne/bosh-bootstrap).
@@ -216,7 +198,9 @@ summary: A library to ask an end-user to choose an infrastructure (AWS, OpenStac
216
198
  test_files:
217
199
  - spec/.DS_Store
218
200
  - spec/integration/cli/address/address_aws_spec.rb
201
+ - spec/integration/cli/address/address_openstack_spec.rb
219
202
  - spec/integration/cli/key_pair/key_pair_aws_spec.rb
203
+ - spec/integration/cli/key_pair/key_pair_openstack_spec.rb
220
204
  - spec/integration/cli/provider/provider_aws_spec.rb
221
205
  - spec/integration/cli/provider/provider_openstack_spec.rb
222
206
  - spec/spec_helper.rb