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

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

Instance Attribute Summary collapse

Attributes inherited from Server

#private_key, #private_key_path, #public_key, #public_key_path, #username

Attributes inherited from Model

#collection, #connection

Instance Method Summary collapse

Methods inherited from Server

#scp, #scp_download, #ssh, #ssh_port, #sshable?

Methods inherited from Model

#initialize, #inspect, #reload, #symbolize_keys, #to_json, #wait_for

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #requires, #requires_one

Constructor Details

This class inherits a constructor from Fog::Model

Instance Attribute Details

#disk_offering_idObject

Returns the value of attribute disk_offering_id.



40
41
42
# File 'lib/fog/cloudstack/models/compute/server.rb', line 40

def disk_offering_id
  @disk_offering_id
end

#ip_addressObject

Returns the value of attribute ip_address.



40
41
42
# File 'lib/fog/cloudstack/models/compute/server.rb', line 40

def ip_address
  @ip_address
end

#ip_to_network_listObject

Returns the value of attribute ip_to_network_list.



40
41
42
# File 'lib/fog/cloudstack/models/compute/server.rb', line 40

def ip_to_network_list
  @ip_to_network_list
end

#network_idsObject

Returns the value of attribute network_ids.



40
41
42
# File 'lib/fog/cloudstack/models/compute/server.rb', line 40

def network_ids
  @network_ids
end

#security_group_idsObject



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

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

Instance Method Details

#addressesObject



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

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

#destroyObject



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

def destroy
  requires :id
  data = connection.destroy_virtual_machine("id" => id)
  connection.jobs.new(data["destroyvirtualmachineresponse"])
end

#flavorObject



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

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

#ready?Boolean

Returns:

  • (Boolean)


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

def ready?
  state == 'Running'
end

#rebootObject



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

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

#saveObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/fog/cloudstack/models/compute/server.rb', line 79

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,
    'displayname'       => display_name,
    'group'             => group,
    'domainid'          => domain_id,
    'hostid'            => host_id,
    'ipaddress'         => ip_address,
    'iptonetworklist'   => ip_to_network_list,
    'projectid'         => project_id,
  }

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

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

#security_groupsObject



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

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

#security_groups=(security_groups) ⇒ Object



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

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

#startObject



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

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

#stop(force = false) ⇒ Object



110
111
112
113
114
# File 'lib/fog/cloudstack/models/compute/server.rb', line 110

def stop(force=false)
  requires :id
  data = connection.stop_virtual_machine("id" => self.id, "force" => force)
  connection.jobs.new(data["stopvirtualmachineresponse"])
end