vagrant-hp 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
@@ -1,3 +1,7 @@
1
+ # 0.1.3 (Jan 17 2014)
2
+ * Upgraded to fog 1.19.0
3
+ * Upgraded to HP-Compute-v13.5
4
+
1
5
  # 0.1.2 (Oct 26 2013)
2
6
  * Upgraded to fog 1.15.0
3
7
 
@@ -0,0 +1,13 @@
1
+ # 0.1.3 (Jan 17 2014)
2
+ * Upgraded to fog 1.19.0
3
+ * Upgraded to HP-Compute-v13.5
4
+
5
+ # 0.1.2 (Oct 26 2013)
6
+ * Upgraded to fog 1.15.0
7
+
8
+ # 0.1.1 (May 22, 2013)
9
+ * Added support to specify security groups.
10
+
11
+ # 0.1.0 (March 31, 2013)
12
+ * Vagrant-Hp
13
+ * Initial release.
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
@@ -6,5 +6,6 @@ group :development do
6
6
  # We depend on Vagrant for development, but we don't add it as a
7
7
  # gem dependency because we expect to be installed within the
8
8
  # Vagrant environment itself using `vagrant plugin`.
9
- gem "vagrant", :git => "git://github.com/mohitsethi/vagrant.git"
9
+ gem 'vagrant', git: 'git://github.com/mohitsethi/vagrant.git'
10
+ gem 'coveralls', require: false
10
11
  end
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Vagrant HP Provider
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/vagrant-hp.png)](http://badge.fury.io/rb/vagrant-hp) [![Dependency Status](https://gemnasium.com/mohitsethi/vagrant-hp.png)](https://gemnasium.com/mohitsethi/vagrant-hp) [![Code Climate](https://codeclimate.com/github/mohitsethi/vagrant-hp.png)](https://codeclimate.com/github/mohitsethi/vagrant-hp) [![Build Status](https://travis-ci.org/mohitsethi/vagrant-hp.png?branch=master)](https://travis-ci.org/mohitsethi/vagrant-hp) [![Coverage Status](https://coveralls.io/repos/mohitsethi/vagrant-hp/badge.png)](https://coveralls.io/r/mohitsethi/vagrant-hp)
4
+
5
+
3
6
  This is a [Vagrant](http://www.vagrantup.com) 1.1+ plugin that adds an [HP](http://www.hpcloud.com)
4
7
  provider to Vagrant, allowing Vagrant to control and provision machines on HP Cloud.
5
8
 
@@ -8,6 +11,7 @@ provider to Vagrant, allowing Vagrant to control and provision machines on HP Cl
8
11
  ## Features
9
12
 
10
13
  * Boot Servers on HP Cloud
14
+ * Auto Floating-IP management
11
15
  * SSH into the instances.
12
16
  * Provision the instances with any built-in Vagrant provisioner.
13
17
  * Minimal synced folder support via `rsync`.
@@ -90,10 +94,10 @@ provider-specific configuration for this provider.
90
94
  This provider exposes quite a few provider-specific configuration options:
91
95
 
92
96
  * `access_key` - The access key for accessing HP Cloud
93
- * `image` - The Image-id or Image-Name to boot, such as
97
+ * `image` - The Image-id or Image-Name to boot, such as
94
98
  "Ubuntu Precise 12.04 LTS Server 64-bit 20121026 (b)"
95
- * `availability_zone` - The availability zone to launch the server.
96
- If nil, it will use 'az1'.
99
+ * `availability_zone` - The availability zone to launch the server ['us-east', 'us-west'].
100
+ If nil, it will use 'us-west'.
97
101
  * `flavor` - The type of flavor, such as "standard.xsmall"
98
102
  * `keypair_name` - The name of the keypair to use to bootstrap image
99
103
  which support it.
data/Rakefile CHANGED
@@ -1,6 +1,9 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
3
  require 'rspec/core/rake_task'
4
+ require 'rubocop/rake_task'
5
+
6
+ Rubocop::RakeTask.new
4
7
 
5
8
  # Immediately sync all stdout so that tools like buildbot can
6
9
  # immediately load in the output.
@@ -0,0 +1,28 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
5
+ VAGRANTFILE_API_VERSION = "2"
6
+
7
+ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
8
+ # Every Vagrant virtual environment requires a box to build off of.
9
+ config.vm.box = "dummy"
10
+ config.vm.provider :hp do |rs|
11
+ rs.access_key = "Y5SKH1MU6HZ2PEM9ZNZL"
12
+ rs.secret_key = "YA2BJr98R3hDK7IwpIkHXlDCDo9GG+GIuqhflPqQ"
13
+ rs.flavor = "standard.xsmall"
14
+ rs.tenant_id = "87309806546461"
15
+ rs.server_name = "test_server"
16
+ #rs.image = "Ubuntu Precise 12.04 LTS Server 64-bit 20121026 (b)"
17
+ rs.image = "CentOS 6.3 Server 64-bit 20130116 (b)"
18
+ rs.keypair_name = "test_hp"
19
+ #rs.keypair_name = "ms"
20
+ rs.ssh_private_key_path = "./test_key.pem"
21
+ #rs.ssh_private_key_path = "~anne/.ssh/id_rsa"
22
+ rs.ssh_username = "root"
23
+ #rs.availability_zone = "az1"
24
+ # Security Groups defaults to ["default"]
25
+ # rs.security_groups = ["group1", "group2"]
26
+ end
27
+
28
+ end
@@ -1,18 +1,17 @@
1
- require "pathname"
2
-
3
- require "vagrant-hp/plugin"
1
+ require 'pathname'
2
+ require 'vagrant-hp/plugin'
4
3
 
5
4
  module VagrantPlugins
6
5
  module HP
7
- lib_path = Pathname.new(File.expand_path("../vagrant-hp", __FILE__))
8
- autoload :Action, lib_path.join("action")
9
- autoload :Errors, lib_path.join("errors")
6
+ lib_path = Pathname.new(File.expand_path('../vagrant-hp', __FILE__))
7
+ autoload :Action, lib_path.join('action')
8
+ autoload :Errors, lib_path.join('errors')
10
9
 
11
10
  # This returns the path to the source of this plugin.
12
11
  #
13
12
  # @return [Pathname]
14
13
  def self.source_root
15
- @source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
14
+ @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
16
15
  end
17
16
  end
18
17
  end
@@ -3,8 +3,8 @@
3
3
  # Copyright:: Copyright (c) 2013 Mohit Sethi.
4
4
  #
5
5
 
6
- require "pathname"
7
- require "vagrant/action/builder"
6
+ require 'pathname'
7
+ require 'vagrant/action/builder'
8
8
 
9
9
  module VagrantPlugins
10
10
  module HP
@@ -26,7 +26,7 @@ module VagrantPlugins
26
26
  Vagrant::Action::Builder.new.tap do |b|
27
27
  b.use ConfigValidate
28
28
  b.use Call, IsCreated do |env, b2|
29
- if !env[:result]
29
+ unless env[:result]
30
30
  b2.use MessageNotCreated
31
31
  next
32
32
  end
@@ -63,7 +63,7 @@ module VagrantPlugins
63
63
  Vagrant::Action::Builder.new.tap do |b|
64
64
  b.use ConfigValidate
65
65
  b.use Call, IsCreated do |env, b2|
66
- if !env[:result]
66
+ unless env[:result]
67
67
  b2.use MessageNotCreated
68
68
  next
69
69
  end
@@ -92,19 +92,20 @@ module VagrantPlugins
92
92
  end
93
93
 
94
94
  # The autoload farm
95
- action_root = Pathname.new(File.expand_path("../action", __FILE__))
96
- autoload :ConnectHP, action_root.join("connect_hp")
97
- autoload :IsCreated, action_root.join("is_created")
98
- autoload :MessageAlreadyCreated, action_root.join("message_already_created")
99
- autoload :MessageNotCreated, action_root.join("message_not_created")
100
- autoload :ReadSSHInfo, action_root.join("read_ssh_info")
101
- autoload :ReadState, action_root.join("read_state")
102
- autoload :RunInstance, action_root.join("run_instance")
103
- autoload :SyncFolders, action_root.join("sync_folders")
104
- autoload :TimedProvision, action_root.join("timed_provision")
105
- autoload :WarnNetworks, action_root.join("warn_networks")
106
- autoload :CreateServer, action_root.join("create_server")
107
- autoload :DeleteServer, action_root.join("delete_server")
95
+ action_root = Pathname.new(File.expand_path('../action', __FILE__))
96
+ autoload :ConnectHP, action_root.join('connect_hp')
97
+ autoload :IsCreated, action_root.join('is_created')
98
+ autoload :MessageAlreadyCreated, action_root.join(
99
+ 'message_already_created')
100
+ autoload :MessageNotCreated, action_root.join('message_not_created')
101
+ autoload :ReadSSHInfo, action_root.join('read_ssh_info')
102
+ autoload :ReadState, action_root.join('read_state')
103
+ autoload :RunInstance, action_root.join('run_instance')
104
+ autoload :SyncFolders, action_root.join('sync_folders')
105
+ autoload :TimedProvision, action_root.join('timed_provision')
106
+ autoload :WarnNetworks, action_root.join('warn_networks')
107
+ autoload :CreateServer, action_root.join('create_server')
108
+ autoload :DeleteServer, action_root.join('delete_server')
108
109
  end
109
110
  end
110
111
  end
@@ -3,8 +3,8 @@
3
3
  # Copyright:: Copyright (c) 2013 Mohit Sethi.
4
4
  #
5
5
 
6
- require "fog/hp"
7
- require "log4r"
6
+ require 'fog/hp'
7
+ require 'log4r'
8
8
 
9
9
  module VagrantPlugins
10
10
  module HP
@@ -15,7 +15,7 @@ module VagrantPlugins
15
15
  class ConnectHP
16
16
  def initialize(app, env)
17
17
  @app = app
18
- @logger = Log4r::Logger.new("vagrant_hp::action::connect_hp")
18
+ @logger = Log4r::Logger.new('vagrant_hp::action::connect_hp')
19
19
  end
20
20
 
21
21
  def call(env)
@@ -26,26 +26,25 @@ module VagrantPlugins
26
26
  tenant_id = config.tenant_id
27
27
  availability_zone = availability_zone(config.availability_zone)
28
28
 
29
- @logger.info("Connecting to HP...")
30
- env[:hp_compute] = Fog::Compute.new({
31
- :provider => :hp,
32
- :hp_access_key => access_key,
33
- :hp_secret_key => secret_key,
34
- :hp_tenant_id => tenant_id,
35
- :hp_avl_zone => availability_zone,
36
- })
29
+ @logger.info('Connecting to HP...')
30
+ env[:hp_compute] = Fog::Compute.new(
31
+ provider: 'HP',
32
+ version: 'v2',
33
+ hp_access_key: access_key,
34
+ hp_secret_key: secret_key,
35
+ hp_tenant_id: tenant_id,
36
+ hp_avl_zone: availability_zone,
37
+ )
37
38
 
38
39
  @app.call(env)
39
40
  end
40
41
 
41
42
  def availability_zone(availability_zone)
42
43
  case availability_zone
43
- when 'az3'
44
- return 'az-3.region-a.geo-1'
45
- when 'az2'
46
- return 'az-2.region-a.geo-1'
44
+ when 'us-east'
45
+ return 'region-b.geo-1'
47
46
  else
48
- return 'az-1.region-a.geo-1'
47
+ return 'region-a.geo-1'
49
48
  end
50
49
  end
51
50
  end
@@ -4,8 +4,7 @@
4
4
  #
5
5
 
6
6
  require 'vagrant/util/retryable'
7
- require "log4r"
8
-
7
+ require 'log4r'
9
8
 
10
9
  module VagrantPlugins
11
10
  module HP
@@ -16,7 +15,7 @@ module VagrantPlugins
16
15
 
17
16
  def initialize(app, env)
18
17
  @app = app
19
- @logger = Log4r::Logger.new("vagrant_hp::action::create_server")
18
+ @logger = Log4r::Logger.new('vagrant_hp::action::create_server')
20
19
  end
21
20
 
22
21
  def call(env)
@@ -24,34 +23,36 @@ module VagrantPlugins
24
23
  config = env[:machine].provider_config
25
24
 
26
25
  # Find the flavor
27
- env[:ui].info(I18n.t("vagrant_hp.finding_flavor"))
26
+ env[:ui].info(I18n.t('vagrant_hp.finding_flavor'))
28
27
  flavor = find_match(env[:hp_compute].flavors.all, config.flavor)
29
- raise Errors::NoMatchingFlavor if !flavor
28
+ raise Errors::NoMatchingFlavor unless flavor
30
29
 
31
30
  # Find the image
32
- env[:ui].info(I18n.t("vagrant_hp.finding_image"))
31
+ env[:ui].info(I18n.t('vagrant_hp.finding_image'))
33
32
  image = find_match(env[:hp_compute].images, config.image)
34
- raise Errors::NoMatchingImage if !image
33
+ raise Errors::NoMatchingImage unless image
35
34
 
36
35
  # Figure out the name for the server
37
- server_name = config.server_name || env[:machine].name if env[:machine].name != "default" || get_server_name()
36
+ server_name = config.server_name || env[:machine].name if \
37
+ env[:machine].name != 'default' || get_server_name
38
38
 
39
39
  # Output the settings we're going to use to the user
40
- env[:ui].info(I18n.t("vagrant_hp.launching_server"))
40
+ env[:ui].info(I18n.t('vagrant_hp.launching_server'))
41
41
  env[:ui].info(" -- Flavor: #{flavor.name}")
42
42
  env[:ui].info(" -- Image: #{image.name}")
43
43
  env[:ui].info(" -- Name: #{server_name}")
44
- if config.security_groups
44
+ env[:ui].info(" -- Key-name: #{config.keypair_name}")
45
+ if config.security_groups
45
46
  env[:ui].info(" -- Security Groups: #{config.security_groups}")
46
47
  end
47
48
 
48
49
  # Build the options for launching...
49
50
  options = {
50
- :flavor_id => flavor.id,
51
- :image_id => image.id,
52
- :name => server_name,
53
- :key_name => config.keypair_name,
54
- :security_groups => config.security_groups
51
+ flavor_id: flavor.id,
52
+ image_id: image.id,
53
+ name: server_name,
54
+ key_name: config.keypair_name,
55
+ security_groups: config.security_groups
55
56
  }
56
57
 
57
58
  # Create the server
@@ -61,8 +62,8 @@ module VagrantPlugins
61
62
  env[:machine].id = server.id
62
63
 
63
64
  # Wait for the server to finish building
64
- env[:ui].info(I18n.t("vagrant_hp.waiting_for_build"))
65
- retryable(:on => Timeout::Error, :tries => 200) do
65
+ env[:ui].info(I18n.t('vagrant_hp.waiting_for_build'))
66
+ retryable(on: Timeout::Error, tries: 200) do
66
67
  # If we're interrupted don't worry about waiting
67
68
  next if env[:interrupted]
68
69
 
@@ -72,21 +73,24 @@ module VagrantPlugins
72
73
 
73
74
  # Wait for the server to be ready
74
75
  begin
75
- server.wait_for(15) { ready? }
76
+ server.wait_for(30) { ready? }
76
77
  rescue RuntimeError, Fog::Errors::TimeoutError => e
77
78
  # If we don't have an error about a state transition, then
78
79
  # we just move on.
79
- #raise if e.message !~ /should have transitioned/
80
+ # raise if e.message !~ /should have transitioned/
80
81
  env[:ui].info("Error: #{e.message}")
81
82
  end
82
83
  end
83
-
84
- if !env[:interrupted]
84
+ env[:ui].clear_line
85
+ env[:ui].info(I18n.t('vagrant_hp.associate_floating_ip_to_server'))
86
+ ip = env[:hp_compute].addresses.create
87
+ ip.server = server
88
+ unless env[:interrupted]
85
89
  # Clear the line one more time so the progress is removed
86
90
  env[:ui].clear_line
87
91
 
88
92
  # Wait for SSH to become available
89
- env[:ui].info(I18n.t("vagrant_hp.waiting_for_ssh"))
93
+ env[:ui].info(I18n.t('vagrant_hp.waiting_for_ssh'))
90
94
  while true
91
95
  begin
92
96
  # If we're interrupted then just back out
@@ -97,7 +101,7 @@ module VagrantPlugins
97
101
  sleep 2
98
102
  end
99
103
 
100
- env[:ui].info(I18n.t("vagrant_hp.ready"))
104
+ env[:ui].info(I18n.t('vagrant_hp.ready'))
101
105
  end
102
106
 
103
107
  @app.call(env)
@@ -106,7 +110,7 @@ module VagrantPlugins
106
110
  protected
107
111
 
108
112
  # generate a random name if server_name is empty
109
- def get_server_name()
113
+ def get_server_name
110
114
  server_name = "vagrant_hp-#{rand.to_s.split('.')[1]}"
111
115
  server_name.to_s
112
116
  end
@@ -3,7 +3,7 @@
3
3
  # Copyright:: Copyright (c) 2013 Mohit Sethi.
4
4
  #
5
5
 
6
- require "log4r"
6
+ require 'log4r'
7
7
 
8
8
  module VagrantPlugins
9
9
  module HP
@@ -12,12 +12,15 @@ module VagrantPlugins
12
12
  class DeleteServer
13
13
  def initialize(app, env)
14
14
  @app = app
15
- @logger = Log4r::Logger.new("vagrant_hp::action::delete_server")
15
+ @logger = Log4r::Logger.new('vagrant_hp::action::delete_server')
16
16
  end
17
17
 
18
18
  def call(env)
19
19
  if env[:machine].id
20
- @logger.info(I18n.t("vagrant_hp.deleting_server"))
20
+ @logger.info(I18n.t('vagrant_hp.deleting_floating_ip'))
21
+ ip = env[:hp_compute].addresses.find { |ip| ip.instance_id==env[:machine].id }
22
+ ip.destroy
23
+ @logger.info(I18n.t('vagrant_hp.deleting_server'))
21
24
  server = env[:hp_compute].servers.get(env[:machine].id)
22
25
  server.destroy
23
26
  env[:machine].id = nil
@@ -3,7 +3,7 @@
3
3
  # Copyright:: Copyright (c) 2013 Mohit Sethi.
4
4
  #
5
5
 
6
- require "log4r"
6
+ require 'log4r'
7
7
 
8
8
  module VagrantPlugins
9
9
  module HP
@@ -12,12 +12,12 @@ module VagrantPlugins
12
12
  class HaltServer
13
13
  def initialize(app, env)
14
14
  @app = app
15
- @logger = Log4r::Logger.new("vagrant_hp::action::delete_server")
15
+ @logger = Log4r::Logger.new('vagrant_hp::action::delete_server')
16
16
  end
17
17
 
18
18
  def call(env)
19
19
  if env[:machine].id
20
- @logger.info(I18n.t("vagrant_hp.deleting_server"))
20
+ @logger.info(I18n.t('vagrant_hp.deleting_server'))
21
21
  server = env[:hp_compute].servers.get(env[:machine].id)
22
22
  server.stop # verify this
23
23
  env[:machine].id = nil
@@ -12,7 +12,7 @@ module VagrantPlugins
12
12
  end
13
13
 
14
14
  def call(env)
15
- env[:ui].info(I18n.t("vagrant_hp.already_created"))
15
+ env[:ui].info(I18n.t('vagrant_hp.already_created'))
16
16
  @app.call(env)
17
17
  end
18
18
  end
@@ -12,7 +12,7 @@ module VagrantPlugins
12
12
  end
13
13
 
14
14
  def call(env)
15
- env[:ui].info(I18n.t("vagrant_hp.not_created"))
15
+ env[:ui].info(I18n.t('vagrant_hp.not_created'))
16
16
  @app.call(env)
17
17
  end
18
18
  end