abiquo-api 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '081649fb6f2d19e5513bf3b9882819c30d16bbd1'
4
- data.tar.gz: 63a0c58e1add09477c713902fa2d635469ddf599
3
+ metadata.gz: de18c834f09d7c9d5de6d66bf6bdeab3cf6411d2
4
+ data.tar.gz: 3452aabc8d21f916d95d433d4f8a7e13832b007e
5
5
  SHA512:
6
- metadata.gz: abe73a4ea3d1aa60337299cd9b956f0033e63cdf2c7118319180b5e93d93946d41624a3ac6e8b3087f1d09422034c542d2b285c39508bd5dc2353f399f05175f
7
- data.tar.gz: 76853b77d605f04a5fbe0f48b934944ba4492a4934d2df7b4194d34c1b86005467a5ca7f5a318c3b68773549841a158509f893d486015457fe64e4a8fe0ca455
6
+ metadata.gz: 3f058fd0c5fa53fb3eb7b18b86dff51c28f36086e5044cceeaf62bfbfa9203119b188ed176af5c797b2b722c4bdc254ac9339e50dc0d60fc1069a565148f1369
7
+ data.tar.gz: 8dcd5f3d1ff42318a24aec23fac631a665b9f0ebcc0f290abb59f9c072f448dc2087ed09a23d56bfe96003509bc4ab91fc21e1d16aa193593612f64ddbf84b27
data/README.md CHANGED
@@ -68,24 +68,23 @@ abq = AbiquoAPI.new(:abiquo_api_url => 'https://10.60.13.40/api',
68
68
  Then you can start browsing the API:
69
69
 
70
70
  ```ruby
71
- l = AbiquoAPI::Link.new(:href => '/api/cloud/virtualdatacenters',
72
- :type => 'application/vnd.abiquo.virtualdatacenters+json',
73
- :client => abq)
71
+ l = AbiquoAPI::Link.new(:href => 'cloud/virtualdatacenters',
72
+ :type => 'application/vnd.abiquo.virtualdatacenters+json',
73
+ :client => abq)
74
74
 
75
75
  l.get
76
76
  ```
77
77
 
78
78
  ## Client object
79
79
 
80
- The client object contains 3 objects that allow API browsing.
80
+ The client object contains 2 methods that allow API browsing.
81
81
 
82
- - **user.** The user object returned by the ```/api/login``` call.
83
- - **enterprise.** The user's enterprise link to be used in new objects.
84
- - **properties.** A hash containing all the system properties in the system. Useful to get default values for some objects (ie. VLAN parameters in VDC creation).
82
+ - **login** Makes the `login` API call, returning the current user information. From there you can navigate to related objects.
83
+ - **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).
85
84
 
86
85
  ## Link object
87
86
 
88
- Represents an Abiquo API Link. Issuing ```get``` on them will retrieve link destination. This allows for things like:
87
+ Represents an Abiquo API Link. Issuing `get` on them will retrieve link destination. This allows for things like:
89
88
 
90
89
  ```ruby
91
90
  vapp = vdc.link(:virtualappliances).get.first
@@ -107,19 +106,19 @@ This is used to iterate over paginated lists.
107
106
 
108
107
  ```ruby
109
108
  a = AbiquoAPI.new(:abiquo_api_url => 'https://10.60.13.40/api',
110
- :abiquo_username => "admin",
111
- :abiquo_password => "xabiquo")
109
+ :abiquo_username => "admin",
110
+ :abiquo_password => "xabiquo")
112
111
  ```
113
112
 
114
113
 
115
- #### User object
114
+ #### Login call
116
115
 
117
116
  Is the User object returned by the API at login. You can browse the links provided like:
118
117
 
119
118
  ```ruby
120
- a.user
119
+ user = a.login
121
120
 
122
- vm = a.user.link(:virtualmachines).get.first
121
+ vm = user.link(:virtualmachines).get.first
123
122
 
124
123
  vm.name
125
124
  => "ABQ_6b6d9856-c05f-425e-8916-1ff7de1683e3"
@@ -134,21 +133,22 @@ vm.id
134
133
 
135
134
  ```ruby
136
135
  a = AbiquoAPI.new(:abiquo_api_url => 'https://10.60.13.40/api',
137
- :abiquo_username => "admin",
138
- :abiquo_password => "xabiquo")
136
+ :abiquo_username => "admin",
137
+ :abiquo_password => "xabiquo")
139
138
  ```
140
139
 
141
140
  #### Create a Link object to issue a request
142
141
 
143
142
  ```ruby
144
143
  l = AbiquoAPI::Link.new(:href => '/api/cloud/virtualdatacenters',
145
- :type => 'application/vnd.abiquo.virtualdatacenters+json')
144
+ :type => 'application/vnd.abiquo.virtualdatacenters+json',
145
+ :client => a)
146
146
  ```
