Class: Megam::API

Inherits:
Object
  • Object
show all
Defined in:
lib/megam/api.rb,
lib/megam/api/disks.rb,
lib/megam/api/addons.rb,
lib/megam/api/errors.rb,
lib/megam/api/promos.rb,
lib/megam/api/quotas.rb,
lib/megam/api/backups.rb,
lib/megam/api/credits.rb,
lib/megam/api/domains.rb,
lib/megam/api/flavors.rb,
lib/megam/api/license.rb,
lib/megam/api/reports.rb,
lib/megam/api/sensors.rb,
lib/megam/api/sshkeys.rb,
lib/megam/api/version.rb,
lib/megam/api/accounts.rb,
lib/megam/api/assembly.rb,
lib/megam/api/balances.rb,
lib/megam/api/eventsvm.rb,
lib/megam/api/requests.rb,
lib/megam/api/eventsall.rb,
lib/megam/api/rawimages.rb,
lib/megam/api/snapshots.rb,
lib/megam/api/assemblies.rb,
lib/megam/api/components.rb,
lib/megam/api/marketplaces.rb,
lib/megam/api/eventsbilling.rb,
lib/megam/api/eventsstorage.rb,
lib/megam/api/organizations.rb,
lib/megam/api/subscriptions.rb,
lib/megam/api/billedhistories.rb,
lib/megam/api/eventscontainer.rb,
lib/megam/api/eventsmarketplace.rb,
lib/megam/api/billingtransactions.rb

Defined Under Namespace

Modules: Errors

Constant Summary collapse

API_VERSION2 =
'/v2'.freeze
X_Megam_DATE =
'X-Megam-DATE'.freeze
X_Megam_HMAC =
'X-Megam-HMAC'.freeze
X_Megam_OTTAI =
'X-Megam-OTTAI'.freeze
X_Megam_ORG =
'X-Megam-ORG'.freeze
X_Megam_PUTTUSAVI =
'X-Megam-PUTTUSAVI'.freeze
X_Megam_MASTERKEY =
'X-Megam-MASTERKEY'.freeze
HEADERS =
{
    'Accept'          => 'application/json',
    'Accept-Encoding' => 'gzip',
    'User-Agent'      => "megam-api/#{Megam::API::VERSION}",
    'X-Ruby-Version'  => RUBY_VERSION,
    'X-Ruby-Platform' => RUBY_PLATFORM
}
OPTIONS =
{
    headers: {},
    nonblock: false
}
VERSION =
"1.52.6"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ API

Returns a new instance of API.



153
154
155
156
157
158
159
160
161
# File 'lib/megam/api.rb', line 153

def initialize(options = {})
    @options = OPTIONS.merge(options)

    assign_credentials

    ensure_host_is_flattened

    turn_off_ssl_verify
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



126
127
128
# File 'lib/megam/api.rb', line 126

def api_key
  @api_key
end

#api_urlObject

Returns the value of attribute api_url.



127
128
129
# File 'lib/megam/api.rb', line 127

def api_url
  @api_url
end

#api_versionObject

Returns the value of attribute api_version.



127
128
129
# File 'lib/megam/api.rb', line 127

def api_version
  @api_version
end

#emailObject

Returns the value of attribute email.



126
127
128
# File 'lib/megam/api.rb', line 126

def email
  @email
end

#last_responseObject (readonly)

Returns the value of attribute last_response.



129
130
131
# File 'lib/megam/api.rb', line 129

def last_response
  @last_response
end

#master_keyObject

Returns the value of attribute master_key.



128
129
130
# File 'lib/megam/api.rb', line 128

def master_key
  @master_key
end

#org_idObject

Returns the value of attribute org_id.



126
127
128
# File 'lib/megam/api.rb', line 126

def org_id
  @org_id
end

#password_hashObject

Returns the value of attribute password_hash.



126
127
128
# File 'lib/megam/api.rb', line 126

def password_hash
  @password_hash
end

#textObject

Returns the value of attribute text.



