Class: Dopv::Infrastructure::Base

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
DopCommon::Utils
Defined in:
lib/dopv/infrastructure/providers/base.rb

Direct Known Subclasses

BareMetal, OpenStack, Ovirt, Vsphere

Constant Summary collapse

MAX_RETRIES =
5

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plan, state_store) ⇒ Base

Returns a new instance of Base.



43
44
45
46
47
48
# File 'lib/dopv/infrastructure/providers/base.rb', line 43

def initialize(plan, state_store)
  @compute_provider = nil
  @plan = plan
  @state_store = state_store
  @data_disks_db = Dopv::PersistentDisk::DB.new(state_store, nodename)
end

Instance Attribute Details

#data_disks_dbObject (readonly)

Returns the value of attribute data_disks_db.



21
22
23
# File 'lib/dopv/infrastructure/providers/base.rb', line 21

def data_disks_db
  @data_disks_db
end

Class Method Details

.bootstrap_node(plan, state_store) ⇒ Object



31
32
33
# File 'lib/dopv/infrastructure/providers/base.rb', line 31

def self.bootstrap_node(plan, state_store)
  new(plan, state_store).bootstrap_node
end

.destroy_node(plan, state_store, destroy_data_volumes = false) ⇒ Object



35
36
37
# File 'lib/dopv/infrastructure/providers/base.rb', line 35

def self.destroy_node(plan, state_store, destroy_data_volumes=false)
  new(plan, state_store).destroy_node(destroy_data_volumes)
end

.refresh_node(plan, state_store) ⇒ Object



39
40
41
# File 'lib/dopv/infrastructure/providers/base.rb', line 39

def self.refresh_node(plan, state_store)
  new(plan, state_store).refresh_node
end

Instance Method Details

#bootstrap_nodeObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/dopv/infrastructure/providers/base.rb', line 50

def bootstrap_node
  begin
    unless get_node_instance
      execute_hook(:pre_create_vm, true)
      node_instance = create_node_instance
      add_node_nics(node_instance)
      add_node_data_volumes(node_instance)
      add_node_affinities(node_instance)
      start_node_instance(node_instance)
      execute_hook(:post_create_vm, true)
      record_node_instance(node_instance)
      refresh_node_instance(node_instance)
    else
      ::Dopv::log.warn("Node #{nodename}: Already exists.")
      # TODO: Ask Marcel what would be a purpose/use case of this
      execute_hook(:pre_create_vm, false)
      execute_hook(:post_create_vm, false)
    end
  rescue Exception => e
    ::Dopv::log.error("Node #{nodename}: #{e}")
    destroy_node_instance(node_instance)
    raise ProviderError, "Node #{nodename}: #{e}."
  end
end

#destroy_node(destroy_data_volumes = false) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/dopv/infrastructure/providers/base.rb', line 75

def destroy_node(destroy_data_volumes=false)
  node_instance = get_node_instance
  if node_instance
    execute_hook(:pre_destroy_vm, true)
    destroy_node_instance(node_instance, destroy_data_volumes)
    execute_hook(:post_destroy_vm, true)
    erase_node_instance(node_instance)
  else
    # TODO: Ask Marcel what would be a purpose/use case of this
    execute_hook(:pre_destroy_vm, false)
    execute_hook(:post_destroy_vm, false)
  end
end

#refresh_nodeObject



89
90
91
92
93
94
95
96
97
# File 'lib/dopv/infrastructure/providers/base.rb', line 89

def refresh_node
  node_instance = get_node_instance
  if node_instance
    record_node_instance(node_instance)
    refresh_node_instance(node_instance)
  else
    erase_node_instance(node_instance)
  end
end