cyoi 0.9.2 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTQ0ZGE5ZDMzMzU5MGZiZDcxMTBjZDNiMTk2ZmRhZWFkZmM5ZjUwOA==
4
+ MDdkOWUzMjRmM2Q4OThkNmFkNjc5NDJlMjQxN2NhZTYwZGRhMDdiNQ==
5
5
  data.tar.gz: !binary |-
6
- MTdhYWE3Njg5YzE4YTE5MWE0MzVkNTdlZGEyYzQ5MjFkYWI2M2I5Zg==
6
+ NTA2ZDgyZTFiZWI5OTA5MzA2NzgyMjU0ZjcxMzk2Y2E5M2ZiODUyNw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NGY1ZmIxY2E2ZDIzZWE5YThhZWU5NmMzZGZlMTIwYTBmMGQ4ODUxNzlmZjEy
10
- ZjQ1NjYyNGRmMmMxMDFhMWQxYjQxN2MxMTBmNmQ3MzY5ZmYxYzQxZjkwODhj
11
- MTlmZjU2NDFhYWY5NDkzMDQzYWIyNWUxMGIwZjQwMmQyMDNiNDA=
9
+ NTNkM2FiZDczOGEzYzAxYjZhNTBlZWU3Yjc2ZTBmYzlhZmEzYmE0MjkxODIx
10
+ ZGIzZGVmMjhmZmUzMjI0MzMxOGY0YzQ3ZjQwYzllNjVhNGM5ZjMxMmJjMGNm
11
+ NzRlNmRkMmQ5ZTAyODFjY2NjMTZkYzA2Yjk3ZWQ3OGFkZDRmOWI=
12
12
  data.tar.gz: !binary |-
13
- NDcxMzIyZGQ4NzZjZDliNDVmNzgxMGNmOWFlNjI0ZDVhYTY1YWM4YzM0MTBh
14
- OGViMDkxYzE4YmI4MTIyYmNkOWE4NzZhMmVmNWZjMDdiOWZiNjU4OTVlOGNh
15
- ODA3M2E5YTBkNDIzMDNkN2NjYzM5OWI5YjQ2NzdlMWZiOTFjNTA=
13
+ MTg1YTFlZWU4NzNmZGE1MzM1YTI4OTVkZjI5MGUwN2RlNjk0ZmI1MWFiZWI5
14
+ NzhkNTc3ODQ4NjkzYTY3YWM4NzMxNzg2ZWJiMzM5MjcwNjdiMjQzMDE3YmEy
15
+ NGU4Y2VlNDQ5YWYwZGVlNTM0ODczZjZjNTA0NTA3OTVmY2Q1N2E=
@@ -3,6 +3,11 @@ Change Log
3
3
 
4
4
  Cyoi (choose-your-own-infrastructure) is a library to ask an end-user to choose an infrastructure (AWS, OpenStack, etc), region, and login credentials.
5
5
 
6
+ v0.10
7
+ -----
8
+
9
+ - `blobstores` - create a bucket/container on AWS/OpenStack
10
+
6
11
  v0.9
7
12
  ----
8
13
 
data/bin/cyoi CHANGED
@@ -17,11 +17,14 @@ when :address
17
17
  when :image
18
18
  require "cyoi/cli/image"
19
19
  Cyoi::Cli::Image.new(argv)
20
+ when :blobstore
21
+ require "cyoi/cli/blobstore"
22
+ Cyoi::Cli::Blobstore.new(argv)
20
23
  when :keypair, :key_pair
21
24
  require "cyoi/cli/key_pair"
22
25
  Cyoi::Cli::KeyPair.new(argv)
23
26
  else
24
- $stderr.puts "USAGE: cyoi [provider|address|key_pair]"
27
+ $stderr.puts "USAGE: cyoi [provider|address|image|blobstore|key_pair]"
25
28
  exit 1
26
29
  end
27
30
 
@@ -30,4 +33,4 @@ require "fog"
30
33
  Fog.mock!
31
34
 
32
35
  cli.show_settings
