Class: Cloudkeeper::BackendConnector

Inherits:
Object
  • Object
show all
Includes:
Entities::Conversions
Defined in:
lib/cloudkeeper/backend_connector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBackendConnector

Returns a new instance of BackendConnector.



7
8
9
10
# File 'lib/cloudkeeper/backend_connector.rb', line 7

def initialize
  @grpc_client = CloudkeeperGrpc::Communicator::Stub.new(Cloudkeeper::Settings[:'backend-endpoint'], credentials)
  @nginx = Cloudkeeper::Nginx::HttpServer.new
end

Instance Attribute Details

#grpc_clientObject (readonly)

Returns the value of attribute grpc_client.



5
6
7
# File 'lib/cloudkeeper/backend_connector.rb', line 5

def grpc_client
  @grpc_client
end

#nginxObject (readonly)

Returns the value of attribute nginx.



5
6
7
# File 'lib/cloudkeeper/backend_connector.rb', line 5

def nginx
  @nginx
end

Instance Method Details

#add_appliance(appliance) ⇒ Object



22
23
24
25
# File 'lib/cloudkeeper/backend_connector.rb', line 22

def add_appliance(appliance)
  logger.debug "'add_appliance' gRPC method call (appliance.identifier: #{appliance.identifier})"
  manage_appliance appliance, :add_appliance
end

#appliances(image_list_identifier) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cloudkeeper/backend_connector.rb', line 53

def appliances(image_list_identifier)
  logger.debug "'appliances' gRPC method call"
  handle_errors(
    grpc_client.appliances(
      CloudkeeperGrpc::ImageListIdentifier.new(image_list_identifier: image_list_identifier),
      return_op: true
    ), raise_exception: true
  ) do |response|
    response.inject({}) do |acc, elem|
      image = convert_image_proto(elem.image)
      appliance = convert_appliance_proto elem, image
      acc.merge appliance.identifier => appliance
    end
  end
end

#image_listsObject



46
47
48
49
50
51
# File 'lib/cloudkeeper/backend_connector.rb', line 46

def image_lists
  logger.debug "'image_lists' gRPC method call"
  handle_errors(grpc_client.image_lists(Google::Protobuf::Empty.new, return_op: true)) do |response|
    response.map(&:image_list_identifier)
  end
end

#post_actionObject



17
18
19
20
# File 'lib/cloudkeeper/backend_connector.rb', line 17

def post_action
  logger.debug "'post_action' gRPC method call"
  handle_errors grpc_client.post_action(Google::Protobuf::Empty.new, return_op: true)
end

#pre_actionObject



12
13
14
15
# File 'lib/cloudkeeper/backend_connector.rb', line 12

def pre_action
  logger.debug "'pre_action' gRPC method call"
  handle_errors grpc_client.pre_action(Google::Protobuf::Empty.new, return_op: true), raise_exception: true
end

#remove_appliance(appliance) ⇒ Object



32
33
34
35
36
# File 'lib/cloudkeeper/backend_connector.rb', line 32

def remove_appliance(appliance)
  logger.debug "'remove_appliance' gRPC method call (appliance.identifier: #{appliance.identifier})"
  appliance.image = nil
  manage_appliance appliance, :remove_appliance
end

#remove_image_list(image_list_identifier) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/cloudkeeper/backend_connector.rb', line 38

def remove_image_list(image_list_identifier)
  logger.debug "'remove_image_list' gRPC method call (image_list_identifier: #{image_list_identifier})"
  handle_errors grpc_client.remove_image_list(
    CloudkeeperGrpc::ImageListIdentifier.new(image_list_identifier: image_list_identifier),
    return_op: true
  )
end

#update_appliance(appliance) ⇒ Object



27
28
29
30
# File 'lib/cloudkeeper/backend_connector.rb', line 27

def update_appliance(appliance)
  logger.debug "'update_appliance' gRPC method call (appliance.identifier: #{appliance.identifier})"
  manage_appliance appliance, :update_appliance
end