class OnappMarket::Resource

Represent a generic resource available on the market

Constants

ID
TYPE

Attributes

api[RW]

The API used to manage this resource

created_at[RW]

Creation date (CO favours Unix Timestamp)

deleted[RW]

Has the resource been deleted?

deleted_at[RW]

The time the resource was deleted (Unix Timestamp)

description[RW]

A user description of the resource

is_active[RW]

Is the resource active?

label[RW]

A simple label to identify the resource

local_id[RW]

The local (supplier) resource id

location_city[RW]

Location city

location_country[RW]

Location country

location_name[RW]

Descriptor of the location NOTE - do we want (in the future) a more explicit location definition?

location_region[RW]

Location region

resource_id[RW]

The market assigned id

transaction_id[RW]

Transaction ID

type[R]

The resource type

user_id[RW]

User id of creator

user_local_id[RW]

User.local_id of creator

Public Class Methods

namespace() click to toggle source

All resources shall share the same namespace

# File lib/onapp_market/resource.rb, line 63
def self.namespace
  Resource::TYPE
end
new(hash = {}, type = nil) click to toggle source

Create a new resource

Attributes

  • 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

Public Instance Methods

activate() click to toggle source

Activate a market resource

Returns

Roles

supplier, admin

# File lib/onapp_market/resource.rb, line 73
def activate
  @api.get("/resource/#{self.resource_id.url_safe}/activate")
end
deactivate() click to toggle source

Deactivate an OnApp CP resource

Returns

Roles

supplier, admin

# File lib/onapp_market/resource.rb, line 84
def deactivate
  @api.get("/resource/#{self.resource_id.url_safe}/deactivate")
end
get_billing_data(start_date, end_date, period = :daily) click to toggle source

Get the billing statistics for a resource for a given time period

Attributes

  • start_date - Date - start date

  • end_date - Date - end date

  • period - Billing period: hourly|daily|monthly

Returns

Roles

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_instances(filter = {}, detail = false) click to toggle source

Get a list of instances provisioned on this ‘resource’ by the market

Attributes

  • 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)

Returns

Roles

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_pricing() click to toggle source

Get the pricing for this resource

Returns

Roles

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_status() click to toggle source

Get the status of this resource

Returns

Roles

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() click to toggle source

Remove an OnApp CP resource from the federated market

Returns

Roles

supplier, admin

# File lib/onapp_market/resource.rb, line 94
def remove
  @api.delete("/resource/#{self.resource_id.url_safe}")
end
submit_notice(summary, body) click to toggle source

Submit a notice against a resource

Attributes

  • summary - Summary or title of the notice - trimmed to 64 length

  • body - Detail or description of the notice - trimmed to 1024 length

Returns

Roles

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_pricing(pricing) click to toggle source

Update an OnApp CPs pricing information

Attributes

Returns

Roles

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