125
126
127
# File 'lib/megam/api.rb', line 125

def text
  @text
end

Instance Method Details

#delete_accounts(delete_account) ⇒ Object



61
62
63
64
65
66
67
68
69
70
# File 'lib/megam/api/accounts.rb', line 61

def delete_accounts()
  @options = {path: "/admin/accounts/#{["user_email"]}",
              :body => ''}.merge(@options)

   request(
   :expects  => 200,
   :method   => :delete,
   :body     => @options[:body]
   )
end

#delete_assemblies(asm_id) ⇒ Object

Yet to be tested DELETE /nodes/:node_id



37
38
39
40
41
42
43
44
45
46
# File 'lib/megam/api/assemblies.rb', line 37

def delete_assemblies(asm_id)
  @options = {:path => '/nodes/#{asm_id}',
    :body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :delete,
    :body     => @options[:body]
  )
end

#delete_assembly(id, asms_id) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/megam/api/assembly.rb', line 44

def delete_assembly(id, asms_id)
   @options = {path: "/admin/assembly/#{asms_id}/#{id}",
            :body => ''}.merge(@options)

   request(
   :expects  => 200,
   :method   => :delete,
   :body     => @options[:body]
  )
end

#delete_flavors(delete_flavors) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/megam/api/flavors.rb', line 44

def delete_flavors(delete_flavors)
  @options = {path: "/flavors/#{delete_flavors["name"]}",
              :body => ''}.merge(@options)

   request(
   :expects  => 201,
   :method   => :delete,
   :body     => @options[:body]
   )
end

#delete_marketplaceapp(catitem_id) ⇒ Object

Yet to be tested DELETE /marketplacess/:node_id



56
57
58
59
60
61
62
63
64
65
# File 'lib/megam/api/marketplaces.rb', line 56

def delete_marketplaceapp(catitem_id)
  @options = {:path => '/marketplaces/#{catitem_id}',
    :body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :delete,
    :body     => @options[:body]
  )
end

#forgot(account) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/megam/api/accounts.rb', line 50

def forgot()
  @options = { path:  "/accounts/forgot/#{["email"]}", passthru: true,
               body: ''}.merge(@options)

  request(
  :expects => 201,
  :method => :get,
  :body => @options[:body]
  )
end

#get_accounts(email) ⇒ Object

GET /accounts



4
5
6
7
8
9
10
11
12
13
# File 'lib/megam/api/accounts.rb', line 4

def get_accounts(email)
  @options = {:path => "/accounts/#{email}",
    :body => ''}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_addon(name) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/megam/api/addons.rb', line 5

