Class: DDcloud::API::Server

Inherits:
Core
  • Object
show all
Defined in:
lib/ddcloud/api/server.rb

Instance Attribute Summary

Attributes inherited from Core

#client

Instance Method Summary collapse

Methods inherited from Core

#endpoint, #get, #get_simple, #initialize, #log, #org_endpoint, #org_id, #perform, #post, #post_simple, #query_params, #request_query_string, #request_simple_body, #request_xml_body, #simple_params, #single, #xml_params

Constructor Details

This class inherits a constructor from DDcloud::API::Core

Instance Method Details

#add_storage(server_id, amount) ⇒ Object

amount is # of GBs



111
112
113
114
115
# File 'lib/ddcloud/api/server.rb', line 111

def add_storage(server_id, amount)
  org_endpoint "/server/#{server_id}?addLocalStorage"
  query_params(amount: amount)
  get
end

#create(name, description, network_id, image_id, administrator_password = @client.default_password) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ddcloud/api/server.rb', line 53

def create(name, description, network_id, image_id, administrator_password=@client.default_password)
  org_endpoint "/server"
  xml_params(
    tag: "Server",
    schema: "server",
    name: name,
    description: description,
    vlan_resource_path: "/oec/#{org_id}/network/#{network_id}",
    image_resource_path: "/oec/base/image/#{image_id}",
    is_started: 'true',
    administrator_password: administrator_password
  )
  post
end

#delete(server_id) ⇒ Object



68
69
70
71
# File 'lib/ddcloud/api/server.rb', line 68

def delete(server_id)
  org_endpoint "/server/#{server_id}?delete"
  get
end

#list(options = {}) ⇒ Object

id location networkId sourceImageId deployed boolean name – Matched against names of servers created.MIN=20120901T00:00:00Z created.MAX=20120901T00:00:00Z state

"NORMAL",
"PENDING_ADD",
"PENDING_CHANGE",
"PENDING_DELETE",
"FAILED_ADD",
"FAILED_DELETE",
"PENDING_CLEAN" and
"REQUIRES_SUPPORT".

order_by: started, operatingSystemId, state and all other



22
23
24
25
26
# File 'lib/ddcloud/api/server.rb', line 22

def list(options = {})
  org_endpoint "/serverWithState"
  query_params options
  get
end

#list_deployed_with_disks(network_id, options = {}) ⇒ Object



28
29
30
31
32
# File 'lib/ddcloud/api/server.rb', line 28

def list_deployed_with_disks(network_id, options = {})
  org_endpoint "/network/#{network_id}/server/deployedWithDisks"
  query_params options
  get
end

#modify(server_id, name = nil, description = nil, cpu_count = nil, memory = nil) ⇒ Object

memory in MB, ust be multiple of 1024



74
75
76
77
78
79
80
81
82
83
# File 'lib/ddcloud/api/server.rb', line 74

def modify(server_id, name = nil, description = nil, cpu_count = nil, memory = nil)
  query_params(
    name: name,
    description: description,
    cpu_count: cpu_count,
    memory: memory
  )
  org_endpoint "/server/#{server_id}"
  post
end

#poweroff(server_id) ⇒ Object



95
96
97
98
# File 'lib/ddcloud/api/server.rb', line 95

def poweroff(server_id)
  org_endpoint "/server/#{server_id}?poweroff"
  get
end

#reboot(server_id) ⇒ Object



100
101
102
103
# File 'lib/ddcloud/api/server.rb', line 100

def reboot(server_id)
  org_endpoint "/server/#{server_id}?reboot"
  get
end

#remove_storage(server_id, disk_id) ⇒ Object



117
118
119
120
# File 'lib/ddcloud/api/server.rb', line 117

def remove_storage(server_id, disk_id)
  org_endpoint "/server/#{server_id}/disk/#{disk_id}?delete"
  get
end

#reset(server_id) ⇒ Object



105
106
107
108
# File 'lib/ddcloud/api/server.rb', line 105

def reset(server_id)
  org_endpoint "/server/#{server_id}?reset"
  get
end

#show(server_id, options = {}) ⇒ Object



34
35
36
37
# File 'lib/ddcloud/api/server.rb', line 34

def show(server_id, options = {})
  options[:id] = server_id
  single(list(options))
end

#show_by_ip(ip, options = {}) ⇒ Object



44
45
46
47
# File 'lib/ddcloud/api/server.rb', line 44

def show_by_ip(ip, options = {})
  options[:private_ip] = ip
  single(list(options))
end

#show_by_name(name, options = {}) ⇒ Object



39
40
41
42
# File 'lib/ddcloud/api/server.rb', line 39

def show_by_name(name, options = {})
  options[:name] = name
  single(list(options))
end

#show_with_disks(network_id, server_id, options = {}) ⇒ Object



49
50
51
# File 'lib/ddcloud/api/server.rb', line 49

def show_with_disks(network_id, server_id, options = {})
  list_deployed_with_disks(network_id, options).find {|s| s.id == server_id}
end

#shutdown(server_id) ⇒ Object



90
91
92
93
# File 'lib/ddcloud/api/server.rb', line 90

def shutdown(server_id)
  org_endpoint "/server/#{server_id}?shutdown"
  get
end

#start(server_id) ⇒ Object



85
86
87
88
# File 'lib/ddcloud/api/server.rb', line 85

def start(server_id)
  org_endpoint "/server/#{server_id}?start"
  get
end