Module: Deltacloud::Client::Methods::Common

Included in:
Connection, Firewall, Instance, StorageVolume
Defined in:
lib/deltacloud/client/methods/common.rb

Instance Method Summary collapse

Instance Method Details

#create_resource(resource_name, create_opts = {}) ⇒ Object

A generic method for creating a new resources

  • resource_name -> A resource name to create (eg. :image)

  • create_opts -> HTTP options to pass into the create operation



25
26
27
28
29
30
31
32
# File 'lib/deltacloud/client/methods/common.rb', line 25

def create_resource(resource_name, create_opts={})
  no_convert_model = create_opts.delete(:no_convert_model)
  must_support! resource_name.to_s.pluralize
  response = connection.post(api_uri(resource_name.to_s.pluralize)) do |request|
    request.params = create_opts
  end
  no_convert_model ? response : model(resource_name).convert(self, response.body)
end

#destroy_resource(resource_name, resource_id) ⇒ Object

A generic method for destroying resources



36
37
38
39
40
41
42
# File 'lib/deltacloud/client/methods/common.rb', line 36

def destroy_resource(resource_name, resource_id)
  must_support! resource_name.to_s.pluralize
  result = connection.delete(
    api_uri([resource_name.to_s.pluralize, resource_id].join('/'))
  )
  result.status.is_no_content?
end