33
- cli.execute!
36
+ cli.execute!
@@ -0,0 +1,65 @@
1
+ require "cyoi/cli"
2
+ require "cyoi/cli/auto_detection"
3
+ require "cyoi/cli/helpers"
4
+ class Cyoi::Cli::Blobstore
5
+ include Cyoi::Cli::Helpers
6
+
7
+ attr_reader :blobstore_name
8
+
9
+ def initialize(argv, stdin=STDIN, stdout=STDOUT, stderr=STDERR, kernel=Kernel)
10
+ @argv, @stdin, @stdout, @stderr, @kernel = argv, stdin, stdout, stderr, kernel
11
+ unless @blobstore_name = @argv.shift
12
+ raise "Please provide blobstore name as first argument"
13
+ end
14
+ @settings_dir = @argv.shift || "/tmp/provider_settings"
15
+ @settings_dir = File.expand_path(@settings_dir)
16
+ end
17
+
18
+ # TODO run Cyoi::Cli::Provider first if settings.provider.name missing
19
+ def execute!
20
+ unless settings.exists?("provider.name") && settings.exists?("provider.credentials")
21
+ $stderr.puts("Please run 'cyoi provider' first")
22
+ exit 1
23
+ end
24
+
25
+ settings["blobstore"] = perform_and_return_attributes
26
+ save_settings!
27
+
28
+ blobstore_cli.display_confirmation
29
+ end
30
+
31
+ # Continue the interactive session with the user
32
+ # specific to the infrastructure they have chosen.
33
+ #
34
+ # The returned object is a class from cyoi/cli/provider_blobstore/provier_cli_INFRASTRUCTURE.rb
35
+ # The class loads itself into `@blobstore_clis` via `register_blobstore_cli`
36
+ #
37
+ # Returns nil if settings.key_pair.name not set
38
+ def blobstore_cli
39
+ @blobstore_cli ||= begin
40
+ provider_name = settings.exists?("provider.name")
41
+ return nil unless provider_name
42
+ require "cyoi/cli/provider_blobstore/blobstore_cli_#{settings.provider.name}"
43
+
44
+ settings["blobstore"] ||= {}
45
+ settings.blobstore["name"] = blobstore_name
46
+
47
+ klass = self.class.blobstore_cli(settings.provider.name)
48
+ klass.new(provider_client, settings.blobstore, hl)
49
+ end
50
+ end
51
+
52
+ def perform_and_return_attributes
53
+ blobstore_cli.perform_and_return_attributes
54
+ end
55
+
56
+ def self.register_cli(name, klass)
57
+ @blobstore_clis ||= {}
58
+ @blobstore_clis[name] = klass
59
+ end
60
+
61
+ def self.blobstore_cli(name)
62
+ @blobstore_clis[name]
63
+ end
64
+
65
+ end
@@ -41,9 +41,11 @@ class Cyoi::Cli::KeyPair
41
41
  provider_name = settings.exists?("provider.name")
42
42
  return nil unless provider_name
43
43
  require "cyoi/cli/provider_key_pair/key_pair_#{settings.provider.name}"
44
- klass = self.class.key_pair_cli(settings.provider.name)
44
+
45
45
  settings["key_pair"] ||= {}
46
46
  settings.key_pair["name"] = key_pair_name
47
+
48
+ klass = self.class.key_pair_cli(settings.provider.name)
47
49
  klass.new(provider_client, settings.key_pair, hl)
48
50
  end
49
51
  end
@@ -61,4 +63,4 @@ class Cyoi::Cli::KeyPair
61
63
  def valid?
62
64
  key_pair_cli && key_pair_cli.valid?
63
65
  end
64
- end
66
+ end
@@ -0,0 +1,5 @@
1
+ require "cyoi/cli/provider_blobstore/blobstore_cli_base"
2
+ class Cyoi::Cli::Blobstore::BlobstoreCliAws < Cyoi::Cli::Blobstore::BlobstoreCliBase
3
+ end
4
+
5
+ Cyoi::Cli::Blobstore.register_cli("aws", Cyoi::Cli::Blobstore::BlobstoreCliAws)
@@ -0,0 +1,29 @@
1
+ class Cyoi::Cli::Blobstore; end
2
+ class Cyoi::Cli::Blobstore::BlobstoreCliBase
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); was #{@attributes.class}" unless @attributes.is_a?(ReadWriteSettings)
12
+ end
13
+
14
+ def perform_and_return_attributes
15
+ # create blobstore OR show how many blobstore already exist in blobstore
16
+ provider_client.create_blobstore(attributes["name"])
17
+ export_attributes
18
+ end
19
+
20
+ # helper to export the complete nested attributes.
21
+ def export_attributes
22
+ attributes.to_nested_hash
23
+ end
24
+
25
+ def display_confirmation
26
+ puts "\n"
27
+ puts "Confirming: Using blobstore #{attributes["name"]}"
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ require "cyoi/cli/provider_blobstore/blobstore_cli_base"
2
+ class Cyoi::Cli::Blobstore::BlobstoreCliOpenStack < Cyoi::Cli::Blobstore::BlobstoreCliBase
3
+ end
4
+
5
+ Cyoi::Cli::Blobstore.register_cli("aws", Cyoi::Cli::Blobstore::BlobstoreCliOpenStack)
@@ -174,6 +174,14 @@ class Cyoi::Providers::Clients::AwsProviderClient < Cyoi::Providers::Clients::Fo
174
174
  server
