Class: Fog::Compute::CloudSigma::Server

Inherits:
Fog::CloudSigma::CloudsigmaModel show all
Defined in:
lib/fog/cloudsigma/models/server.rb

Instance Method Summary collapse

Methods inherited from Fog::CloudSigma::CloudsigmaModel

model_attribute, model_attribute_array

Instance Method Details

#add_nic(vlan = nil, ip_v4_conf = nil, ip_v6_conf = nil, model = 'virtio', boot_order = nil) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/fog/cloudsigma/models/server.rb', line 165

def add_nic(vlan=nil, ip_v4_conf=nil, ip_v6_conf=nil, model='virtio', boot_order=nil)
  nic_data = {
      'model' => model,
      'vlan' => vlan,
      'ip_v4_conf' => ip_v4_conf,
      'ip_v6_conf' => ip_v6_conf
  }
  if boot_order
    nic_data['boot_order'] = boot_order
  end

  self.nics = self.nics << Nic.new(nic_data)
end

#add_private_nic(vlan, model = 'virtio', boot_order = nil) ⇒ Object



191
192
193
194
# File 'lib/fog/cloudsigma/models/server.rb', line 191

def add_private_nic(vlan, model='virtio', boot_order=nil)
  vlan = vlan.kind_of?(String) ? vlan : vlan.identity
  add_nic(vlan, nil, nil, model, boot_order)
end

#add_public_nic(ip_or_conf = :dhcp, model = 'virtio', boot_order = nil) ⇒ Object



179
180
181
182
183
184
185
186
187
188
189
# File 'lib/fog/cloudsigma/models/server.rb', line 179

def add_public_nic(ip_or_conf=:dhcp, model='virtio', boot_order=nil)
  case ip_or_conf
    when :dhcp
      add_nic(nil, {:conf => :dhcp}, nil, model, boot_order)
    when :manual
      add_nic(nil, {:conf => :manual}, nil, model, boot_order)
    else
      ip = ip_or_conf.kind_of?(String) ? ip_or_conf : ip_or_conf.identity
      add_nic(nil, {:conf => :static, :ip => ip}, nil, model, boot_order)
  end
end

#clone(clone_params = {}) ⇒ Object



94
95
96
97
98
99
# File 'lib/fog/cloudsigma/models/server.rb', line 94

def clone(clone_params={})
  requires :identity
  response = service.clone_server(identity, clone_params)

  self.class.new(response.body)
end

#close_vncObject



89
90
91
92
# File 'lib/fog/cloudsigma/models/server.rb', line 89

def close_vnc
  requires :identity
  service.close_vnc(identity)
end

#createObject



37
38
39
40
41
42
43
44
# File 'lib/fog/cloudsigma/models/server.rb', line 37

def create
  requires :name, :cpu, :mem, :vnc_password
  data = attributes

  response = service.create_server(data)
  new_attributes = response.body['objects'].first
  merge_attributes(new_attributes)
end

#destroyObject Also known as: delete



56
57
58
59
60
61
# File 'lib/fog/cloudsigma/models/server.rb', line 56

def destroy
  requires :identity

  service.delete_server(identity)
  true
end

#mount_volume(volume, device = 'virtio', dev_channel = nil, boot_order = nil) ⇒ Object



101
102
103
104
105
106
107
108
109
110
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
138
139
140
141
142
# File 'lib/fog/cloudsigma/models/server.rb', line 101

def mount_volume(volume, device = 'virtio', dev_channel = nil, boot_order = nil)
  unless dev_channel
    specified_channels = self.volumes.map { |v| v.dev_channel }.sort
    if specified_channels
      controller, controller_channel = 0, 0
      max_ctlr, max_chnl = case device
                             when 'ide'
                               [4, 2]
                             else
                               [1024, 5]
                           end

      dev_channel = "#{controller}:#{controller_channel}"
      while specified_channels.include? dev_channel
        controller_channel += 1
        if controller_channel >= max_chnl
          controller_channel = 0
          controller += 1
          if controller >= max_ctlr
            raise Fog::CloudSigma::Errors::Error.new("Max channel reached, cannot attach more")
          end
        end
        dev_channel = "#{controller}:#{controller_channel}"
      end
    else # no other channels specified
      dev_channel = '0:0'
    end
  end

  vol_id = volume.kind_of?(String) ? volume : volume.identity
  mountpoint_data = {
      'drive' => vol_id,
      'device' => device,
      'dev_channel' => dev_channel,
  }

  if boot_order
    mountpoint_data['boot_order'] = boot_order
  end

  self.volumes = self.volumes << MountPoint.new(mountpoint_data)
end

#open_vncObject



84
85
86
87
# File 'lib/fog/cloudsigma/models/server.rb', line 84

def open_vnc
  requires :identity
  service.open_vnc(identity)
end

#ready?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/fog/cloudsigma/models/server.rb', line 80

def ready?
  status == "running"
end

#remove_all_nicsObject



206
207
208
# File 'lib/fog/cloudsigma/models/server.rb', line 206

def remove_all_nics
  self.nics = []
end

#remove_nic(mac_or_position) ⇒ Object



196
197
198
199
200
201
202
203
204
# File 'lib/fog/cloudsigma/models/server.rb', line 196

def remove_nic(mac_or_position)
  if mac_or_position.kind_of? Fixnum
    self.nics.delete_at(mac_or_position)
    # assign to update attributes
    return self.nics = self.nics
  end

  self.nics = self.nics.reject { |n| n.mac == mac_or_position }
end

#saveObject



29
30
31
32
33
34
35
# File 'lib/fog/cloudsigma/models/server.rb', line 29

def save
  if persisted?
    update
  else
    create
  end
end

#shutdownObject



75
76
77
78
# File 'lib/fog/cloudsigma/models/server.rb', line 75

def shutdown
  requires :identity
  service.stop_server(identity, true)
end

#start(start_params = {}) ⇒ Object



65
66
67
68
# File 'lib/fog/cloudsigma/models/server.rb', line 65

def start(start_params={})
  requires :identity
  service.start_server(identity, start_params)
end

#stopObject



70
71
72
73
# File 'lib/fog/cloudsigma/models/server.rb', line 70

def stop
  requires :identity
  service.stop_server(identity)
end

#unmount_all_volumesObject



161
162
163
# File 'lib/fog/cloudsigma/models/server.rb', line 161

def unmount_all_volumes
  self.volumes = []
end

#unmount_volume(volume_or_position) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/fog/cloudsigma/models/server.rb', line 144

def unmount_volume(volume_or_position)
  if volume_or_position.kind_of? Fixnum
    self.volumes.delete_at(volume_or_position)
    # assign to update attributes
    return self.volumes = self.volumes
  end

  vol_id = volume_or_position.kind_of?(String) ? volume_or_position : volume_or_position.identity
  self.volumes = self.volumes.reject do |v|
    if v.volume.kind_of? Hash
      v.volume['uuid'] == vol_id
    else
      v.volume == vol_id
    end
  end
end

#updateObject



46
47
48
49
50
51
52
53
54
# File 'lib/fog/cloudsigma/models/server.rb', line 46

def update
  requires :identity, :name, :cpu, :mem, :vnc_password

  data = attributes

  response = service.update_server(identity, data)
  new_attributes = response.body
  merge_attributes(new_attributes)
end