Represent a generic resource available on the market
The API used to manage this resource
Creation date (CO favours Unix Timestamp)
Has the resource been deleted?
The time the resource was deleted (Unix Timestamp)
A user description of the resource
Is the resource active?
A simple label to identify the resource
The local (supplier) resource id
Location city
Location country
Descriptor of the location NOTE - do we want (in the future) a more explicit location definition?
Location region
The market assigned id
Transaction ID
The resource type
User id of creator
User.local_id of creator
All resources shall share the same namespace
# File lib/onapp_market/resource.rb, line 63 def self.namespace Resource::TYPE end
Create a new resource
hash - Hash of attributes to apply
type - type for serialization help
# File lib/onapp_market/resource.rb, line 54 def initialize(hash = {}, type = nil) super(hash, type) # Restrict access restrict [:user_id,:user_local_id], :admin restrict [:local_id, :transaction_id], [:admin, :supplier, :ro_admin] end
Activate a market resource
OnappMarket::API::Response - Response
supplier, admin
# File lib/onapp_market/resource.rb, line 73 def activate @api.get("/resource/#{self.resource_id.url_safe}/activate") end
Deactivate an OnApp CP resource
OnappMarket::API::Response - Response
supplier, admin
# File lib/onapp_market/resource.rb, line 84 def deactivate @api.get("/resource/#{self.resource_id.url_safe}/deactivate") end
Get the billing statistics for a resource for a given time period
start_date - Date - start date
end_date - Date - end date
period - Billing period: hourly|daily|monthly
OnappMarket::API::Response - object/hash of JSON billing data if is_ok?
supplier, admin
# File lib/onapp_market/resource.rb, line 169 def get_billing_data(start_date, end_date, period = :daily) @api.get("/resource/#{self.resource_id.url_safe}/billing", {:start => start_date.rfc3339, :end => end_date.rfc3339, :period => period.to_s}) end
Get a list of instances provisioned on this ‘resource’ by the market
filter - hash of exact attributes mathces. In the future we
may add search_instances for more flexible access.
detail - List of ids (false) or objects (true)
OnappMarket::API::Response - data will contain an Array of instance_ids if is_ok?
supplier, admin
# File lib/onapp_market/resource.rb, line 141 def get_instances(filter = {}, detail = false) @api.get("/resource/#{self.resource_id.url_safe}/instances", {:filter => filter, :detail => detail}, detail) end
Get the pricing for this resource
OnappMarket::API::Response - data contains OnappMarket::Base::Pricing if is_ok?
supplier, trader, admin
# File lib/onapp_market/resource.rb, line 104 def get_pricing @api.get("/resource/#{self.resource_id.url_safe}/pricing") end
Get the status of this resource
OnappMarket::API::Response - data contains 'hash' of status elements if is_ok?
supplier, trader, admin
# File lib/onapp_market/resource.rb, line 114 def get_status @api.get("/resource/#{self.resource_id.url_safe}/status") end
Remove an OnApp CP resource from the federated market
OnappMarket::API::Response - Response
supplier, admin
# File lib/onapp_market/resource.rb, line 94 def remove @api.delete("/resource/#{self.resource_id.url_safe}") end
Submit a notice against a resource
summary - Summary or title of the notice - trimmed to 64
length
body - Detail or description of the notice - trimmed to 1024
length
OnappMarket::API::Response - message submitted if is_ok?
supplier, admin
# File lib/onapp_market/resource.rb, line 154 def submit_notice(summary, body) @api.post("/resource/#{self.resource_id.url_safe}/submit_notice", {:summary => summary, :body => body}) end
Update an OnApp CPs pricing information
pricing - OnappMarket::Pricing
Updates pricing information
OnappMarket::API::Response - Response
supplier, admin
# File lib/onapp_market/resource.rb, line 127 def update_pricing(pricing) # Post - will de-serialize and return response @api.put("/resource/#{self.resource_id.url_safe}/pricing", OnappMarket::API::Serialize.to_hash(pricing)) end