vagrant-niftycloud 0.1.0.dev

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.
Files changed (34) hide show
  1. data/.gitignore +18 -0
  2. data/CHANGELOG.md +1 -0
  3. data/Gemfile +10 -0
  4. data/LICENSE +8 -0
  5. data/README.md +256 -0
  6. data/Rakefile +21 -0
  7. data/dummy.box +0 -0
  8. data/example_box/README.md +13 -0
  9. data/example_box/metadata.json +3 -0
  10. data/lib/vagrant-niftycloud.rb +18 -0
  11. data/lib/vagrant-niftycloud/action.rb +178 -0
  12. data/lib/vagrant-niftycloud/action/connect_niftycloud.rb +56 -0
  13. data/lib/vagrant-niftycloud/action/is_created.rb +18 -0
  14. data/lib/vagrant-niftycloud/action/message_already_created.rb +16 -0
  15. data/lib/vagrant-niftycloud/action/message_not_created.rb +16 -0
  16. data/lib/vagrant-niftycloud/action/message_will_not_destroy.rb +16 -0
  17. data/lib/vagrant-niftycloud/action/read_ssh_info.rb +52 -0
  18. data/lib/vagrant-niftycloud/action/read_state.rb +56 -0
  19. data/lib/vagrant-niftycloud/action/resume_instance.rb +56 -0
  20. data/lib/vagrant-niftycloud/action/run_instance.rb +131 -0
  21. data/lib/vagrant-niftycloud/action/suspend_instance.rb +56 -0
  22. data/lib/vagrant-niftycloud/action/sync_folders.rb +67 -0
  23. data/lib/vagrant-niftycloud/action/terminate_instance.rb +61 -0
  24. data/lib/vagrant-niftycloud/action/timed_provision.rb +21 -0
  25. data/lib/vagrant-niftycloud/config.rb +210 -0
  26. data/lib/vagrant-niftycloud/errors.rb +35 -0
  27. data/lib/vagrant-niftycloud/plugin.rb +73 -0
  28. data/lib/vagrant-niftycloud/provider.rb +50 -0
  29. data/lib/vagrant-niftycloud/util/timer.rb +17 -0
  30. data/lib/vagrant-niftycloud/version.rb +5 -0
  31. data/locales/en.yml +91 -0
  32. data/spec/vagrant-niftycloud/config_spec.rb +154 -0
  33. data/vagrant-niftycloud.gemspec +57 -0
  34. metadata +157 -0