147
147
 
148
148
  #### Get on the link
149
149
 
150
150
  ```ruby
151
- v = a.get(l).first
151
+ v = l.get.first
152
152
  ```
153
153
 
154
154
  #### Create a new object
@@ -167,7 +167,7 @@ v1.vlan.delete("tag")
167
167
 
168
168
  ```ruby
169
169
  l1 = AbiquoAPI::Link.new(:href => '/api/cloud/virtualdatacenters',
170
- :type => 'application/vnd.abiquo.virtualdatacenter+json')
170
+ :type => 'application/vnd.abiquo.virtualdatacenter+json')
171
171
  ```
172
172
 
173
173
  #### Post data
@@ -82,24 +82,13 @@ class AbiquoAPI
82
82
  credentials,
83
83
  connection_options)
84
84
 
85
- api_path = URI.parse(api_url).path
86
-
87
- loginresp = @http_client.request(
88
- :expects => [200],
89
- :method => 'GET',
90
- :path => "#{api_path}/login",
91
- :accept => 'application/vnd.abiquo.user+json'
92
- )
93
- @enterprise = AbiquoAPIClient::Link.new(loginresp['links'].select {|l| l['rel'] == 'enterprise'}.first)
94
- @user = AbiquoAPIClient::LinkModel.new(loginresp.merge({:client => self}))
95
-
96
85
  if options.has_key? :version
97
86
  @version = options[:version][0..2]
98
87
  else
99
88
  @version = @http_client.request(
100
89
  :expects => [200],
101
90
  :method => 'GET',
102
- :path => "#{api_path}/version",
91
+ :path => "version",
103
92
  :accept => 'text/plain'
104
93
  ).delete("\n")[0..2]
105
94
  end
@@ -107,6 +96,21 @@ class AbiquoAPI
107
96
  self
108
97
  end
109
98
 
99
+ ##
100
+ # Performs a `login` call to Abiquo to retrieve
101
+ # user related info
102
+ #
103
+ def login
104
+ loginresp = @http_client.request(
105
+ :expects => [200],
106
+ :method => 'GET',
107
+ :path => "login",
108
+ :accept => 'application/vnd.abiquo.user+json'
109
+ )
110
+ @enterprise = AbiquoAPIClient::Link.new(loginresp['links'].select {|l| l['rel'] == 'enterprise'}.first)
111
+ @user = AbiquoAPIClient::LinkModel.new(loginresp.merge({:client => self}))
112
+ end
113
+
110
114
  ##
111
115
  # Loads System properties
112
116
  #
@@ -114,7 +118,7 @@ class AbiquoAPI
114
118
  @http_client.request(
115
119
  :expects => [200],
116
120
  :method => 'GET',
117
- :path => "#{api_path}/config/properties",
121
+ :path => "config/properties",
118
122
  :accept => 'application/vnd.abiquo.systemproperties+json'
119
123
  )
120
124
  end
@@ -212,7 +216,7 @@ class AbiquoAPI
212
216
  req_hash[:content] = "#{ctype}; version=#{@version};" unless ctype.eql? ""
213
217
 
214
218
  resp = @http_client.request(req_hash)
215
- resp.nil? ? nil : AbiquoAPIClient::LinkModel.new({ :client => self}.merge(resp))
219
+ resp.nil? ? nil : AbiquoAPIClient::LinkModel.new({:client => self}.merge(resp))
216
220
  end
217
221
 
218
222
  ##
@@ -249,7 +253,7 @@ class AbiquoAPI
249
253
  req_hash[:content] = "#{ctype}; version=#{@version};" unless ctype.eql? ""
250
254
 
251
255
  resp = @http_client.request(req_hash)
252
- resp.nil? ? nil : AbiquoAPIClient::LinkModel.new({ :client => self}.merge(resp))
256
+ resp.nil? ? nil : AbiquoAPIClient::LinkModel.new({:client => self}.merge(resp))
253
257
  end
254
258
 
255
259
  ##
@@ -264,12 +268,12 @@ class AbiquoAPI
264
268
  # Returns nil
265
269
  #
266
270
  def delete(link, options = {})
267
- @http_client.request(
268
- :expects => [204],
271
+ resp = @http_client.request(
272
+ :expects => [204,202],
269
273
  :method => 'DELETE',
270
274
  :path => link.href,
271
275
  :query => options
272
276
  )
273
- nil
277
+ resp.nil? ? nil : AbiquoAPIClient::LinkModel.new({:client => self}.merge(resp))
274
278
  end
275
279
  end
@@ -1,3 +1,3 @@
1
1
  module AbiquoAPIClient
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abiquo-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc Cirauqui
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-13 00:00:00.000000000 Z
11
+ date: 2017-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon