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
- #_id ⇒ Object
-
#client ⇒ Object
TODO: ManageIQ uses a non RESTful message format def save res = client.save self self.id = ActiveSupport::JSON.decode(res)[‘id’] unless res.blank? true rescue RestClient::UnprocessableEntity => e self.errors = ActiveSupport::JSON.decode(e.response) false end.
- #destroy ⇒ Object
- #initialize ⇒ Object
- #path ⇒ Object
- #resource_name ⇒ Object
- #to_json ⇒ Object
- #to_payload ⇒ Object
Methods included from ManageIQClient
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
#_id ⇒ Object
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 |
#client ⇒ Object
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 |
#destroy ⇒ Object
66 67 68 |
# File 'app/models/manage_iq_client/resource.rb', line 66 def destroy client.destroy self end |
#initialize ⇒ Object
37 38 39 |
# File 'app/models/manage_iq_client/resource.rb', line 37 def initialize @errors = [] end |
#path ⇒ Object
78 79 80 |
# File 'app/models/manage_iq_client/resource.rb', line 78 def path [self.class.path, id].join '/' end |
#resource_name ⇒ Object
70 71 72 |
# File 'app/models/manage_iq_client/resource.rb', line 70 def resource_name self.class.to_s.demodulize.underscore end |
#to_json ⇒ Object
74 75 76 |
# File 'app/models/manage_iq_client/resource.rb', line 74 def to_json { resource_name => attributes }.to_json end |
#to_payload ⇒ Object
61 62 63 64 |
# File 'app/models/manage_iq_client/resource.rb', line 61 def to_payload attributes # { resource_name => attributes } end |