class OnappMarket::Trader

Trader Side OnApp Market API - Trader Functions

This is the API used by Trader to provision and manage resources on the OnApp Market, and subsequently control those resources.

Assumptions

It is assumed that any user of this API will have

Public Class Methods

new(api) click to toggle source

Create a new instance of Supplier API

Attributes

  • api - The API to communicate over

# File lib/onapp_market/trader.rb, line 26
def initialize(api)
  raise "No OnAppMarket API specified" if api == nil
  @api = api
end

Public Instance Methods

get_flavors(resource_id) click to toggle source

Get the flavors associated with the specified resource

Attributes

  • resource_id - The resource_id of the Compute resource

Returns

Roles

trader, admin

# File lib/onapp_market/trader.rb, line 131
def get_flavors(resource_id)
  @api.get("/compute/#{resource_id.url_safe}/flavors")
end
get_instance(instance_id) click to toggle source

Get a specific instance

Attributes

  • instance_id - instance id we wish to retrieve

Returns

Roles

trader, admin

# File lib/onapp_market/trader.rb, line 107
def get_instance(instance_id)
  @api.get("/instance/#{instance_id.url_safe}")
end
get_instance_billing_data(instance_id, start_date, end_date, period = :daily) click to toggle source

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

Attributes

  • instance_id - instance id of instance whose billing data we require

  • start_date - Date - start date

  • end_date - Date - end date

  • period - Billing period: hourly|daily|monthly

Returns

Roles

trader, admin

# File lib/onapp_market/trader.rb, line 67
def get_instance_billing_data(instance_id, start_date, end_date, period = :daily)
  @api.get("/instance/#{instance_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 by this user

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

trader, admin

# File lib/onapp_market/trader.rb, line 95
def get_instances(filter = {}, detail = false)
  @api.get("/instance", {:filter => filter, :detail => detail}, detail)
end
get_pricing(resource_id) click to toggle source

Get the pricing data for a specified resource

Attributes

  • resource_id - the resource id

Returns

Roles

trader, admin

# File lib/onapp_market/trader.rb, line 52
def get_pricing(resource_id)
  @api.get("/resource/#{resource_id.url_safe}/pricing")
end
get_resource(resource_id) click to toggle source

Get a resource

Attributes

  • resource_id - The resource id

Returns

Roles

trader, admin

# File lib/onapp_market/trader.rb, line 40
def get_resource(resource_id)
  @api.get("/resource/#{resource_id.to_s.url_safe}")
end
get_templates(resource_id) click to toggle source

Get the templates associated with the specified resource

Attributes

  • resource_id - The resource_id of the Compute resource

Returns

Roles

trader, admin

# File lib/onapp_market/trader.rb, line 119
def get_templates(resource_id)
  @api.get("/compute/#{resource_id.url_safe}/template")
end
get_user_billing_data(user_id, start_date, end_date, period = :daily) click to toggle source

Get a user’s billing statistics

Attributes

  • user_id - user id of user whose billing data we require

  • start_date - DateTime - start date

  • end_date - DateTime - end date

  • period - Billing period: hourly|daily|monthly

Returns

Roles

admin

# File lib/onapp_market/trader.rb, line 82
def get_user_billing_data(user_id, start_date, end_date, period = :daily)
  @api.get("/admin/user/#{user_id.url_safe}/billing", {:start => start_date.rfc3339, :end => end_date.rfc3339, :period => period.to_s})
end
provision(resource_id, instance) click to toggle source

Create a new resource on the market using a specified resource

Attributes

  • resource_id - The id of the resource

  • instance - The instance to be created

Returns

Roles

trader, admin

# File lib/onapp_market/trader.rb, line 144
def provision(resource_id, instance)
  @api.post("/instance", {:resource_id => resource_id, :instance => OnappMarket::API::Serialize.to_hash(instance)})
end
resource_get_notices(resource_id, start_date, end_date) click to toggle source

Get the notices for a resource for a given time period

Attributes

  • resource_id - resource id of resource whose notices we require

  • start_date - Date - start date

  • end_date - Date - end date

Returns

Roles

trader, admin

# File lib/onapp_market/trader.rb, line 196
def resource_get_notices(resource_id, start_date, end_date)
  @api.get("/resource/#{resource_id.to_s.url_safe}/notices", {:start_date => start_date.iso8601, :end_date => end_date.iso8601})
end
resource_notification_url(url) click to toggle source

Submit a URL that will receive notifications, for example, a hypervisor zone has been ‘deactivated’

Attributes

  • url - The url for the notifications

Returns

OnappMarket::API::Response - registered successfully if is_ok?

Roles

trader, admin

# File lib/onapp_market/trader.rb, line 182
def resource_notification_url(url)
  @api.post("/resource/notification_url", {:url => url})
end
resource_notifications_off(resource_id) click to toggle source

Request notifications are turned off for changes in a zone Assumes you have already set up a listener with notifications_url

Attributes

+ resource_id - The id of the zone you are no longer interested in

Returns

OnappMarket::API::Response - set if is_ok?

Roles

trader, admin

# File lib/onapp_market/trader.rb, line 170
def resource_notifications_off(resource_id)
  @api.get("/resource/#{resource_id.url_safe}/notifications_off")
end
resource_notifications_on(resource_id) click to toggle source

Request notifications as a trader for changes in a zone Assumes you have already set up a listener with notifications_url

Attributes

+ resource_id - The id of the zone you are interested in

Returns

OnappMarket::API::Response - set if is_ok?

Roles

trader, admin

# File lib/onapp_market/trader.rb, line 157
def resource_notifications_on(resource_id)
  @api.get("/resource/#{resource_id.url_safe}/notifications_on")
end
resource_subscribe(resource_id) click to toggle source

Indicate desire to subscribe to the specified resource

Attributes

+ resource_id - The id of the zone you are subscribing to

Returns

OnappMarket::API::Response - set if is_ok?

Roles

trader, admin

# File lib/onapp_market/trader.rb, line 208
def resource_subscribe(resource_id)
  @api.get("/resource/#{resource_id.url_safe}/subscribe")
end
resource_unsubscribe(resource_id) click to toggle source

Indicate desire to subscribe to the specified resource

Attributes

+ resource_id - The id of the zone you are subscribing to

Returns

OnappMarket::API::Response - set if is_ok?

Roles

trader, admin

# File lib/onapp_market/trader.rb, line 220
def resource_unsubscribe(resource_id)
  @api.get("/resource/#{resource_id.url_safe}/unsubscribe")
end