1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
# vagrant_cloud
Ruby client for the [Vagrant Cloud API](https://www.vagrantup.com/docs/vagrant-cloud/api.html).
[](https://rubygems.org/gems/vagrant_cloud)
This library provides the functionality to create, modify, and delete boxes, versions,
and providers on Vagrant Cloud.
## Usage
The Vagrant Cloud library provides two methods for interacting with the Vagrant Cloud API. The
first is direct interaction using a `VagrantCloud::Client` instance. The second is a basic
model based approach using a `VagrantCloud::Account` instance.
### Direct Client
The `VagrantCloud::Client` class contains all the underlying functionality which with
`vagrant_cloud` library uses for communicating with Vagrant Cloud. It can be used directly
for quickly and easily sending requests to Vagrant Cloud. The `VagrantCloud::Client`
class will automatically handle any configured authentication, request parameter
structuring, and response validation. All API related methods in the `VagrantCloud::Client`
class will return `Hash` results.
Example usage (display box details):
```ruby
require "vagrant_cloud"
client = VagrantCloud::Client.new(access_token: "MY_TOKEN")
box = client.box_get(username: "hashicorp", name: "bionic64")
puts "Box: #{box[:tag]} Description: #{box[:description]}"
```
Example usage (creating box and releasing a new version):
```ruby
require "vagrant_cloud"
require "net/http"
# Create a new client
client = VagrantCloud::Client.new(access_token: "MY_TOKEN")
# Create a new box
client.box_create(
username: "hashicorp",
name: "test-bionic64",
short_description: "Test Box",
long_description: "Testing box for an example",
is_private: false
)
# Create a new version
client.box_version_create(
username: "hashicorp",
name: "test-bionic64",
version: "1.0.0",
description: "Version 1.0.0 release"
)
# Create a new provider
client.box_version_provider_create(
username: "hashicorp",
name: "test-bionic64",
version: "1.0.0",
provider: "virtualbox"
)
# Request box upload URL
upload_url = client.box_version_provider_upload(
username: "hashicorp",
name: "test-bionic64",
version: "1.0.0",
provider: "virtualbox"
)
# Upload box asset
uri = URI.parse(upload_url[:upload_path])
request = Net::HTTP::Post.new(uri)
box = File.open(BOX_PATH, "rb")
request.set_form([["file", box]], "multipart/form-data")
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme.eql?("https")) do |http|
http.request(request)
end
# Release the version
client.box_version_release(
username: "hashicorp",
name: "test-bionic64",
version: "1.0.0"
)
```
### Simple Models
The `VagrantCloud::Account` class is the entry point for using simple models to
interact with Vagrant Cloud.
Example usage (display box details):
```ruby
require "vagrant_cloud"
account = VagrantCloud::Account.new(access_token: "MY_TOKEN")
org = account.organization(name: "hashicorp")
box = org.boxes.detect { |b| b.name == "bionic64" }
puts "Box: #{box[:tag]} Description: #{box[:description]}"
```
Example usage (creating box and releasing a new version):
```ruby
require "vagrant_cloud"
# Load our account
account = VagrantCloud::Account.new(access_token: "MY_TOKEN")
# Load organization
org = account.organization(name: "hashicorp")
# Create a new box
box = org.add_box("test-bionic64")
box.description = "Testing box for an example"
box.short_description = "Test Box"
# Create a new version
version = box.add_version("1.0.0")
version.description = "Version 1.0.0 release"
# Create a new provider
provider = version.add_provider("virtualbox")
# Save the box, version, and provider
box.save
# Upload box asset
provider.upload(path: BOX_PATH)
# Release the version
version.release
```
## Development & Contributing
Pull requests are very welcome!
Install dependencies:
```
bundle install
```
Run the tests:
```
bundle exec rspec
```
## Releasing
Release a new version:
1. Update the version in the `version.txt` file
1. Commit the change to master
1. Create a new version tag in git: `git tag vX.X.X`
1. Push the new tag and master to GitHub `git push origin main --tags`
The new release will be automatically built and published.
## History
- This gem was developed and maintained by [Cargo Media](https://www.cargomedia.ch) from April 2014 until October 2017.
- The `vagrant_cloud` CLI tool included in this RubyGem has been deprecated and removed. See `vagrant cloud` for a replacement.
|