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
11
# 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
  @errors = false
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



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

def errors
  @errors
end

#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



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

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



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/cloudkeeper/backend_connector.rb', line 58

def appliances(image_list_identifier)
  logger.debug "'appliances' gRPC method call"
  response = handle_errors(exception: true) do
    grpc_client.appliances(CloudkeeperGrpc::ImageListIdentifier.new(image_list_identifier: image_list_identifier))
  end

  response.inject({}) do |acc, elem|
    image = convert_image_proto(elem.image)
    appliance = convert_appliance_proto elem, image
    acc.merge appliance.identifier => appliance
  end
end

#image_listsObject



52
53
54
55
56
# File 'lib/cloudkeeper/backend_connector.rb', line 52

def image_lists
  logger.debug "'image_lists' gRPC method call"
  response = handle_errors(exception: true) { grpc_client.image_lists(Google::Protobuf::Empty.new) }
  response.map(&:image_list_identifier)
end

#post_actionObject



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

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

#pre_actionObject



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

def pre_action
  logger.debug "'pre_action' gRPC method call"
  handle_errors(exception: true) { grpc_client.pre_action(Google::Protobuf::Empty.new) }
end

#remove_appliance(appliance) ⇒ Object



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

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_expired_appliancesObject



71
72
73
74
# File 'lib/cloudkeeper/backend_connector.rb', line 71

def remove_expired_appliances
  logger.debug "'remove_expired_appliances' gRPC method call"
  handle_errors { grpc_client.remove_expired_appliances(Google::Protobuf::Empty.new) }
end

#remove_image_list(image_list_identifier) ⇒ Object



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

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

#update_appliance(appliance) ⇒ Object



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

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

#update_appliance_metadata(appliance) ⇒ Object



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

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