Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move configuration defaults out of base-box definition and into plugin #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 44 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions basebox/joyent-base64/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 22 additions & 8 deletions lib/vagrant-joyent/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down