def get_addon(name)
  @options = {:path => "/addons/#{name}",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_assembliesObject

GET /nodes



4
5
6
7
8
9
10
11
12
# File 'lib/megam/api/assemblies.rb', line 4

def get_assemblies
  @options = {:path => '/assemblies',:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_backups(asm_id) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/megam/api/backups.rb', line 14

def get_backups(asm_id)
    @options = {:path => "/backups/#{asm_id}",:body => ""}.merge(@options)

    request(
        :expects  => 200,
        :method   => :get,
        :body     => @options[:body]
    )
end

#get_balance(id) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/megam/api/balances.rb', line 13

def get_balance(id)
  @options = {:path => "/balances/#{id}",:body => Megam::JSONCompat.to_json(id)}.merge(@options)
  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_balancesObject



3
4
5
6
7
8
9
10
11
# File 'lib/megam/api/balances.rb', line 3

def get_balances
  @options = {:path => '/balances',:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_billedhistoriesObject



3
4
5
6
7
8
9
10
11
# File 'lib/megam/api/billedhistories.rb', line 3

def get_billedhistories
  @options = {:path => '/billedhistories',:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_billedhistory(id) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/megam/api/billedhistories.rb', line 13

def get_billedhistory(id)
  @options = {:path => "/billedhistories/#{id}",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_billingtransactionsObject



3
4
5
6
7
8
9
10
11
# File 'lib/megam/api/billingtransactions.rb', line 3

def get_billingtransactions
  @options = {:path => '/billingtransactions',:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_components(comp_id) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/megam/api/components.rb', line 3

def get_components(comp_id)
  @options = { path: "/components/#{comp_id}", body: '' }.merge(@options)

  request(
    expects: 200,
    method: :get,
    body: @options[:body]
  )
end

#get_credits(account_id) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/megam/api/credits.rb', line 13

def get_credits()
  @options = {:path => "/credits/#{}",:body => Megam::JSONCompat.to_json()}.merge(@options)
  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_disks(asm_id) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/megam/api/disks.rb', line 14

def get_disks(asm_id)
  @options = {:path => "/disks/#{asm_id}",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_domainsObject



5
6
7
8
9
10
11
12
# File 'lib/megam/api/domains.rb', line 5

def get_domains
  @options = {:path => "/domains", :body => ''}.merge(@options)
  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_eventsall(limit, new_events) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/megam/api/eventsall.rb', line 15

def get_eventsall(limit, new_events)
  @options = {:path => "/eventsall/show/#{limit}",
    :body => Megam::JSONCompat.to_json(new_events)}.merge(@options)
  request(
    :expects  => 200,
    :method   => :post,
    :body     => @options[:body]
  )
end

#get_eventsbilling(limit, new_events) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/megam/api/eventsbilling.rb', line 15

def get_eventsbilling(limit, new_events)
  @options = {:path => "/eventsbilling/show/#{limit}",
    :body => Megam::JSONCompat.to_json(new_events)}.merge(@options)
  request(
    :expects  => 200,
    :method   => :post,
    :body     => @options[:body]
  )
end

#get_eventscontainer(limit, new_events) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/megam/api/eventscontainer.rb', line 15

def get_eventscontainer(limit, new_events)
  @options = {:path => "/eventscontainer/show/#{limit}",
    :body => Megam::JSONCompat.to_json(new_events)}.merge(@options)
  request(
    :expects  => 200,
    :method   => :post,
    :body     => @options[:body]
  )
end

#get_eventsMarketplace(limit, new_events) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/megam/api/eventsmarketplace.rb', line 15

def get_eventsMarketplace(limit, new_events)
  @options = {:path => "/eventsmarketplace/show/#{limit}",
    :body => Megam::JSONCompat.to_json(new_events)}.merge(@options)
  request(
    :expects  => 200,
    :method   => :post,
    :body     => @options[:body]
  )
end

#get_eventsvm(limit, new_events) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/megam/api/eventsvm.rb', line 15

def get_eventsvm(limit, new_events)
  @options = {:path => "/eventsvm/show/#{limit}",
    :body => Megam::JSONCompat.to_json(new_events)}.merge(@options)
  request(
    :expects  => 200,
    :method   => :post,
    :body     => @options[:body]
  )
end

#get_flavorsObject



4
5
6
7
8
9
10
11
# File 'lib/megam/api/flavors.rb', line 4

def get_flavors()
    @options = {:path => "/flavors",:body => ""}.merge(@options)
    request(
        :expects  => 200,
        :method   => :get,
        :body     => @options[:body]
    )
end

#get_license(license_id) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/megam/api/license.rb', line 4

def get_license(license_id)
  @options = {:path => "/admin/licenses/#{license_id}",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_marketplaceapp(id) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/megam/api/marketplaces.rb', line 14

def get_marketplaceapp(id)
  @options = {:path => "/marketplaces/#{id}",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_marketplaceappsObject



4
5
6
7
8
9
10
11
12
# File 'lib/megam/api/marketplaces.rb', line 4

def get_marketplaceapps
  @options = {:path => '/marketplaces',:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_marketplaceflavor(flavor) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/megam/api/marketplaces.rb', line 34

def get_marketplaceflavor(flavor)
  @options = {:path => "/marketplaces/f/#{flavor}",:body => ""}.merge(@options)
  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_marketplaceprovider(provider) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/megam/api/marketplaces.rb', line 24

def get_marketplaceprovider(provider)
  @options = {:path => "/marketplaces/p/#{provider}" ,:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_one_assemblies(asm_id) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/megam/api/assemblies.rb', line 14

def get_one_assemblies(asm_id)
  @options = {:path => "/assemblies/#{asm_id}",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_one_assembly(asm_id) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/megam/api/assembly.rb', line 3

def get_one_assembly(asm_id)
  @options = { path: "/assembly/#{asm_id}", body: '' }.merge(@options)

  request(
    expects: 200,
    method: :get,
    body: @options[:body]
  )
end

#get_one_backup(backup_id) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/megam/api/backups.rb', line 24

def get_one_backup(backup_id)
    @options = {:path => "/backups/show/#{backup_id}",:body => ""}.merge(@options)

    request(
        :expects  => 200,
        :method   => :get,
        :body     => @options[:body]
    )
end

#get_one_flavor(id) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/megam/api/flavors.rb', line 13

def get_one_flavor(id)
  @options = { path: "/flavors/#{id}", body: '' }.merge(@options)

  request(
    expects: 200,
    method: :get,
    body: @options[:body]
  )
end

#get_one_quota(name) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/megam/api/quotas.rb', line 4

def get_one_quota(name)
  @options = { path: "/quotas/#{name}", body: '' }.merge(@options)

  request(
    expects: 200,
    method: :get,
    body: @options[:body]
  )
end

#get_one_rawimage(name) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/megam/api/rawimages.rb', line 4

def get_one_rawimage(name)
  @options = { path: "/rawimages/#{name}", body: '' }.merge(@options)

  request(
    expects: 200,
    method: :get,
    body: @options[:body]
  )
end

#get_organization(id) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/megam/api/organizations.rb', line 14

def get_organization(id)

  @options = {:path => "/organizations/#{id}",
  :body => ''}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_organizationsObject



3
4
5
6
7
8
9
10
11
12
# File 'lib/megam/api/organizations.rb', line 3

def get_organizations
  @options = {:path => '/organizations',:body => ''}.merge(@options)

  request(
    :expects => 200,
    :method => :get,
    :body => @options[:body]

  )
end

#get_promos(id) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/megam/api/promos.rb', line 5

def get_promos(id)
  @options = {:path => "/promos/#{id}", :body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_reports(new_sps) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/megam/api/reports.rb', line 15

def get_reports(new_sps)
  @options = {:path => '/accounts/reports/content', :body => Megam::JSONCompat.to_json(new_sps)}.merge(@options)
  request(
    :expects  => 200,
    :method   => :post,
    :body     => @options[:body]
  )
end

#get_request(node_name) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/megam/api/requests.rb', line 15

def get_request(node_name)
  @options = {:path => "/requests/#{node_name}",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_requestsObject

GET /requests



5
6
7
8
9
10
11
12
13
# File 'lib/megam/api/requests.rb', line 5

def get_requests
  @options = {:path => '/requests',:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_sensor(id) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/megam/api/sensors.rb', line 13

def get_sensor(id)
  @options = {:path => "/sensors/#{id}",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_sensorsObject



3
4
5
6
7
8
9
10
11
# File 'lib/megam/api/sensors.rb', line 3

def get_sensors
  @options = {:path => '/sensors',:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_snapshots(asm_id) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/megam/api/snapshots.rb', line 14

def get_snapshots(asm_id)
  @options = {:path => "/snapshots/#{asm_id}",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_sshkey(sshkey_name) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/megam/api/sshkeys.rb', line 13

def get_sshkey(sshkey_name)
  @options = {:path => "/sshkeys/#{sshkey_name}",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_sshkeysObject



3
4
5
6
7
8
9
10
11
# File 'lib/megam/api/sshkeys.rb', line 3

def get_sshkeys
  @options = {:path => '/sshkeys',:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#get_subscriptionObject



4
5
6
7
8
9
10
11
12
# File 'lib/megam/api/subscriptions.rb', line 4

def get_subscription
  @options = {:path => "/subscriptions",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#index_eventsallObject



26
27
28
29
30
31
32
33
34
# File 'lib/megam/api/eventsall.rb', line 26

def index_eventsall
  @options = {:path => "/eventsall",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#index_eventsbillingObject



25
26
27
28
29
30
31
32
33
# File 'lib/megam/api/eventsbilling.rb', line 25

def index_eventsbilling
  @options = {:path => "/eventsbilling",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#index_eventscontainerObject



25
26
27
28
29
30
31
32
33
# File 'lib/megam/api/eventscontainer.rb', line 25

def index_eventscontainer
  @options = {:path => "/eventscontainer",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#index_eventsMarketplaceObject



25
26
27
28
29
30
31
32
33
# File 'lib/megam/api/eventsmarketplace.rb', line 25

def index_eventsMarketplace
  @options = {:path => "/eventsmarketplace",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#index_eventsstorageObject



14
15
16
17
18
19
20
21
22
# File 'lib/megam/api/eventsstorage.rb', line 14

def index_eventsstorage
  @options = {:path => "/eventsstorage",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#index_eventsvmObject



25
26
27
28
29
30
31
32
33
# File 'lib/megam/api/eventsvm.rb', line 25

def index_eventsvm
  @options = {:path => "/eventsvm",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#list_accountsObject

ADMIN: LIST /accounts



84
85
86
87
88
89
90
91
92
93
# File 'lib/megam/api/accounts.rb', line 84

def list_accounts
  @options = {:path => "/admin/accounts",
    :body => ''}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#list_assemblyObject



34
35
36
37
38
39
40
41
42
# File 'lib/megam/api/assembly.rb', line 34

def list_assembly
  @options = {:path => "/assembly",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#list_backupsObject

GET /nodes



4
5
6
7
8
9
10
11
12
# File 'lib/megam/api/backups.rb', line 4

def list_backups
    @options = {:path => "/backups",:body => ""}.merge(@options)

    request(
        :expects  => 200,
        :method   => :get,
        :body     => @options[:body]
    )
end

#list_creditsObject



3
4
5
6
7
8
9
10
11
# File 'lib/megam/api/credits.rb', line 3

def list_credits
  @options = {:path => '/credits',:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#list_disksObject

GET /nodes



4
5
6
7
8
9
10
11
12
# File 'lib/megam/api/disks.rb', line 4

def list_disks
  @options = {:path => "/disks",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#list_eventsall(limit) ⇒ Object

GET /nodes



4
5
6
7
8
9
10
11
12
# File 'lib/megam/api/eventsall.rb', line 4

def list_eventsall(limit)
  @options = {:path => "/eventsvm/#{limit}",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#list_eventsbilling(limit) ⇒ Object

GET /nodes



4
5
6
7
8
9
10
11
12
# File 'lib/megam/api/eventsbilling.rb', line 4

def list_eventsbilling(limit)
  @options = {:path => "/eventsbilling/#{limit}",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#list_eventscontainer(limit) ⇒ Object

GET /nodes



4
5
6
7
8
9
10
11
12
# File 'lib/megam/api/eventscontainer.rb', line 4

def list_eventscontainer(limit)
  @options = {:path => "/eventscontainer/#{limit}",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#list_eventsMarketplace(limit) ⇒ Object

GET /nodes



4
5
6
7
8
9
10
11
12
# File 'lib/megam/api/eventsmarketplace.rb', line 4

def list_eventsMarketplace(limit)
  @options = {:path => "/eventsmarketplace/#{limit}",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#list_eventsstorage(limit) ⇒ Object

GET /nodes



4
5
6
7
8
9
10
11
12
# File 'lib/megam/api/eventsstorage.rb', line 4

def list_eventsstorage(limit)
  @options = {:path => "/eventsstorage/#{limit}",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#list_eventsvm(limit) ⇒ Object

GET /nodes



4
5
6
7
8
9
10
11
12
# File 'lib/megam/api/eventsvm.rb', line 4

def list_eventsvm(limit)
  @options = {:path => "/eventsvm/#{limit}",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#list_quotasObject



25
26
27
28
29
30
31
32
33
# File 'lib/megam/api/quotas.rb', line 25

def list_quotas
  @options = {:path => "/quotas",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#list_rawimagesObject



14
15
16
17
18
19
20
21
22
# File 'lib/megam/api/rawimages.rb', line 14

def list_rawimages
  @options = {:path => "/rawimages",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#list_snapshotsObject

GET /nodes



4
5
6
7
8
9
10
11
12
# File 'lib/megam/api/snapshots.rb', line 4

def list_snapshots
  @options = {:path => "/snapshots",:body => ""}.merge(@options)

  request(
    :expects  => 200,
    :method   => :get,
    :body     => @options[:body]
  )
end

#login(new_account) ⇒ Object

The body content needs to be a json.



16
17
18
19
20
21
22
23
24
25
# File 'lib/megam/api/accounts.rb', line 16

def ()
  @options = {:path => '/accounts/login',
  :body => Megam::JSONCompat.to_json()}.merge(@options)

  request(
    :expects  => 302,
    :method   => :post,
    :body     => @options[:body]
    )
end

#password_reset(account) ⇒ Object



72
73
74
75
76
77
78
79
80
81
# File 'lib/megam/api/accounts.rb', line 72

def password_reset()
  @options = {:path => "/accounts/password_reset", passthru: true,
              body: Megam::JSONCompat.to_json()}.merge(@options)

  request(
  :expects => 201,
  :method => :post,
  :body => @options[:body]
  )
end

#post_accounts(new_account) ⇒ Object

The body content needs to be a json.



28
29
30
31
32
33
34
35
36
37
# File 'lib/megam/api/accounts.rb', line 28

def post_accounts()
  @options = {path: '/accounts/content',
              body:  Megam::JSONCompat.to_json()}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
    )
end

#post_addons(new_addon) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/megam/api/addons.rb', line 15

def post_addons(new_addon)
  @options = {:path => '/addons/content',
    :body => Megam::JSONCompat.to_json(new_addon)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_assemblies(new_asm) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/megam/api/assemblies.rb', line 24

def post_assemblies(new_asm)
  @options = {:path => '/assemblies/content',
    :body => Megam::JSONCompat.to_json(new_asm)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_backups(new_sps) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/megam/api/backups.rb', line 34

def post_backups(new_sps)
    @options = {:path => '/backups/content',
    :body => Megam::JSONCompat.to_json(new_sps)}.merge(@options)

    request(
        :expects  => 201,
        :method   => :post,
        :body     => @options[:body]
    )
end

#post_balances(new_balance) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/megam/api/balances.rb', line 22

def post_balances(new_balance)
  @options = {:path => '/balances/content',
    :body => Megam::JSONCompat.to_json(new_balance)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_billedhistories(new_billedhistory) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/megam/api/billedhistories.rb', line 23

def post_billedhistories(new_billedhistory)
  @options = {:path => '/billedhistories/content',
    :body => Megam::JSONCompat.to_json(new_billedhistory)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_billingtransactions(new_billtransaction) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/megam/api/billingtransactions.rb', line 13

def post_billingtransactions(new_billtransaction)
  @options = {:path => '/billingtransactions/content',
    :body => Megam::JSONCompat.to_json(new_billtransaction)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_credits(new_credits) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/megam/api/credits.rb', line 22

def post_credits(new_credits)
  @options = {:path => '/credits/content',
    :body => Megam::JSONCompat.to_json(new_credits)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_disks(new_dsk) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/megam/api/disks.rb', line 23

def post_disks(new_dsk)
  @options = {:path => '/disks/content',
    :body => Megam::JSONCompat.to_json(new_dsk)}.merge(@options)
  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_domains(new_domain) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/megam/api/domains.rb', line 15

def post_domains(new_domain)
  @options = {:path => '/domains/content',
  :body =>  Megam::JSONCompat.to_json(new_domain)}.merge(@options)
  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_flavors(new_flavors) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/megam/api/flavors.rb', line 23

def post_flavors(new_flavors)
    @options = {:path => "/flavors/content",
    :body => Megam::JSONCompat.to_json(new_flavors)}.merge(@options)
    request(
        :expects  => 201,
        :method   => :post,
        :body     => @options[:body]
    )
end

#post_license(new_license) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/megam/api/license.rb', line 14

def post_license(new_license)
  @options = {:path => '/admin/licenses/content',
    :body => Megam::JSONCompat.to_json(new_license)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_marketplaceapp(catitem) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/megam/api/marketplaces.rb', line 43

def post_marketplaceapp(catitem)
  @options = {:path => '/marketplaces/content',
    :body => Megam::JSONCompat.to_json(catitem)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_organization(new_organization) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/megam/api/organizations.rb', line 26

def post_organization(new_organization)

  @options = {:path => '/organizations/content',
  :body =>  Megam::JSONCompat.to_json(new_organization)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_quotas(new_sps) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/megam/api/quotas.rb', line 35

def post_quotas(new_sps)
  @options = {:path => '/quotas/content',
      :body => Megam::JSONCompat.to_json(new_sps)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_rawimages(rawimage_item) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/megam/api/rawimages.rb', line 24

def post_rawimages(rawimage_item)
  @options = {:path => '/rawimages/content',
      :body => Megam::JSONCompat.to_json(rawimage_item)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_reports(new_sps) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/megam/api/reports.rb', line 4

def post_reports(new_sps)
  @options = {:path => '/admin/reports/content',
      :body => Megam::JSONCompat.to_json(new_sps)}.merge(@options)

  request(
    :expects  => 200,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_request(new_req) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/megam/api/requests.rb', line 25

def post_request(new_req)
  @options = {:path => '/requests/content',
    :body => Megam::JSONCompat.to_json(new_req)}.merge(@options)
  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_sensors(new_sensors) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/megam/api/sensors.rb', line 23

def post_sensors(new_sensors)
  @options = {:path => '/sensors/content',
    :body => Megam::JSONCompat.to_json(new_sensors)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_snapshots(new_sps) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/megam/api/snapshots.rb', line 23

def post_snapshots(new_sps)
  @options = {:path => '/snapshots/content',
    :body => Megam::JSONCompat.to_json(new_sps)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_sshkey(new_sshkey) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/megam/api/sshkeys.rb', line 23

def post_sshkey(new_sshkey)
  @options = {:path => '/sshkeys/content',
    :body => Megam::JSONCompat.to_json(new_sshkey)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#post_subscriptions(new_subscription) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/megam/api/subscriptions.rb', line 14

def post_subscriptions(new_subscription)
  @options = {:path => '/subscriptions/content',
    :body => Megam::JSONCompat.to_json(new_subscription)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#remove_disks(asm_id, disk_id) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/megam/api/disks.rb', line 32

def remove_disks(asm_id, disk_id)

  @options = {:path => "/disks/delete/#{asm_id}/#{disk_id}",
    :body => ""}.merge(@options)
  request(
    :expects  => 201,
    :method   => :get,
    :body     => @options[:body]
  )
end

#request(params, &block) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/megam/api.rb', line 168

def request(params, &block)
    just_color_debug("#{@options[:path]}")
    start = Time.now
    Megam::Log.debug('START')

    ensure_authkeys unless is_passthru?

    begin
        response = connection.request(params, &block)
    rescue Excon::Errors::HTTPStatusError => error
        klass = case error.response.status

        when 401 then Megam::API::Errors::Unauthorized
        when 403 then Megam::API::Errors::Forbidden
        when 404 then Megam::API::Errors::NotFound
        when 408 then Megam::API::Errors::Timeout
        when 422 then Megam::API::Errors::RequestFailed
        when 423 then Megam::API::Errors::Locked
        when /50./ then Megam::API::Errors::RequestFailed
        else Megam::API::Errors::ErrorWithResponse
        end
        reerror = klass.new(error.message, error.response)
        reerror.set_backtrace(error.backtrace)
        reerror.response.body = Megam::JSONCompat.from_json(reerror.response.body.chomp)
        raise(reerror)
    end

    @last_response = response

    if response.body && !response.body.empty?
        if response.headers['Content-Encoding'] == 'gzip'
            response.body = Zlib::GzipReader.new(StringIO.new(response.body)).read
        end

        begin
            unless response.headers[X_Megam_OTTAI]
                response.body = Megam::JSONCompat.from_json(response.body.chomp)
            else
                response.body = Megam::KoniPai.new.koni(response.body.chomp)
            end
        rescue Exception => jsonerr
            raise(jsonerr)
        end
    end

    Megam::Log.debug("END(#{(Time.now - start)}s)")

    @connection.reset
    response
end

#update_accounts(update_account) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/megam/api/accounts.rb', line 39

def update_accounts()
  @options = {path: '/accounts/update', passthru: true,
              body: Megam::JSONCompat.to_json()}.merge(@options)

  request(
  :expects => 201,
  :method => :post,
  :body => @options[:body]
  )
end

#update_assembly(new_asm) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/megam/api/assembly.rb', line 13

def update_assembly(new_asm)
   @options = { path: '/assembly/update',
                body: Megam::JSONCompat.to_json(new_asm) }.merge(@options)

   request(
     expects: [200, 201],
     method: :post,
     body: @options[:body]
   )
end

#update_backups(update_sps) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/megam/api/backups.rb', line 45

def update_backups(update_sps)
    @options = {:path => '/backups/update',
    :body => Megam::JSONCompat.to_json(update_sps)}.merge(@options)

    request(
        :expects  => 201,
        :method   => :post,
        :body     => @options[:body]
    )
end

#update_balance(new_balance) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/megam/api/balances.rb', line 33

def update_balance(new_balance)
  @options = {:path => '/admin/balances/update',
    :body => Megam::JSONCompat.to_json(new_balance)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#update_component(new_asm) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/megam/api/components.rb', line 13

def update_component(new_asm)
   @options = { path: '/components/update',
                body: Megam::JSONCompat.to_json(new_asm) }.merge(@options)

   request(
     expects: [200, 201],
     method: :post,
     body: @options[:body]
   )
end

#update_flavors(update_flavors) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/megam/api/flavors.rb', line 33

def update_flavors(update_flavors)
    @options = {:path => '/flavors/update',
    :body => Megam::JSONCompat.to_json(update_flavors)}.merge(@options)

    request(
        :expects  => 201,
        :method   => :post,
        :body     => @options[:body]
    )
end

#update_organization(new_organization) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/megam/api/organizations.rb', line 38

def update_organization(new_organization)

  @options = {:path => '/organizations/update',
  :body =>  Megam::JSONCompat.to_json(new_organization)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#update_quotas(new_asm) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/megam/api/quotas.rb', line 14

def update_quotas(new_asm)
   @options = { path: '/quotas/update',
                body: Megam::JSONCompat.to_json(new_asm) }.merge(@options)

   request(
     expects: [200, 201],
     method: :post,
     body: @options[:body]
   )
end

#update_snapshots(update_sps) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/megam/api/snapshots.rb', line 34

def update_snapshots(update_sps)
  @options = {:path => '/snapshots/update',
    :body => Megam::JSONCompat.to_json(update_sps)}.merge(@options)

  request(
    :expects  => 201,
    :method   => :post,
    :body     => @options[:body]
  )
end

#upgrade_assembly(asm_id) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/megam/api/assembly.rb', line 24

def upgrade_assembly(asm_id)
   @options = { path: "/assembly/upgrade/#{asm_id}", body: '' }.merge(@options)

   request(
     expects: [200, 201],
     method: :get,
     body: @options[:body]
   )
end