Class: Fog::Compute::Cloudstack::Server

Inherits:
Server
  • Object
show all
Defined in:
lib/fog/cloudstack/models/compute/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#disk_offering_idObject

Returns the value of attribute disk_offering_id.



42
43
44
# File 'lib/fog/cloudstack/models/compute/server.rb', line 42

def disk_offering_id
  @disk_offering_id
end

#ip_addressObject Also known as: public_ip_address

Returns the value of attribute ip_address.



42
43
44
# File 'lib/fog/cloudstack/models/compute/server.rb', line 42

def ip_address
  @ip_address
end

#ip_to_network_listObject

Returns the value of attribute ip_to_network_list.



42
43
44
# File 'lib/fog/cloudstack/models/compute/server.rb', line 42

def ip_to_network_list
  @ip_to_network_list
end

#network_idsObject

Returns the value of attribute network_ids.



42
43
44
# File 'lib/fog/cloudstack/models/compute/server.rb', line 42

def network_ids
  @network_ids
end

#security_group_idsObject



103
104
105
# File 'lib/fog/cloudstack/models/compute/server.rb', line 103

def security_group_ids
  @security_group_ids || (self.security_group_list || []).map{|sg| sg["id"]}
end

Instance Method Details

#addressesObject



48
49
50
# File 'lib/fog/cloudstack/models/compute/server.rb', line 48

def addresses
  nics.map{|nic| Address.new(nic)}
end

#destroy(options = {}) ⇒ Object



79
80
81
82
83
# File 'lib/fog/cloudstack/models/compute/server.rb', line 79

def destroy(options={})
  requires :id
  data = service.destroy_virtual_machine(options.merge({'id'=> self.id}))
  service.jobs.new(data["destroyvirtualmachineresponse"])
end

#flavorObject



85
86
87
# File 'lib/fog/cloudstack/models/compute/server.rb', line 85

def flavor
  service.flavors.get(self.flavor_id)
end

#ip_addressesObject



52
53
54
# File 'lib/fog/cloudstack/models/compute/server.rb', line 52

def ip_addresses
  addresses.map(&:ip_address)
end

#private_ip_addressObject



75
76
77
# File 'lib/fog/cloudstack/models/compute/server.rb', line 75

def private_ip_address
  private_ip_addresses.first
end

#private_ip_addressesObject



71
72
73
# File 'lib/fog/cloudstack/models/compute/server.rb', line 71

def private_ip_addresses
  ip_addresses - public_ip_addresses
end

#public_ip_addressesObject



67
68
69
# File 'lib/fog/cloudstack/models/compute/server.rb', line 67

def public_ip_addresses
  if public_ip_address.nil? then [public_ip_address] else [] end
end

#ready?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/fog/cloudstack/models/compute/server.rb', line 89

def ready?
  state == 'Running'
end

#rebootObject



93
94
95
96
97
# File 'lib/fog/cloudstack/models/compute/server.rb', line 93

def reboot
  requires :id
  data = service.reboot_virtual_machine('id' => self.id) # FIXME: does this ever fail?
  service.jobs.new(data["rebootvirtualmachineresponse"])
end

#reset_passwordObject



61
62
63
64
65
# File 'lib/fog/cloudstack/models/compute/server.rb', line 61

def reset_password
  requires :id
  data = service.reset_password_for_virtual_machine(id)
  service.jobs.new(data['resetpasswordforvirtualmachineresponse'])
end

#saveObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/fog/cloudstack/models/compute/server.rb', line 111

def save
  requires :image_id, :flavor_id, :zone_id

  options = {
    'templateid'        => image_id,
    'serviceofferingid' => flavor_id,
    'zoneid'            => zone_id,
    'networkids'        => network_ids,
    'diskofferingid'    => disk_offering_id,
    'name'              => name,
    'displayname'       => display_name,
    'group'             => group,
    'domainid'          => domain_id,
    'hostid'            => host_id,
    'ipaddress'         => ip_address,
    'iptonetworklist'   => ip_to_network_list,
    'projectid'         => project_id,
    'keypair'           => key_name,
    'userdata'           => user_data,
  }

  options.merge!('networkids' => network_ids) if network_ids
  options.merge!('securitygroupids' => security_group_ids) unless security_group_ids.empty?

  data = service.deploy_virtual_machine(options)
  merge_attributes(data['deployvirtualmachineresponse'])
end

#security_groupsObject



107
108
109
# File 'lib/fog/cloudstack/models/compute/server.rb', line 107

def security_groups
  security_group_ids.map{|id| service.security_groups.get(id)}
end

#security_groups=(security_groups) ⇒ Object



99
100
101
# File 'lib/fog/cloudstack/models/compute/server.rb', line 99

def security_groups=(security_groups)
  self.security_group_ids= Array(security_groups).map(&:id)
end

#startObject



139
140
141
142
143
# File 'lib/fog/cloudstack/models/compute/server.rb', line 139

def start
  requires :id
  data = service.start_virtual_machine("id" => self.id)
  service.jobs.new(data["startvirtualmachineresponse"])
end

#stop(options = {}) ⇒ Object



145
146
147
148
149
150
151
152
153
# File 'lib/fog/cloudstack/models/compute/server.rb', line 145

def stop(options={})
  requires :id
  unless options.is_a?(Hash)
    Fog::Logger.deprecation("Passing force as a boolean option has been deprecated. Please pass a hash with 'force' => (true|false)")
    options = {'force' => options}
  end
  data = service.stop_virtual_machine(options.merge({'id' => self.id}))
  service.jobs.new(data["stopvirtualmachineresponse"])
end

#volumesObject



56
57
58
59
# File 'lib/fog/cloudstack/models/compute/server.rb', line 56

def volumes
  requires :id
  service.volumes.all('virtualmachineid' => id)
end