Class: OVH::Provisioner::APIObject::DedicatedServer

Inherits:
APIObject
  • Object
show all
Defined in:
lib/ovh/provisioner/api_object/dedicated_server.rb

Overview

Represent a dedicated server

Constant Summary collapse

IDLE =

install_status const

'Server is not being installed or reinstalled at the moment'
NO_OS =
'none_64'

Instance Attribute Summary collapse

Attributes inherited from APIObject

#id

Instance Method Summary collapse

Methods inherited from APIObject

#<=>, attr_reader, attributes, #attributes, classname, #config, #delete, entrypoint, #get, #init_properties, #initialize, #post, underscore

Constructor Details

This class inherits a constructor from OVH::Provisioner::APIObject::APIObject

Instance Attribute Details

#bootObject (readonly)

Returns the value of attribute boot.



30
31
32
# File 'lib/ovh/provisioner/api_object/dedicated_server.rb', line 30

def boot
  @boot
end

#dcObject (readonly)

Returns the value of attribute dc.



30
31
32
# File 'lib/ovh/provisioner/api_object/dedicated_server.rb', line 30

def dc
  @dc
end

#flavorObject (readonly)

Returns the value of attribute flavor.



32
33
34
# File 'lib/ovh/provisioner/api_object/dedicated_server.rb', line 32

def flavor
  @flavor
end

#flavor_tagObject (readonly)

Returns the value of attribute flavor_tag.



32
33
34
# File 'lib/ovh/provisioner/api_object/dedicated_server.rb', line 32

def flavor_tag
  @flavor_tag
end

#install_statusObject (readonly)

Returns the value of attribute install_status.



34
35
36
# File 'lib/ovh/provisioner/api_object/dedicated_server.rb', line 34

def install_status
  @install_status
end

#ipObject (readonly)

Returns the value of attribute ip.



30
31
32
# File 'lib/ovh/provisioner/api_object/dedicated_server.rb', line 30

def ip
  @ip
end

#locationObject (readonly)

Returns the value of attribute location.



30
31
32
# File 'lib/ovh/provisioner/api_object/dedicated_server.rb', line 30

def location
  @location
end

#osObject (readonly)

Returns the value of attribute os.



30
31
32
# File 'lib/ovh/provisioner/api_object/dedicated_server.rb', line 30

def os
  @os
end

#reverseObject (readonly)

Returns the value of attribute reverse.



30
31
32
# File 'lib/ovh/provisioner/api_object/dedicated_server.rb', line 30

def reverse
  @reverse
end

#server_idObject (readonly)

Returns the value of attribute server_id.



30
31
32
# File 'lib/ovh/provisioner/api_object/dedicated_server.rb', line 30

def server_id
  @server_id
end

#stateObject (readonly)

Returns the value of attribute state.



31
32
33
# File 'lib/ovh/provisioner/api_object/dedicated_server.rb', line 31

def state
  @state
end

#vrackObject (readonly)

Returns the value of attribute vrack.



33
34
35
# File 'lib/ovh/provisioner/api_object/dedicated_server.rb', line 33

def vrack
  @vrack
end

#vrack_idObject (readonly)

Returns the value of attribute vrack_id.



33
34
35
# File 'lib/ovh/provisioner/api_object/dedicated_server.rb', line 33

def vrack_id
  @vrack_id
end

Instance Method Details

#define_reverse(domain, name = newname) ⇒ Object



79
80
81
82
83
84
# File 'lib/ovh/provisioner/api_object/dedicated_server.rb', line 79

def define_reverse(domain, name = newname)
  full_name = "#{name}.#{domain.id}"
  return "#{reverse}: no change" if reverse == full_name

  add_reverse(full_name)
end

#installObject



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ovh/provisioner/api_object/dedicated_server.rb', line 36

def install
  raise 'Please provide a valid template' if config['template'].nil?

  ok, reason = can_install
  if ok
    result = post('install/start', install_body)
    if result.is_a?(String) # Meaning an error message
      reason = result
      ok = false
    end
  end
  "#{id}: #{ok ? 'ok' : 'failed'}\n  #{reason}"
end

#ipmiObject



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/ovh/provisioner/api_object/dedicated_server.rb', line 86

def ipmi
  request_ipmi

  (1..10).each do |_|
    result = get('features/ipmi/access?type=kvmipJnlp')
    unless result.is_a?(String)
      launch_ipmi(result['value'])
      break
    end
    sleep(1)
  end
end

#newnameObject



57
58
59
60
61
62
63
# File 'lib/ovh/provisioner/api_object/dedicated_server.rb', line 57

def newname
  name_scheme = Provisioner.config['name_scheme']
  return reverse if name_scheme.nil?

  subst = attributes.map { |a| { a => send(a) } }.reduce(&:merge)
  name_scheme % subst
end

#rename(domain, name = newname) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/ovh/provisioner/api_object/dedicated_server.rb', line 65

def rename(domain, name = newname)
  full_name = "#{name}.#{domain.id}"
  return "#{reverse}: no change" if reverse == full_name

  # check if name is already used
  records = domain.filter_records('subdomain' => newname)
  return "#{reverse}: name already used" unless records.list.empty?

  # remove old name (only if it belongs to the same domain)
  remove_old_names(domain)

  domain.add_record(name, 'A', ip)
end

#to_sObject



50
51
52
53
54
55
# File 'lib/ovh/provisioner/api_object/dedicated_server.rb', line 50

def to_s
  "#{reverse}[#{id}/#{server_id}]" \
  "\n  #{location} - #{flavor} - #{vrack}:#{ip} " \
  "- #{boot}:#{os} - #{state}" \
  "\n  #{install_status}"
end