From 29811656613c2e7b058f899a43a1ae9b77dc07d5 Mon Sep 17 00:00:00 2001 From: Larry Gilbert Date: Thu, 4 Dec 2014 18:41:36 -0800 Subject: [PATCH 1/2] Move default values out of Vagrantfile; check more env variables Putting the defaults in the provider plugin gives it a chance to set up default values before a Vagrant box has been downloaded and installed. Also, some new environment variables are checked now, which are taken from Joyent's SmartDataCenter CLI tools. The traditional environment variables are checked and still take precedence. Config value | Original env vars | New env vars --------------+-------------------------------+-------------- username | JOYENT_USERNAME | SDC_ACCOUNT keyname | (n/a) | SDC_KEY_ID keyfile | JOYENT_SSH_PRIVATE_KEY_PATH | SDC_KEY password | JOYENT_PASSWORD | (n/a) api_url | JOYENT_API_URL | SDC_URL --- basebox/joyent-base64/Vagrantfile | 10 ---------- lib/vagrant-joyent/config.rb | 30 ++++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/basebox/joyent-base64/Vagrantfile b/basebox/joyent-base64/Vagrantfile index 9a6e792..89efb29 100644 --- a/basebox/joyent-base64/Vagrantfile +++ b/basebox/joyent-base64/Vagrantfile @@ -6,16 +6,6 @@ Vagrant.configure("2") do |config| # base64 1.9.0 joyent.dataset = "ff86eb8a-a069-11e3-ae0e-4f3c8983a91c" - joyent.username = ENV["JOYENT_USERNAME"] - joyent.password = ENV["JOYENT_PASSWORD"] - joyent.api_url = ENV["JOYENT_API_URL"] or "https://us-east-1.api.joyentcloud.com" - - joyent.flavor = "Small 1GB" - - joyent.node_name = "vagrant-joyent" - joyent.ssh_username = "root" - joyent.keyfile = ENV["JOYENT_SSH_PRIVATE_KEY_PATH"] - joyent.provision_chef = false end end diff --git a/lib/vagrant-joyent/config.rb b/lib/vagrant-joyent/config.rb index fdb8ca6..a65ae10 100644 --- a/lib/vagrant-joyent/config.rb +++ b/lib/vagrant-joyent/config.rb @@ -34,20 +34,34 @@ def initialize(datacenter_specific=false) def finalize! # API - @username = nil if @username == UNSET_VALUE - @password = nil if @username == UNSET_VALUE - @keyname = nil if @keyname == UNSET_VALUE - @keyfile = nil if @keyfile == UNSET_VALUE - @api_url = nil if @api_url == UNSET_VALUE + if @username == UNSET_VALUE + @username = ENV['JOYENT_USERNAME'] || ENV['SDC_ACCOUNT'] || nil + end + + if @keyname == UNSET_VALUE + @keyname = ENV['SDC_KEY_ID'] || nil + end + + if @keyfile == UNSET_VALUE + @keyfile = ENV['JOYENT_SSH_PRIVATE_KEY_PATH'] || ENV['SDC_KEY'] || nil + end + + if @password == UNSET_VALUE + @password = ENV['JOYENT_PASSWORD'] || nil + end + + if @api_url == UNSET_VALUE + @api_url = ENV['JOYENT_API_URL'] || ENV['SDC_URL'] || 'https://us-east-1.api.joyentcloud.com' + end # SSL @ssl_verify_peer = true if @ssl_verify_peer = UNSET_VALUE # Machines @dataset = nil if @dataset == UNSET_VALUE - @flavor = "Small 1GB" if @instance_type == UNSET_VALUE - @node_name = nil if @node_name == UNSET_VALUE - @ssh_username = nil if @ssh_username == UNSET_VALUE + @flavor = 'Small 1GB' if @flavor == UNSET_VALUE + @node_name = 'vagrant-joyent' if @node_name == UNSET_VALUE + @ssh_username = 'root' if @ssh_username == UNSET_VALUE end def validate(machine) From f8025675dfa4bb6939270e9c958e3e1cb89cb34b Mon Sep 17 00:00:00 2001 From: Larry Gilbert Date: Fri, 5 Dec 2014 12:32:14 -0800 Subject: [PATCH 2/2] Expand configuration info in README --- README.md | 61 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index b71f736..4990b24 100644 --- a/README.md +++ b/README.md @@ -23,28 +23,55 @@ Vagrantfile to use with Joyent: $ vagrant init apetresc/joyent-base64 -Before launching an instance, you must configure your environment with -your Joyent credentials. The following environment variables exist: - - * `JOYENT_USERNAME` (_required_): The Joyent account to create - instances on behalf of. - * `JOYENT_SSH_PRIVATE_KEY_PATH` (_optional_): A local path to the - private key file corresponding to a public key associated with the - Joyent account. If it's not specified, you will probably be unable - to SSH into a newly-launched instance. - * `JOYENT_PASSWORD` (_optional_): The Joyent account password. Only - required if `JOYENT_SSH_PRIVATE_KEY_PATH` is not provided. - * `JOYENT_API_URL` (_optional_): The API endpoint to use. This - corresponds to the Joyent region the instances will be created in. - Defaults to `https://us-east-1.api.joyentcloud.com`. - -You probably want to set these in your shell's profile (`~/.bashrc`, -`~/.zshrc`, etc.) and restart your shell. +Change the configuration as appropriate (see "Configuration" section). To launch a new instance, use: $ vagrant up --provider=joyent +## Configuration + +You may add Joyent-specific configuration to your Vagrantfile like this: + +```ruby + config.vm.provider :joyent do |joyent| + joyent.username = 'my_example_account' + joyent.api_url = 'https://us-east-1.api.joyentcloud.com' + end +``` + +Some variables are required, others are optional. Most of them (including the +required one) may be set in your environment as environment variables (they are +shown below in all caps: `LIKE_THIS`). + +### username + * _required_ (no default value) + * The Joyent account to create instances on behalf of. + +### api_url + * _optional_ (default: `JOYENT_API_URL`, `SDC_URL`, or + "https://us-east-1.api.joyentcloud.com") + * Corresponds to the Joyent region the instances will be created in. + +### keyfile + * _optional_ (default: value of `JOYENT_SSH_PRIVATE_KEY_PATH` or `SDC_KEY` + * A local path to the private SSH key file + corresponding to a public key associated with the Joyent account. If it's + not specified, you will probably be unable to SSH into a newly-launched + instance. + +### keyname + * _optional_ (default: value of `SDC_KEY_ID`) + * The ID of the SSH key, if there is more than + one associated with your Joyent account. In reality, this is the SSH + key's fingerprint (16 octets, hexadecimal, comma-delimited: + xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx). + +### password + * _not recommended_ (default: `JOYENT_PASSWORD`; environment variable is + preferable for obvious security reasons) + * The Joyent account password. Only required if `keyfile` is not provided. + ## Contributing 1. Fork it