Class: Fog::Compute::Packet::Device

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/compute/packet/models/device.rb

Overview

Device Model

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Device

Returns a new instance of Device.



44
45
46
# File 'lib/fog/compute/packet/models/device.rb', line 44

def initialize(attributes = {})
  super
end

Instance Method Details

#destroyObject



112
113
114
115
116
117
# File 'lib/fog/compute/packet/models/device.rb', line 112

def destroy
  requires :id

  response = service.delete_device(id)
  true if response.status == 204
end

#inactive?Boolean

Returns:

  • (Boolean)


130
131
132
# File 'lib/fog/compute/packet/models/device.rb', line 130

def inactive?
  state == "inactive"
end

#ready?Boolean

Returns:

  • (Boolean)


126
127
128
# File 'lib/fog/compute/packet/models/device.rb', line 126

def ready?
  state == "active"
end

#rebootObject



94
95
96
97
98
# File 'lib/fog/compute/packet/models/device.rb', line 94

def reboot
  requires :id
  response = service.reboot_device(id)
  true if response.status == 202
end

#reloadObject



119
120
121
122
123
124
# File 'lib/fog/compute/packet/models/device.rb', line 119

def reload
  requires :id
  response = service.get_device(id)
  return unless response.body
  merge_attributes(response.body)
end

#saveObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/fog/compute/packet/models/device.rb', line 48

def save
  requires :project_id, :facility, :plan, :hostname, :operating_system

  options = {}
  options[:plan] = plan
  options[:facility] = facility
  options[:hostname] = hostname
  options[:operating_system] = operating_system

  options[:description] = description if description
  options[:billing_cycle] = billing_cycle if billing_cycle
  options[:always_pxe] = always_pxe if always_pxe
  options[:ipxe_script_url] = ipxe_script_url if ipxe_script_url
  options[:userdata] = userdata if userdata
  options[:locked] = locked if locked
  options[:hardware_reservation_id] = hardware_reservation_id if hardware_reservation_id
  options[:spot_instance] = spot_instance if spot_instance
  options[:spot_price_max] = spot_price_max if spot_price_max
  options[:termination_time] = termination_time if termination_time
  options[:tags] = tags if tags
  options[:project_ssh_keys] = project_ssh_keys if project_ssh_keys
  options[:user_ssh_keys] = user_ssh_keys if user_ssh_keys
  options[:features] = features if features

  response = service.create_device(project_id, options)
  merge_attributes(response.body)
end

#startObject



100
101
102
103
104
# File 'lib/fog/compute/packet/models/device.rb', line 100

def start
  requires :id
  response = service.poweron_device(id)
  true if response.status == 202
end

#stopObject



106
107
108
109
110
# File 'lib/fog/compute/packet/models/device.rb', line 106

def stop
  requires :id
  response = service.poweroff_device(id)
  true if response.status == 202
end

#updateObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/fog/compute/packet/models/device.rb', line 76

def update
  requires :id

  options = {}
  options[:hostname] = hostname if hostname
  options[:description] = description if description
  options[:billing_cycle] = billing_cycle if billing_cycle
  options[:userdata] = userdata if userdata
  options[:locked] = locked if locked
  options[:tags] = tags if tags
  options[:always_pxe] = always_pxe if always_pxe
  options[:ipxe_script_url] = ipxe_script_url if ipxe_script_url
  options[:spot_instance] = spot_instance if spot_instance

  response = service.update_device(id, options)
  merge_attributes(response.body)
end