@@ -0,0 +1,50 @@
1
+ require "log4r"
2
+ require "vagrant"
3
+
4
+ module VagrantPlugins
5
+ module NiftyCloud
6
+ class Provider < Vagrant.plugin("2", :provider)
7
+ def initialize(machine)
8
+ @machine = machine
9
+ end
10
+
11
+ def action(name)
12
+ # Attempt to get the action method from the Action class if it
13
+ # exists, otherwise return nil to show that we don't support the
14
+ # given action.
15
+ action_method = "action_#{name}"
16
+ return Action.send(action_method) if Action.respond_to?(action_method)
17
+ nil
18
+ end
19
+
20
+ def ssh_info
21
+ # Run a custom action called "read_ssh_info" which does what it
22
+ # says and puts the resulting SSH info into the `:machine_ssh_info`
23
+ # key in the environment.
24
+ env = @machine.action("read_ssh_info")
25
+ env[:machine_ssh_info]
26
+ end
27
+
28
+ def state
29
+ # Run a custom action we define called "read_state" which does
30
+ # what it says. It puts the state in the `:machine_state_id`
31
+ # key in the environment.
32
+ env = @machine.action("read_state")
33
+
34
+ state_id = env[:machine_state_id]
35
+
36
+ # Get the short and long description
37
+ short = I18n.t("vagrant_niftycloud.states.short_#{state_id}")
38
+ long = I18n.t("vagrant_niftycloud.states.long_#{state_id}")
39
+
40
+ # Return the MachineState object
41
+ Vagrant::MachineState.new(state_id, short, long)
42
+ end
43
+
44
+ def to_s
45
+ id = @machine.id.nil? ? "new" : @machine.id
46
+ "NiftyCloud (#{id})"
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,17 @@
1
+ module VagrantPlugins
2
+ module NiftyCloud
3
+ module Util
4
+ class Timer
5
+ # A basic utility method that times the execution of the given
6
+ # block and returns it.
7
+ def self.time
8
+ start_time = Time.now.to_f
9
+ yield
10
+ end_time = Time.now.to_f
11
+
12
+ end_time - start_time
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module NiftyCloud
3
+ VERSION = "0.1.0.dev"
4
+ end
5
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,91 @@
1
+ en:
2
+ vagrant_niftycloud:
3
+ already_created: |-
4
+ The machine is already created.
5
+ launching_instance: |-
6
+ Launching an instance with the following settings...
7
+ launch_no_keypair: |-
8
+ Warning! You didn't specify a keypair to launch your instance with.
9
+ This can sometimes result in not being able to access your instance.
10
+ not_created: |-
11
+ Instance is not created. Please run `vagrant up` first.
12
+ ready: |-
13
+ Machine is booted and ready for use!
14
+ rsync_folder: |-
15
+ Rsyncing folder: %{hostpath} => %{guestpath}
16
+ terminating: |-
17
+ Terminating the instance...
18
+ waiting_for_ready: |-
19
+ Waiting for instance to become "ready"...
20
+ waiting_for_ssh: |-
21
+ Waiting for SSH to become available...
22
+ will_not_destroy: |-
23
+ The instance '%{name}' will not be destroyed, since the confirmation
24
+ was declined.
25
+
26
+ config:
27
+ access_key_id_required: |-
28
+ An access key ID must be specified via "access_key_id"
29
+ image_id_required: |-
30
+ An Image ID must be configured via "image_id"
31
+ private_key_missing: |-
32
+ The specified private key for NiftyCloud could not be found
33
+ zone_required: |-
34
+ A zone must be specified via "zone"
35
+ secret_access_key_required: |-
36
+ A secret access key is required via "secret_access_key"
37
+
38
+ errors:
39
+ instance_ready_timeout: |-
40
+ The instance never became "ready" in NiftyCloud. The timeout currently
41
+ set waiting for the instance to become ready is %{timeout} seconds.
42
+ Please verify that the machine properly boots. If you need more time
43
+ set the `instance_ready_timeout` configuration on the NiftyCloud provider.
44
+ niftycloud_response_error: |-
45
+ Response Error occured while connecting to Nifty Cloud API
46
+
47
+ Error Code: %{code}
48
+ %{message}
49
+
50
+ niftycloud_configuration_error: |-
51
+ Configuration for Nifty Cloud API is invalid
52
+
53
+ %{message}
54
+
55
+ niftycloud_argument_error: |-
56
+ Argument for Nifty Cloud API is invalid.
57
+
58
+ %{message}
59
+
60
+ niftycloud_response_format_error: |-
61
+ Could Not Parse Response of Nifty Cloud API
62
+
63
+ %{message}
64
+
65
+ rsync_error: |-
66
+ There was an error when attemping to rsync a share folder.
67
+ Please inspect the error message below for more info.
68
+
69
+ Host path: %{hostpath}
70
+ Guest path: %{guestpath}
71
+ Error: %{stderr}
72
+
73
+ states:
74
+ short_not_created: |-
75
+ not created
76
+ long_not_created: |-
77
+ The Nifty Cloud instance is not created. Run `vagrant up` to create it.
78
+ short_running: |-
79
+ running
80
+ long_running: |-
81
+ The Nifty Cloud instance is running. To stop this machine, you can run
82
+ `vagrant halt`. To destroy the machine, you can run `vagrant destroy`.
83
+ short_stopped: |-
84
+ stopped
85
+ long_stopped: |-
86
+ The Nifty Cloud instance is stopped. To destroy the machine, you can run
87
+ `vagrant destroy`.
88
+ short_pending: |-
89
+ pending
90
+ long_pending: |-
91
+ The Nifty Cloud instance is pending. Please wait for process to finish
@@ -0,0 +1,154 @@
1
+ require "vagrant-niftycloud/config"
2
+
3
+ describe VagrantPlugins::NiftyCloud::Config do
4
+ let(:instance) { described_class.new }
5
+
6
+ # Ensure tests are not affected by NiftyCloud credential environment variables
7
+ before :each do
8
+ ENV.stub(:[] => nil)
9
+ end
10
+
11
+ describe "defaults" do
12
+ subject do
13
+ instance.tap do |o|
14
+ o.finalize!
15
+ end
16
+ end
17
+
18
+ its("access_key_id") { should be_nil }
19
+ its("image_id") { should be_nil }
20
+ its("key_name") { should be_nil }
21
+ its("zone") { should be_nil }
22
+ its("instance_ready_timeout") { should == 120 }
23
+ its("instance_type") { should == "mini" }
24
+ its("secret_access_key") { should be_nil }
25
+ its("firewall") { should == [] }
26
+ its("user_data") { should be_nil }
27
+ end
28
+
29
+ describe "overriding defaults" do
30
+ # I typically don't meta-program in tests, but this is a very
31
+ # simple boilerplate test, so I cut corners here. It just sets
32
+ # each of these attributes to "foo" in isolation, and reads the value
33
+ # and asserts the proper result comes back out.
34
+ [:access_key_id, :image_id, :key_name, :zone,
35
+ :instance_ready_timeout, :instance_type, :secret_access_key,
36
+ :firewall, :user_data].each do |attribute|
37
+
38
+ it "should not default #{attribute} if overridden" do
39
+ instance.send("#{attribute}=".to_sym, "foo")
40
+ instance.finalize!
41
+ instance.send(attribute).should == "foo"
42
+ end
43
+ end
44
+ end
45
+
46
+ describe "getting credentials from environment" do
47
+ context "without NiftyCloud credential environment variables" do
48
+ subject do
49
+ instance.tap do |o|
50
+ o.finalize!
51
+ end
52
+ end
53
+
54
+ its("access_key_id") { should be_nil }
55
+ its("secret_access_key") { should be_nil }
56
+ end
57
+
58
+ context "with NiftyCloud credential environment variables" do
59
+ before :each do
60
+ ENV.stub(:[]).with("NIFTY_ACCESS_KEY").and_return("access_key")
61
+ ENV.stub(:[]).with("NIFTY_SECRET_KEY").and_return("secret_key")
62
+ end
63
+
64
+ subject do
65
+ instance.tap do |o|
66
+ o.finalize!
67
+ end
68
+ end
69
+
70
+ its("access_key_id") { should == "access_key" }
71
+ its("secret_access_key") { should == "secret_key" }
72
+ end
73
+ end
74
+
75
+ describe "zone config" do
76
+ let(:config_access_key_id) { "foo" }
77
+ let(:config_image_id) { "foo" }
78
+ let(:config_key_name) { "foo" }
79
+ let(:config_instance_type) { "foo" }
80
+ let(:config_secret_access_key) { "foo" }
81
+
82
+ def set_test_values(instance)
83
+ instance.access_key_id = config_access_key_id
84
+ instance.image_id = config_image_id
85
+ instance.key_name = config_key_name
86
+ instance.instance_type = config_instance_type
87
+ instance.secret_access_key = config_secret_access_key
88
+ end
89
+
90
+ context "with no specific config set" do
91
+ subject do
92
+ # Set the values on the top-level object
93
+ set_test_values(instance)
94
+
95
+ # Finalize so we can get the zone config
96
+ instance.finalize!
97
+
98
+ end
99
+
100
+ its("access_key_id") { should == config_access_key_id }
101
+ its("image_id") { should == config_image_id }
102
+ its("key_name") { should == config_key_name }
103
+ its("instance_type") { should == config_instance_type }
104
+ its("secret_access_key") { should == config_secret_access_key }
105
+ end
106
+
107
+ context "with a specific config set" do
108
+ its("access_key_id") { should == config_access_key_id }
109
+ its("image_id") { should == config_image_id }
110
+ its("key_name") { should == config_key_name }
111
+ its("instance_type") { should == config_instance_type }
112
+ its("secret_access_key") { should == config_secret_access_key }
113
+ end
114
+
115
+ describe "inheritance of parent config" do
116
+ let(:zone_name) { "hashi-zone" }
117
+
118
+ subject do
119
+ # Set the values on a specific zone
120
+ instance.zone_config zone_name do |config|
121
+ config.image_id = "child"
122
+ end
123
+
124
+ # Set some top-level values
125
+ instance.access_key_id = "parent"
126
+ instance.image_id = "parent"
127
+ instance.key_name = "parent"
128
+
129
+ # Finalize and get the zone
130
+ instance.finalize!
131
+ instance.get_zone_config(zone_name)
132
+ end
133
+
134
+ its("access_key_id") { should == "parent" }
135
+ its("image_id") { should == "child" }
136
+ end
137
+
138
+ describe "shortcut configuration" do
139
+ subject do
140
+ # Use the shortcut configuration to set some values
141
+ instance.zone_config "east-12", :image_id => "child"
142
+ instance.finalize!
143
+ instance.get_zone_config("east-12")
144
+ end
145
+
146
+ its("image_id") { should == "child" }
147
+ end
148
+
149
+ describe "merging" do
150
+ let(:first) { described_class.new }
151
+ let(:second) { described_class.new }
152
+ end
153
+ end
154
+ end
@@ -0,0 +1,57 @@
1
+ $:.unshift File.expand_path("../lib", __FILE__)
2
+ require "vagrant-niftycloud/version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "vagrant-niftycloud"
6
+ s.version = VagrantPlugins::NiftyCloud::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = "Satoshi Akama"
9
+ s.email = "satoshiakama@gmail.com"
10
+ s.homepage = "http://www.vagrantup.com"
11
+ s.summary = "Enables Vagrant to manage machines in Nifty Cloud"
12
+ s.description = "Enables Vagrant to manage machines in Nifty Cloud."
13
+
14
+ s.required_rubygems_version = ">= 0.1.0"
15
+ s.rubyforge_project = "vagrant-nifycloud"
16
+
17
+ s.add_development_dependency "rake"
18
+ s.add_development_dependency "rspec-core", "~> 2.12.2"
19
+ s.add_development_dependency "rspec-expectations", "~> 2.12.1"
20
+ s.add_development_dependency "rspec-mocks", "~> 2.12.1"
21
+ s.add_dependency "nifty-cloud-sdk", ">= 1.7"
22
+
23
+ # The following block of code determines the files that should be included
24
+ # in the gem. It does this by reading all the files in the directory where
25
+ # this gemspec is, and parsing out the ignored files from the gitignore.
26
+ # Note that the entire gitignore(5) syntax is not supported, specifically
27
+ # the "!" syntax, but it should mostly work correctly.
28
+ root_path = File.dirname(__FILE__)
29
+ all_files = Dir.chdir(root_path) { Dir.glob("**/{*,.*}") }
30
+ all_files.reject! { |file| [".", ".."].include?(File.basename(file)) }
31
+ gitignore_path = File.join(root_path, ".gitignore")
32
+ gitignore = File.readlines(gitignore_path)
33
+ gitignore.map! { |line| line.chomp.strip }
34
+ gitignore.reject! { |line| line.empty? || line =~ /^(#|!)/ }
35
+
36
+ unignored_files = all_files.reject do |file|
37
+ # Ignore any directories, the gemspec only cares about files
38
+ next true if File.directory?(file)
39
+
40
+ # Ignore any paths that match anything in the gitignore. We do
41
+ # two tests here:
42
+ #
43
+ # - First, test to see if the entire path matches the gitignore.
44
+ # - Second, match if the basename does, this makes it so that things
45
+ # like '.DS_Store' will match sub-directories too (same behavior
46
+ # as git).
47
+ #
48
+ gitignore.any? do |ignore|
49
+ File.fnmatch(ignore, file, File::FNM_PATHNAME) ||
50
+ File.fnmatch(ignore, File.basename(file), File::FNM_PATHNAME)
51
+ end
52
+ end
53
+
54
+ s.files = unignored_files
55
+ s.executables = unignored_files.map { |f| f[/^bin\/(.*)/, 1] }.compact
56
+ s.require_path = 'lib'
57
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-niftycloud
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.dev
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Satoshi Akama
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec-core
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 2.12.2
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.12.2
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec-expectations
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 2.12.1
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.12.1
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec-mocks
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.12.1
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.12.1
78
+ - !ruby/object:Gem::Dependency
79
+ name: nifty-cloud-sdk
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '1.7'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '1.7'
94
+ description: Enables Vagrant to manage machines in Nifty Cloud.
95
+ email: satoshiakama@gmail.com
96
+ executables: []
97
+ extensions: []
98
+ extra_rdoc_files: []
99
+ files:
100
+ - CHANGELOG.md
101
+ - dummy.box
102
+ - example_box/metadata.json
103
+ - example_box/README.md
104
+ - Gemfile
105
+ - lib/vagrant-niftycloud/action/connect_niftycloud.rb
106
+ - lib/vagrant-niftycloud/action/is_created.rb
107
+ - lib/vagrant-niftycloud/action/message_already_created.rb
108
+ - lib/vagrant-niftycloud/action/message_not_created.rb
109
+ - lib/vagrant-niftycloud/action/message_will_not_destroy.rb
110
+ - lib/vagrant-niftycloud/action/read_ssh_info.rb
111
+ - lib/vagrant-niftycloud/action/read_state.rb
112
+ - lib/vagrant-niftycloud/action/resume_instance.rb
113
+ - lib/vagrant-niftycloud/action/run_instance.rb
114
+ - lib/vagrant-niftycloud/action/suspend_instance.rb
115
+ - lib/vagrant-niftycloud/action/sync_folders.rb
116
+ - lib/vagrant-niftycloud/action/terminate_instance.rb
117
+ - lib/vagrant-niftycloud/action/timed_provision.rb
118
+ - lib/vagrant-niftycloud/action.rb
119
+ - lib/vagrant-niftycloud/config.rb
120
+ - lib/vagrant-niftycloud/errors.rb
121
+ - lib/vagrant-niftycloud/plugin.rb
122
+ - lib/vagrant-niftycloud/provider.rb
123
+ - lib/vagrant-niftycloud/util/timer.rb
124
+ - lib/vagrant-niftycloud/version.rb
125
+ - lib/vagrant-niftycloud.rb
126
+ - LICENSE
127
+ - locales/en.yml
128
+ - Rakefile
129
+ - README.md
130
+ - spec/vagrant-niftycloud/config_spec.rb
131
+ - vagrant-niftycloud.gemspec
132
+ - .gitignore
133
+ homepage: http://www.vagrantup.com
134
+ licenses: []
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ! '>='
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ! '>='
149
+ - !ruby/object:Gem::Version
150
+ version: 0.1.0
151
+ requirements: []
152
+ rubyforge_project: vagrant-nifycloud
153
+ rubygems_version: 1.8.23
154
+ signing_key:
155
+ specification_version: 3
156
+ summary: Enables Vagrant to manage machines in Nifty Cloud
157
+ test_files: []