Module: ManageIQClient::Resource

Includes:
ManageIQClient
Included in:
Cluster, Datastore, Host, Policy, PolicyProfile, Provider, ResourcePool, Server, Service, ServiceCatalog, ServiceTemplate, Template, VirtualMachine, Zone
Defined in:
app/models/manage_iq_client/resource.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ManageIQClient

credentials=

Class Method Details

.included(base) ⇒ Object



7
8
9
10
11
12
13
# File 'app/models/manage_iq_client/resource.rb', line 7

def self.included(base)
  base.include Virtus.model
  base.extend ClassMethods
  base.cattr_accessor :path
  base.send(:attr_accessor, :errors)
  base.send(:attr_accessor, :id)
end

Instance Method Details

#_idObject



41
42
43
44
45
# File 'app/models/manage_iq_client/resource.rb', line 41

def _id
  id.split(path + '/')[-1].to_i
rescue
  id
end

#clientObject

TODO: ManageIQ uses a non RESTful message format def save

res = client.save self
self.id = ActiveSupport::JSON.decode(res)[resource_name]['id'] unless res.blank?
true

rescue RestClient::UnprocessableEntity => e

self.errors = ActiveSupport::JSON.decode(e.response)
false

end



57
58
59
# File 'app/models/manage_iq_client/resource.rb', line 57

def client
  self.class.client
end

#destroyObject



66
67
68
# File 'app/models/manage_iq_client/resource.rb', line 66

def destroy
  client.destroy self
end

#initializeObject



37
38
39
# File 'app/models/manage_iq_client/resource.rb', line 37

def initialize
  @errors = []
end

#pathObject



78
79
80
# File 'app/models/manage_iq_client/resource.rb', line 78

def path
  [self.class.path, id].join '/'
end

#resource_nameObject



70
71
72
# File 'app/models/manage_iq_client/resource.rb', line 70

def resource_name
  self.class.to_s.demodulize.underscore
end

#to_jsonObject



74
75
76
# File 'app/models/manage_iq_client/resource.rb', line 74

def to_json
  { resource_name => attributes }.to_json
end

#to_payloadObject



61
62
63
64
# File 'app/models/manage_iq_client/resource.rb', line 61

def to_payload
  attributes
  # { resource_name => attributes }
end