Class: Miasma::Models::Compute::OpenStack

Inherits:
Miasma::Models::Compute show all
Includes:
Contrib::OpenStackApiCore::ApiCommon
Defined in:
lib/miasma/contrib/open_stack/compute.rb

Direct Known Subclasses

Rackspace

Constant Summary collapse

SERVER_STATE_MAP =

Returns map state to valid internal values.

Returns:

  • (Smash)

    map state to valid internal values

Smash.new(
  'ACTIVE' => :running,
  'DELETED' => :terminated,
  'SUSPENDED' => :stopped,
  'PASSWORD' => :running
)

Instance Method Summary collapse

Methods included from Contrib::OpenStackApiCore::ApiCommon

#connection, #endpoint, included, #open_stack_api, #token

Methods inherited from Miasma::Models::Compute

#server_filter, #servers

Methods inherited from Types::Api

#api_for, #connect, #connection, #endpoint, #format_response, #initialize, #make_request, #provider, #request

Methods included from Utils::Memoization

#_memo, #clear_memoizations!, #memoize, #unmemoize

Methods included from Utils::Lazy

included

Constructor Details

This class inherits a constructor from Miasma::Types::Api

Instance Method Details

#server_allObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/miasma/contrib/open_stack/compute.rb', line 73

def server_all
  result = request(
    :method => :get,
    :path => '/servers/detail'
  )
  result[:body].fetch(:servers, []).map do |srv|
    Server.new(
      self,
      :id => srv[:id],
      :name => srv[:name],
      :image_id => srv.get(:image, :id),
      :flavor_id => srv.get(:flavor, :id),
      :state => SERVER_STATE_MAP.fetch(srv[:status], :pending),
      :addresses_private => srv.fetch(:addresses, :private, []).map{|a|
        Server::Address.new(
          :version => a[:version].to_i, :address => a[:addr]
        )
      },
      :addresses_public => srv.fetch(:addresses, :public, []).map{|a|
        Server::Address.new(
          :version => a[:version].to_i, :address => a[:addr]
        )
      },
      :status => srv[:status],
      :key_name => srv[:key_name]
    ).valid_state
  end
end

#server_change_state(server, state) ⇒ Object



55
56
# File 'lib/miasma/contrib/open_stack/compute.rb', line 55

def server_change_state(server, state)
end

#server_destroy(server) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/miasma/contrib/open_stack/compute.rb', line 42

def server_destroy(server)
  if(server.persisted?)
    result = request(
      :expects => 204,
      :method => :delete,
      :path => "/servers/#{server.id}"
    )
    true
  else
    false
  end
end

#server_reload(server) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/miasma/contrib/open_stack/compute.rb', line 58

def server_reload(server)
  res = servers.reload.all
  node = res.detect do |s|
    s.id == server.id
  end
  if(node)
    server.load_data(node.data.dup)
    server.valid_state
  else
    server.data[:state] = :terminated
    server.dirty.clear
    server
  end
end

#server_save(server) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/miasma/contrib/open_stack/compute.rb', line 18

def server_save(server)
  unless(server.persisted?)
    server.load_data(server.attributes)
    result = request(
      :expects => 202,
      :method => :post,
      :path => '/servers',
      :json => {
        :server => {
          :flavorRef => server.flavor_id,
          :name => server.name,
          :imageRef => server.image_id,
          :metadata => server.,
          :personality => server.personality,
          :key_pair => server.key_name
        }
      }
    )
    server.id = result.get(:body, :server, :id)
  else
    raise "WAT DO I DO!?"
  end
end