Class: Fog::Compute::ProfitBricks::Datacenter

Inherits:
Models::ProfitBricks::Base show all
Includes:
Helpers::ProfitBricks::DataHelper
Defined in:
lib/fog/profitbricks/models/compute/datacenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::ProfitBricks::DataHelper

#flatten

Methods inherited from Models::ProfitBricks::Base

#failed?, #ready?, #request_status, #wait_for

Constructor Details

#initialize(attributes = {}) ⇒ Datacenter

Returns a new instance of Datacenter.



36
37
38
# File 'lib/fog/profitbricks/models/compute/datacenter.rb', line 36

def initialize(attributes = {})
  super
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



34
35
36
# File 'lib/fog/profitbricks/models/compute/datacenter.rb', line 34

def options
  @options
end

Instance Method Details

#deleteObject



90
91
92
93
94
# File 'lib/fog/profitbricks/models/compute/datacenter.rb', line 90

def delete
  requires :id
  data = service.delete_datacenter(id)
  true
end

#saveObject



40
41
42
43
44
45
46
47
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
75
76
77
# File 'lib/fog/profitbricks/models/compute/datacenter.rb', line 40

def save
  requires :name, :location

  options = {}
  options[:name] = name
  options[:location] = location
  options[:description] = description if description
  options[:servers] = servers if servers
  options[:volumes] = volumes if volumes
  options[:loadbalancers] = loadbalancers if loadbalancers
  options[:lans] = lans if lans

  entities = {}

  # Retrieve servers collection if present and generate appropriate JSON.
  if options.key?(:servers)
    entities[:servers] = collect_entities(options.delete(:servers))
  end

  # Retrieve volumes collection if present and generate appropriate JSON.
  if options.key?(:volumes)
    entities[:volumes] = collect_entities(options.delete(:volumes))
  end

  # Retrieve volumes collection if present and generate appropriate JSON.
  if options.key?(:loadbalancers)
    entities[:loadbalancers] = collect_entities(options.delete(:loadbalancers))
  end

  # Retrieve volumes collection if present and generate appropriate JSON.
  if options.key?(:lans)
    entities[:lans] = collect_entities(options.delete(:lans))
  end

  data = service.create_datacenter(options, entities)
  merge_attributes(flatten(data.body))
  true
end

#updateObject



79
80
81
82
83
84
85
86
87
88
# File 'lib/fog/profitbricks/models/compute/datacenter.rb', line 79

def update
  requires :id

  options = {}
  options[:name] = name if name
  options[:description] = description if description
  data = service.update_datacenter(id, options)
  merge_attributes(flatten(data.body))
  true
end