Basic API browsing and raw object manipulation for Ruby.
To get the client installed just issue:
gem install abiquo-api
Or if you are using a Gemfile, add:
gem 'abiquo-api'
An example usage would be:
require 'abiquo-api'
a = AbiquoAPI.new(:abiquo_api_url => 'https://10.60.13.40/api',
:abiquo_username => "admin",
:abiquo_password => "xabiquo")
Or, if you want to force a specific API version:
require 'abiquo-api'
abq = AbiquoAPI.new(:abiquo_api_url => 'https://10.60.13.40/api',
:abiquo_username => "admin",
:abiquo_password => "xabiquo",
:version => "2.9")
You can also define some connection parameters that will be applied to the underlying Faraday HTTP connection:
require 'abiquo-api'
abq = AbiquoAPI.new(:abiquo_api_url => 'https://10.60.13.40/api',
:abiquo_username => "admin",
:abiquo_password => "xabiquo",
:connection_options => {
:ssl => {
:verify => false
}
})
Or, you can also use OAuth credentials:
require 'abiquo-api'
abq = AbiquoAPI.new(:abiquo_api_url => 'https://10.60.13.40/api',
:abiquo_api_key => "somekey",
:abiquo_api_secret => "somesecret",
:abiquo_token_key => "sometoken",
:abiquo_token_secret => "sometokensecret",
:connection_options => {
:ssl => {
:verify => false
}
})
Then you can start browsing the API:
l = AbiquoAPI::Link.new(:href => 'cloud/virtualdatacenters',
:type => 'application/vnd.abiquo.virtualdatacenters+json',
:client => abq)
l.get
The client object contains 2 methods that allow API browsing.
- login Makes the
login
API call, returning the current user information. From there you can navigate to related objects. - properties Makes the
config/properties
call and returns a hash containing all the system properties in the system. Useful to get default values for some objects (ie. VLAN parameters in VDC creation).
Represents an Abiquo API Link. Issuing get
on them will retrieve link destination. This allows for things like:
vapp = vdc.link(:virtualappliances).get.first
This is used to map Abiquo API objects.
This is used to iterate over paginated lists.
a = AbiquoAPI.new(:abiquo_api_url => 'https://10.60.13.40/api',
:abiquo_username => "admin",
:abiquo_password => "xabiquo")
Is the User object returned by the API at login. You can browse the links provided like:
user = a.login
vm = user.link(:virtualmachines).get.first
vm.name
=> "ABQ_6b6d9856-c05f-425e-8916-1ff7de1683e3"
vm.id
=> 18
a = AbiquoAPI.new(:abiquo_api_url => 'https://10.60.13.40/api',
:abiquo_username => "admin",
:abiquo_password => "xabiquo")
l = AbiquoAPI::Link.new(:href => '/api/cloud/virtualdatacenters',
:type => 'application/vnd.abiquo.virtualdatacenters+json',
:client => a)
v = l.get.first
v1 = a.new_object(:name => "vdctest",
:hypervisorType => "VMX_04",
:vlan => v.vlan,
:links => [v.link(:location), a.enterprise])
v1.vlan.delete("links")
v1.vlan.delete("id")
v1.vlan.delete("tag")
l1 = AbiquoAPI::Link.new(:href => '/api/cloud/virtualdatacenters',
:type => 'application/vnd.abiquo.virtualdatacenter+json')
v2 = a.post(l1, v1)
v2.name = "SomeValue"
v2 = a.put(v2.edit, v2)
Or:
v2.name = "SomeValue"
v2.update
a.delete(v2.edit)
Or:
v2.delete