Project

abiquo-api

0.0
No commit activity in last 3 years
No release in over 3 years
Simple Abiquo API client
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
 Dependencies

Runtime

>= 0.43.0, ~> 0.43
>= 0.9.2, ~> 0.9.2
>= 0.10.0, ~> 0.10.0
>= 0.2.5, ~> 0.2
>= 0
>= 0.3.1, ~> 0.3.1
 Project Readme

Abiquo API client for Ruby

Basic API browsing and raw object manipulation for Ruby.

Installation

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

Client object

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).

Link object

Represents an Abiquo API Link. Issuing get on them will retrieve link destination. This allows for things like:

vapp = vdc.link(:virtualappliances).get.first

Generic model object

This is used to map Abiquo API objects.

Generic list

This is used to iterate over paginated lists.

Examples

Browse the API

Initialize connection

a = AbiquoAPI.new(:abiquo_api_url => 'https://10.60.13.40/api', 
                  :abiquo_username => "admin", 
                  :abiquo_password => "xabiquo")

Login call

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

Create a VDC using an existing one as reference

Initialize connection

a = AbiquoAPI.new(:abiquo_api_url => 'https://10.60.13.40/api', 
                  :abiquo_username => "admin", 
                  :abiquo_password => "xabiquo")

Create a Link object to issue a request

l = AbiquoAPI::Link.new(:href => '/api/cloud/virtualdatacenters', 
                        :type => 'application/vnd.abiquo.virtualdatacenters+json',
                        :client => a)

Get on the link

v = l.get.first

Create a new object

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")

Create a link where to post data

l1 = AbiquoAPI::Link.new(:href => '/api/cloud/virtualdatacenters', 
                         :type => 'application/vnd.abiquo.virtualdatacenter+json')

Post data

v2 = a.post(l1, v1)

Modify the created object

v2.name = "SomeValue"
v2 = a.put(v2.edit, v2)

Or:

v2.name = "SomeValue"
v2.update

Delete it

a.delete(v2.edit)

Or:

v2.delete