175
175
  end
176
176
 
177
+ def fog_storage
178
+ @fog_storage ||= begin
179
+ configuration = Fog.symbolize_credentials(attributes.credentials)
180
+ configuration[:provider] = "AWS"
181
+ Fog::Storage.new(configuration)
182
+ end
183
+ end
184
+
177
185
  # Construct a Fog::Compute object
178
186
  # Uses +attributes+ which normally originates from +settings.provider+
179
187
  def setup_fog_connection
@@ -17,6 +17,26 @@ class Cyoi::Providers::Clients::FogProviderClient
17
17
  def setup_fog_connection
18
18
  end
19
19
 
20
+ def supports_blobstore_service?
21
+ fog_storage
22
+ rescue
23
+ false
24
+ end
25
+
26
+ def create_blobstore(blobstore_name)
27
+ unless supports_blobstore_service?
28
+ puts "Provider does not support blobstore service"
29
+ false
30
+ else
31
+ print "Attempting to create blobstore #{blobstore_name}... "
32
+ blobstore = fog_storage.directories.create(key: blobstore_name)
33
+ puts "done"
34
+ blobstore
35
+ end
36
+ rescue Excon::Errors::Conflict => e
37
+ puts "failed: blobstore already exists but owned by someone else"
38
+ end
39
+
20
40
  def create_key_pair(key_pair_name)
21
41
  print "Acquiring a key pair #{key_pair_name}... "
22
42
  key_pair = fog_compute.key_pairs.create(:name => key_pair_name)
@@ -112,6 +112,12 @@ class Cyoi::Providers::Clients::OpenStackProviderClient < Cyoi::Providers::Clien
112
112
  configuration
113
113
  end
114
114
 
115
+ # May throw odd exception if OpenStack doesn't support Swift, like:
116
+ # NoMethodError: undefined method `join' for "object-store":String
117
+ def fog_storage
118
+ @fog_storage ||= Fog::Storage.new(configuration)
119
+ end
120
+
115
121
  # Construct a Fog::Compute object
116
122
  # Uses +attributes+ which normally originates from +settings.provider+
117
123
  def setup_fog_connection
@@ -1,3 +1,3 @@
1
1
  module Cyoi
2
- VERSION = "0.9.2"
2
+ VERSION = "0.10.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cyoi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dr Nic Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-18 00:00:00.000000000 Z
11
+ date: 2014-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog
@@ -147,6 +147,7 @@ files:
147
147
  - lib/cyoi/cli/address.rb
148
148
  - lib/cyoi/cli/auto_detection.rb
149
149
  - lib/cyoi/cli/auto_detection/auto_detection_fog.rb
150
+ - lib/cyoi/cli/blobstore.rb
150
151
  - lib/cyoi/cli/helpers.rb
151
152
  - lib/cyoi/cli/helpers/interactions.rb
152
153
  - lib/cyoi/cli/helpers/provider.rb
@@ -157,6 +158,9 @@ files:
157
158
  - lib/cyoi/cli/provider_addresses/address_cli_aws.rb
158
159
  - lib/cyoi/cli/provider_addresses/address_cli_openstack.rb
159
160
  - lib/cyoi/cli/provider_addresses/address_cli_vsphere.rb
161
+ - lib/cyoi/cli/provider_blobstore/blobstore_cli_aws.rb
162
+ - lib/cyoi/cli/provider_blobstore/blobstore_cli_base.rb
163
+ - lib/cyoi/cli/provider_blobstore/blobstore_cli_openstack.rb
160
164
  - lib/cyoi/cli/provider_image/image_cli_aws.rb
161
165
  - lib/cyoi/cli/provider_image/image_cli_base.rb
162
166
  - lib/cyoi/cli/provider_image/image_cli_openstack.rb