Commit 764699c4 authored by Johan Jatko's avatar Johan Jatko
Browse files

ready to release

parent 5e9b122a
# Vagrant LUDD DUSTcloud Provider
## Features
- Boot instances in LUDD DUSTcloud.
- SSH into the instances.
- Provision the instances with any built-in Vagrant provisioner.
- Minimal synced folder support via `rsync`.
## Usage
Install using the standard Vagrant 1.1+ plugin installation methods. After installing, `vagrant up` and specify the `dustcloud` provider. An example is shown below.
```
$ vagrant plugin install vagrant-dustcloud
...
$ vagrant up --provider=dustcloud
...
```
## Quick Start
After installing the plugin (instructions above), the quickest way to get started is to actually use a dummy Dustcloud box and specify all the details manually within a config.vm.provider block. So first, add the dummy box using any name you want:
```
$ vagrant box add dummy https://git.ludd.ltu.se/ludd/vagrant-dustcloud/raw/master/dummy.box
...
```
And then make a Vagrantfile that looks like the following.
```ruby
Vagrant.configure("2") do |config|
config.vm.box = "dummy"
config.vm.provider :dustcloud do |dustcloud|
dustcloud.token_file = "~/.dustcloud"
dustcloud.image = "focal"
dustcloud.flavor = "small"
end
end
```
And then run `vagrant up --provider=dustcloud`.
## Development
To work on the `vagrant-dustcloud` plugin, clone this repository out, and use
[Bundler](http://gembundler.com) to get the dependencies:
```
$ bundle
```
If those pass, you're ready to start developing the plugin. You can test
the plugin without installing it into your Vagrant environment by just
creating a `Vagrantfile` in the top level of this directory (it is gitignored)
and add the following line to your `Vagrantfile`
```ruby
Vagrant.require_plugin "vagrant-dustcloud"
```
Use bundler to execute Vagrant:
```
$ bundle exec vagrant up --provider=dustcloud
```
\ No newline at end of file
require 'rubygems'
require 'bundler/setup'
# Immediately sync all stdout so that tools like buildbot can
# immediately load in the output.
$stdout.sync = true
$stderr.sync = true
# Change to the directory of this file.
Dir.chdir(File.expand_path("../", __FILE__))
# This installs the tasks that help with gem creation and
# publishing.
Bundler::GemHelper.install_tasks
\ No newline at end of file
......@@ -156,7 +156,7 @@ module VagrantPlugins
end
b2.use action_halt
b2.use Call, WaitForState, :stopped, 120 do |env2, b3|
b2.use Call, WaitForState, :shutoff, 120 do |env2, b3|
if env2[:result]
b3.use action_up
else
......
......@@ -7,7 +7,7 @@ module VagrantPlugins
end
def call(env)
env[:ui].info("Instance was already created")
env[:ui].info(I18n.t("vagrant_dustcloud.already_status", :status => "created"))
@app.call(env)
end
end
......
......@@ -7,7 +7,7 @@ module VagrantPlugins
end
def call(env)
env[:ui].info("Instance was not created")
env[:ui].info(I18n.t("vagrant_dustcloud.not_created"))
@app.call(env)
end
end
......
......@@ -7,7 +7,7 @@ module VagrantPlugins
end
def call(env)
env[:ui].info("Will not destroy #{env[:machine].name}")
env[:ui].info(I18n.t("vagrant_dustcloud.will_not_destroy", name: env[:machine].name))
@app.call(env)
end
end
......
......@@ -23,7 +23,7 @@ module VagrantPlugins
flavor = env[:machine].provider_config.flavor.to_s
image = env[:machine].provider_config.image.to_s
env[:ui].info("Launching instance on LUDD DUSTcloud")
env[:ui].info(I18n.t("vagrant_dustcloud.launching_instance"))
env[:ui].info(" -- Image: #{image}")
env[:ui].info(" -- Flavor: #{flavor}")
......@@ -42,7 +42,7 @@ module VagrantPlugins
env[:metrics]["instance_ready_time"] = Util::Timer.time do
env[:ui].info("Waiting for instance to become ready")
env[:ui].info(I18n.t("vagrant_dustcloud.waiting_for_ready"))
total_waited = 0
while true
# If we're interrupted don't worry about waiting
......@@ -65,7 +65,7 @@ module VagrantPlugins
if !env[:interrupted]
env[:metrics]["instance_ssh_time"] = Util::Timer.time do
# Wait for SSH to be ready.
env[:ui].info("Waiting for SSH to be ready")
env[:ui].info(I18n.t("vagrant_dustcloud.waiting_for_ssh"))
network_ready_retries = 0
network_ready_retries_max = 10
while true
......@@ -83,14 +83,13 @@ module VagrantPlugins
raise e
end
end
env[:ui].info("Attempt #{network_ready_retries}")
sleep 2
end
end
env[:ui].info("Time for SSH ready: #{env[:metrics]["instance_ssh_time"]}")
# Ready and booted!
env[:ui].info("Instance is ready for action!")
env[:ui].info(I18n.t("vagrant_dustcloud.ready"))
end
terminate(env) if env[:interrupted]
......
require "log4r"
require 'vagrant/util/retryable'
require 'vagrant-dustcloud/util/timer'
module VagrantPlugins
module Dustcloud
......@@ -16,20 +17,20 @@ module VagrantPlugins
def call(env)
# Initialize metrics if they haven't been
env[:metrics] ||= {}
env[:ui].info("Starting instance...")
env[:ui].info(I18n.t("vagrant_dustcloud.starting"))
begin
env[:dustcloud].start_vm(env[:machine].id)
env[:metrics]["instance_ready_time"] = Util::Timer.time do
env[:ui].info("Waiting for instance to become ready")
env[:ui].info(I18n.t("vagrant_dustcloud.waiting_for_ready"))
total_waited = 0
while true
# If we're interrupted don't worry about waiting
break if env[:interrupted]
# Wait for the server to be ready
vm = env[:dustcloud].get_vm(server["uuid"])
vm = env[:dustcloud].get_vm(env[:machine].id)
if vm["status"] == "ACTIVE"
break
end
......@@ -45,7 +46,7 @@ module VagrantPlugins
if !env[:interrupted]
env[:metrics]["instance_ssh_time"] = Util::Timer.time do
# Wait for SSH to be ready.
env[:ui].info("Waiting for SSH to be ready")
env[:ui].info(I18n.t("vagrant_dustcloud.waiting_for_ssh"))
network_ready_retries = 0
network_ready_retries_max = 10
while true
......@@ -63,14 +64,13 @@ module VagrantPlugins
raise e
end
end
env[:ui].info("Attempt #{network_ready_retries}")
sleep 2
end
end
env[:ui].info("Time for SSH ready: #{env[:metrics]["instance_ssh_time"]}")
# Ready and booted!
env[:ui].info("Instance is ready for action!")
env[:ui].info(I18n.t("vagrant_dustcloud.ready"))
end
end
......
......@@ -12,9 +12,9 @@ module VagrantPlugins
def call(env)
if env[:machine].state.id == :shutoff
env[:ui].info("Instance was already shut off")
env[:ui].info(I18n.t("vagrant_dustcloud.already_status", :status => env[:machine].state.id))
else
env[:ui].info("Stopping instance")
env[:ui].info(I18n.t("vagrant_dustcloud.stopping"))
env[:dustcloud].stop_vm(env[:machine].id)
end
......
......@@ -13,14 +13,14 @@ module VagrantPlugins
def call(env)
env[:ui].info("Destroying Dustcloud instance")
env[:ui].info(I18n.t("vagrant_dustcloud.terminating"))
result = env[:dustcloud].destroy_vm(env[:machine].id)
if result["errors"].length > 0
env[:ui].info("Failed to destroy instance")
env[:ui].info(I18n.t("vagrant_dustcloud.terminating_failed"))
result["errors"].each do |item|
env[:ui].info(" -- #{item}")
end
env[:ui].info("You may need to use the Cloud Dashboard (https://dust.ludd.ltu.se) or contact the administrators.")
env[:ui].info(I18n.t("vagrant_dustcloud.terminating_help"))
end
env[:machine].id = nil
......
......@@ -42,7 +42,7 @@ module VagrantPlugins
class Credentials < Vagrant.plugin("2", :config)
def get_token(token_file)
if !token_file.nil? && File.exists?(token_file)
token_file.read
File.read(token_file)
else
ENV["DUSTCLOUD_TOKEN"].to_s
end
......
......@@ -8,24 +8,16 @@ module VagrantPlugins
end
class APIError < VagrantDustcloudError
error_key(:fog_error)
error_key(:api_error)
end
class InternalAPIError < VagrantDustcloudError
error_key(:internal_fog_error)
error_key(:internal_api_error)
end
class InstanceReadyTimeout < VagrantDustcloudError
error_key(:instance_ready_timeout)
end
class InstancePackageError < VagrantDustcloudError
error_key(:instance_package_error)
end
class InstancePackageTimeout < VagrantDustcloudError
error_key(:instance_package_timeout)
end
end
end
end
\ No newline at end of file
......@@ -3,21 +3,36 @@ begin
rescue LoadError
raise "The Vagrant Dustcloud plugin must be run within Vagrant."
end
# This is a sanity check to make sure no one is attempting to install
# this into an early Vagrant version.
if Vagrant::VERSION < "1.2.0"
raise "The Vagrant Dustcloud plugin is only compatible with Vagrant 1.2+"
end
module VagrantPlugins
module Dustcloud
class Plugin < Vagrant.plugin("2")
name "LUDD DUSTcloud Provisioner"
description <<-DESC
This plugin installs a provider that allows Vagrant to manage
machines in LUDD DUSTcloud.
DESC
config(:dustcloud, :provider) do
require_relative "config"
Config
end
provider(:dustcloud) do
setup_i18n
require_relative "provider"
Provider
end
def self.setup_i18n
I18n.load_path << File.expand_path("locales/en.yaml", Dustcloud.source_root)
I18n.reload!
end
end
end
end
\ No newline at end of file
......@@ -33,8 +33,8 @@ module VagrantPlugins
state_id = env[:machine_state_id]
# Get the short and long description
short = I18n.t("vagrant_aws.states.short_#{state_id}")
long = I18n.t("vagrant_aws.states.long_#{state_id}")
short = I18n.t("vagrant_dustcloud.states.short_#{state_id}")
long = I18n.t("vagrant_dustcloud.states.long_#{state_id}")
# Return the MachineState object
Vagrant::MachineState.new(state_id, short, long)
......
module VagrantPlugins
module Dustcloud
VERSION = '0.0.1'
VERSION = '0.0.5'
end
end
\ No newline at end of file
en:
vagrant_dustcloud:
already_status: |-
The machine is already %{status}.
launching_instance: |-
Launching an instance with the following settings...
not_created: |-
Instance is not created. Please run `vagrant up` first.
ready: |-
Machine is booted and ready for use!
rsync_not_found_warning: |-
Warning! Folder sync disabled because the rsync binary is missing in the %{side}.
Make sure rsync is installed and the binary can be found in the PATH.
rsync_folder: |-
Rsyncing folder: %{hostpath} => %{guestpath}
starting: |-
Starting the instance...
stopping: |-
Stopping the instance...
terminating: |-
Terminating the instance...
terminating_failed: |-
Failed to terminate the instance
terminating_help: |-
You may need to use the Cloud Dashboard (https://dust.ludd.ltu.se) or contact the administrators.
waiting_for_ready: |-
Waiting for instance to become "ready"...
waiting_for_ssh: |-
Waiting for SSH to become available...
will_not_destroy: |-
The instance '%{name}' will not be destroyed, since the confirmation
was declined.
config:
token_required: |-
An access key ID must be specified via "access_key_id"
errors:
api_error: |-
There was an error talking to Dustcloud. The error message is shown
below:
%{message}
internal_api_error: |-
There was an error talking to Dustcloud. The error message is shown
below:
Error: %{error}
Response: %{response}
instance_ready_timeout: |-
The instance never became "ready" in Dustcloud. The timeout currently
set waiting for the instance to become ready is %{timeout} seconds.
Please verify that the machine properly boots.
states:
short_not_created: |-
not created
long_not_created: |-
The Dustcloud instance is not created. Run `vagrant up` to create it.
short_shutoff: |-
shut off
long_shutoff: |-
The Dustcloud instance is stopped. Run `vagrant up` to start it.
short_build: |-
building
long_build: |-
The Dustcloud instance is building/planning. It will soon start installation.
short_installing: |-
installing
long_installing: |-
The Dustcloud instance is currently setting up.
short_active: |-
running
long_active: |-
The Dustcloud instance is running. To stop this machine, you can run
`vagrant halt`. To destroy the machine, you can run `vagrant destroy`.
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment