diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..df70ba4 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +# 0.1.0 (Unreleased) + +* Initial release. diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..41cb498 --- /dev/null +++ b/Gemfile @@ -0,0 +1,14 @@ +source "https://rubygems.org" + +gemspec + +group :development do + # We depend on Vagrant for development, but we don't add it as a + # gem dependency because we expect to be installed within the + # Vagrant environment itself using `vagrant plugin`. + gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git" +end + +group :plugins do + gem "vagrant-xenserver", :path => "." +end diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d4717f0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,8 @@ +The MIT License (MIT) +Copyright (c) 2014 Mitchell Hashimoto + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..a0a7b42 --- /dev/null +++ b/README.md @@ -0,0 +1,251 @@ +# Vagrant AWS Provider + + +[![Gem Version](https://badge.fury.io/rb/vagrant-aws.png)][gem] +[![Dependency Status](https://gemnasium.com/mitchellh/vagrant-aws.png)][gemnasium] + + +[gem]: https://rubygems.org/gems/vagrant-aws +[gemnasium]: https://gemnasium.com/mitchellh/vagrant-aws + +This is a [Vagrant](http://www.vagrantup.com) 1.2+ plugin that adds an [AWS](http://aws.amazon.com) +provider to Vagrant, allowing Vagrant to control and provision machines in +EC2 and VPC. + +**NOTE:** This plugin requires Vagrant 1.2+, + +## Features + +* Boot EC2 or VPC instances. +* SSH into the instances. +* Provision the instances with any built-in Vagrant provisioner. +* Minimal synced folder support via `rsync`. +* Define region-specifc configurations so Vagrant can manage machines + in multiple regions. + +## Usage + +Install using standard Vagrant 1.1+ plugin installation methods. After +installing, `vagrant up` and specify the `aws` provider. An example is +shown below. + +``` +$ vagrant plugin install vagrant-aws +... +$ vagrant up --provider=aws +... +``` + +Of course prior to doing this, you'll need to obtain an AWS-compatible +box file for Vagrant. + +## Quick Start + +After installing the plugin (instructions above), the quickest way to get +started is to actually use a dummy AWS 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://github.com/mitchellh/vagrant-aws/raw/master/dummy.box +... +``` + +And then make a Vagrantfile that looks like the following, filling in +your information where necessary. + +``` +Vagrant.configure("2") do |config| + config.vm.box = "dummy" + + config.vm.provider :aws do |aws, override| + aws.access_key_id = "YOUR KEY" + aws.secret_access_key = "YOUR SECRET KEY" + aws.keypair_name = "KEYPAIR NAME" + + aws.ami = "ami-7747d01e" + + override.ssh.username = "ubuntu" + override.ssh.private_key_path = "PATH TO YOUR PRIVATE KEY" + end +end +``` + +And then run `vagrant up --provider=aws`. + +This will start an Ubuntu 12.04 instance in the us-east-1 region within +your account. And assuming your SSH information was filled in properly +within your Vagrantfile, SSH and provisioning will work as well. + +Note that normally a lot of this boilerplate is encoded within the box +file, but the box file used for the quick start, the "dummy" box, has +no preconfigured defaults. + +If you have issues with SSH connecting, make sure that the instances +are being launched with a security group that allows SSH access. + +## Box Format + +Every provider in Vagrant must introduce a custom box format. This +provider introduces `aws` boxes. You can view an example box in +the [example_box/ directory](https://github.com/mitchellh/vagrant-aws/tree/master/example_box). +That directory also contains instructions on how to build a box. + +The box format is basically just the required `metadata.json` file +along with a `Vagrantfile` that does default settings for the +provider-specific configuration for this provider. + +## Configuration + +This provider exposes quite a few provider-specific configuration options: + +* `access_key_id` - The access key for accessing AWS +* `ami` - The AMI id to boot, such as "ami-12345678" +* `availability_zone` - The availability zone within the region to launch + the instance. If nil, it will use the default set by Amazon. +* `instance_ready_timeout` - The number of seconds to wait for the instance + to become "ready" in AWS. Defaults to 120 seconds. +* `instance_type` - The type of instance, such as "m1.small". The default + value of this if not specified is "m1.small". +* `keypair_name` - The name of the keypair to use to bootstrap AMIs + which support it. +* `private_ip_address` - The private IP address to assign to an instance + within a [VPC](http://aws.amazon.com/vpc/) +* `region` - The region to start the instance in, such as "us-east-1" +* `secret_access_key` - The secret access key for accessing AWS +* `security_groups` - An array of security groups for the instance. If this + instance will be launched in VPC, this must be a list of security group + IDs. +* `iam_instance_profile_arn` - The Amazon resource name (ARN) of the IAM Instance + Profile to associate with the instance +* `iam_instance_profile_name` - The name of the IAM Instance Profile to associate + with the instance +* `subnet_id` - The subnet to boot the instance into, for VPC. +* `associate_public_ip` - If true, will associate a public IP address to an instance in a VPC. +* `tags` - A hash of tags to set on the machine. +* `use_iam_profile` - If true, will use [IAM profiles](http://docs.aws.amazon.com/IAM/latest/UserGuide/instance-profiles.html) + for credentials. + +These can be set like typical provider-specific configuration: + +```ruby +Vagrant.configure("2") do |config| + # ... other stuff + + config.vm.provider :aws do |aws| + aws.access_key_id = "foo" + aws.secret_access_key = "bar" + end +end +``` + +In addition to the above top-level configs, you can use the `region_config` +method to specify region-specific overrides within your Vagrantfile. Note +that the top-level `region` config must always be specified to choose which +region you want to actually use, however. This looks like this: + +```ruby +Vagrant.configure("2") do |config| + # ... other stuff + + config.vm.provider :aws do |aws| + aws.access_key_id = "foo" + aws.secret_access_key = "bar" + aws.region = "us-east-1" + + # Simple region config + aws.region_config "us-east-1", :ami => "ami-12345678" + + # More comprehensive region config + aws.region_config "us-west-2" do |region| + region.ami = "ami-87654321" + region.keypair_name = "company-west" + end + end +end +``` + +The region-specific configurations will override the top-level +configurations when that region is used. They otherwise inherit +the top-level configurations, as you would probably expect. + +## Networks + +Networking features in the form of `config.vm.network` are not +supported with `vagrant-aws`, currently. If any of these are +specified, Vagrant will emit a warning, but will otherwise boot +the AWS machine. + +## Synced Folders + +There is minimal support for synced folders. Upon `vagrant up`, +`vagrant reload`, and `vagrant provision`, the AWS provider will use +`rsync` (if available) to uni-directionally sync the folder to +the remote machine over SSH. + +This is good enough for all built-in Vagrant provisioners (shell, +chef, and puppet) to work! + +## Other Examples + +### Tags + +To use tags, simply define a hash of key/value for the tags you want to associate to your instance, like: + +```ruby +Vagrant.configure("2") do |config| + # ... other stuff + + config.vm.provider "aws" do |aws| + aws.tags = { + 'Name' => 'Some Name', + 'Some Key' => 'Some Value' + } + end +end +``` + +### User data + +You can specify user data for the instance being booted. + +```ruby +Vagrant.configure("2") do |config| + # ... other stuff + + config.vm.provider "aws" do |aws| + # Option 1: a single string + aws.user_data = "#!/bin/bash\necho 'got user data' > /tmp/user_data.log\necho" + + # Option 2: use a file + aws.user_data = File.read("user_data.txt") + end +end +``` + +## Development + +To work on the `vagrant-aws` plugin, clone this repository out, and use +[Bundler](http://gembundler.com) to get the dependencies: + +``` +$ bundle +``` + +Once you have the dependencies, verify the unit tests pass with `rake`: + +``` +$ bundle exec rake +``` + +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-aws" +``` +Use bundler to execute Vagrant: +``` +$ bundle exec vagrant up --provider=aws +``` diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..d4347e1 --- /dev/null +++ b/Rakefile @@ -0,0 +1,21 @@ +require 'rubygems' +require 'bundler/setup' +require 'rspec/core/rake_task' + +# 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 + +# Install the `spec` task so that we can run tests. +RSpec::Core::RakeTask.new + +# Default task is to run the unit tests +task :default => "spec" diff --git a/lib/vagrant-xenserver.rb b/lib/vagrant-xenserver.rb new file mode 100644 index 0000000..397d389 --- /dev/null +++ b/lib/vagrant-xenserver.rb @@ -0,0 +1,16 @@ +require "pathname" + +require "vagrant-xenserver/plugin" + +module VagrantPlugins + module XenServer + lib_path = Pathname.new(File.expand_path("../vagrant-xenserver", __FILE__)) + autoload :Action, lib_path.join("action") + autoload :Errors, lib_path.join("errors") + + def self.source_root + @source_root ||= Pathname.new(File.expand_path("../../", __FILE__)) + end + end +end + diff --git a/lib/vagrant-xenserver/action.rb b/lib/vagrant-xenserver/action.rb new file mode 100644 index 0000000..3370730 --- /dev/null +++ b/lib/vagrant-xenserver/action.rb @@ -0,0 +1,21 @@ +require 'vagrant/action/builder' +require 'log4r' + +module VagrantPlugins + module XenServer + module Action + include Vagrant::Action::Builtin + @logger = Log4r::Logger.new('vagrant_xenserver::action') + + def self.action_up + Vagrant::Action::Builder.new.tap do |b| + b.use DummyMessage + end + end + + action_root = Pathname.new(File.expand_path('../action', __FILE__)) + autoload :DummyMessage, action_root.join('dummy') + end + end +end + diff --git a/lib/vagrant-xenserver/action/dummy.rb b/lib/vagrant-xenserver/action/dummy.rb new file mode 100644 index 0000000..3eb728e --- /dev/null +++ b/lib/vagrant-xenserver/action/dummy.rb @@ -0,0 +1,16 @@ +module VagrantPlugins + module XenServer + module Action + class DummyMessage + def initialize(app, env) + @app = app + end + + def call(env) + env[:ui].info("dummy") + end + end + end + end +end + diff --git a/lib/vagrant-xenserver/config.rb b/lib/vagrant-xenserver/config.rb new file mode 100644 index 0000000..174406d --- /dev/null +++ b/lib/vagrant-xenserver/config.rb @@ -0,0 +1,17 @@ +require "vagrant" + +module VagrantPlugins + module AWS + class Config < Vagrant.plugin("2", :config) + attr_accessor :dummy + + def initialize + @dummy = UNSET_VALUE + end + + def finalize! + @dummy = 0 if @dummy == UNSET_VALUE + end + end + end +end diff --git a/lib/vagrant-xenserver/plugin.rb b/lib/vagrant-xenserver/plugin.rb new file mode 100644 index 0000000..50491e8 --- /dev/null +++ b/lib/vagrant-xenserver/plugin.rb @@ -0,0 +1,28 @@ +begin + require "vagrant" +rescue LoadError + raise "The Vagrant XenServer plugin must be run within Vagrant." +end + +module VagrantPlugins + module XenServer + class Plugin < Vagrant.plugin("2") + name "XenServer provider" +# description <<-DESC +# This plugin installs a provider that allows Vagrant to manage +# virtual machines hosted on a XenServer. +# DESC + +# config(:xs, :provider) do +# require_relative "config" +# Config +# end +# +# provider(:xs) do +# require_relative "provider" +# Provider +# end + end + end +end + diff --git a/lib/vagrant-xenserver/provider.rb b/lib/vagrant-xenserver/provider.rb new file mode 100644 index 0000000..0b5db38 --- /dev/null +++ b/lib/vagrant-xenserver/provider.rb @@ -0,0 +1,28 @@ +require "vagrant" + +module VagrantPlugins + module XenServer + class Provider < Vagrant.plugin("2", :provider) + def initialize(machine) + @machine = machine + end + + def action(name) + nil + end + + def ssh_info + return nil + end + + def state + return nil + end + + def to_s + return nil + end + end + end +end + diff --git a/lib/vagrant-xenserver/version.rb b/lib/vagrant-xenserver/version.rb new file mode 100644 index 0000000..9fa7c63 --- /dev/null +++ b/lib/vagrant-xenserver/version.rb @@ -0,0 +1,6 @@ +module VagrantPlugins + module XenServer + VERSION = "0.1.0" + end +end + diff --git a/vagrant-xenserver.gemspec b/vagrant-xenserver.gemspec new file mode 100644 index 0000000..ee0a877 --- /dev/null +++ b/vagrant-xenserver.gemspec @@ -0,0 +1,24 @@ +$:.unshift File.expand_path("../lib", __FILE__) +require "vagrant-xenserver/version" + +Gem::Specification.new do |s| + s.name = "vagrant-xenserver" + s.version = VagrantPlugins::XenServer::VERSION + s.platform = Gem::Platform::RUBY + s.license = "MIT" + s.authors = "Jon Ludlam" + s.email = "jonathan.ludlam@citrix.com" + s.homepage = "http://www.xenserver.org" + s.summary = "Enables Vagrant to manage XenServers." + s.description = "Enables Vagrant to manage XenServers." + + s.add_development_dependency "rake" + + s.files = `git ls-files`.split($\) + s.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } + s.test_files = gem.files.grep(%r{^(test|spec|features)/}) + s.name = 'vagrant-libvirt' + s.require_paths = ['lib'] + s.version = VagrantPlugins::ProviderLibvirt::VERSION + +end