Class: Bcome::Driver::Gcp
- Inherits:
-
Base
- Object
- Base
- Bcome::Driver::Gcp
show all
- Defined in:
- lib/objects/driver/gcp.rb
Defined Under Namespace
Modules: Authentication
Constant Summary
collapse
- APPLICATION_NAME =
'Bcome console'
Instance Method Summary
collapse
Methods inherited from Base
#config, create_from_config, klass_for_type, #loader_completed_title, #loader_title, #spoof_fetch_server_list
#cursor, #do_signal, #fork_process, #signal_failure, #signal_stop, #signal_success, #start_indicator, #stop_indicator, #wrap_indicator
Constructor Details
#initialize(*params) ⇒ Gcp
Returns a new instance of Gcp.
9
10
11
12
13
|
# File 'lib/objects/driver/gcp.rb', line 9
def initialize(*params)
super
validate_service_scopes
validate_authentication_scheme
end
|
Instance Method Details
#do_fetch_server_list(_filters) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/objects/driver/gcp.rb', line 41
def do_fetch_server_list(_filters)
filters = (
@params[:filters] || (
@params[:list_filter] || ''
)
)
gcp_service.list_instances(@params[:project], @params[:zone], filter: filters)
rescue Google::Apis::AuthorizationError => e
raise ::Bcome::Exception::CannotAuthenticateToGcp
rescue Google::Apis::ClientError => e
raise ::Bcome::Exception::Generic, "Namespace #{@node.namespace} / #{e.message}"
rescue Google::Apis::TransmissionError => e
raise ::Bcome::Exception::Generic, 'Cannot reach GCP - do you have an internet connection?'
end
|
#fetch_server_list(_filters) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/objects/driver/gcp.rb', line 23
def fetch_server_list(_filters)
unless authentication_scheme.authorized?
get_authenticated_gcp_service
raise ::Bcome::Exception::Generic, 'GCP authentication process failed' unless authentication_scheme.authorized?
end
wrap_indicator type: :basic, title: loader_title, completed_title: loader_completed_title do
begin
@instances = do_fetch_server_list(_filters)
signal_success
rescue Exception => e
signal_failure
raise e
end
end
@instances.items
end
|
#has_network_credentials? ⇒ Boolean
59
60
61
|
# File 'lib/objects/driver/gcp.rb', line 59
def has_network_credentials?
true
end
|
#network_credentials ⇒ Object
63
64
65
66
67
68
|
# File 'lib/objects/driver/gcp.rb', line 63
def network_credentials
{
access_token: access_token,
project_name: @params[:project]
}
end
|
#pretty_provider_name ⇒ Object
15
16
17
|
# File 'lib/objects/driver/gcp.rb', line 15
def pretty_provider_name
'GCP'
end
|
#pretty_resource_location ⇒ Object
19
20
21
|
# File 'lib/objects/driver/gcp.rb', line 19
def pretty_resource_location
"#{@params[:project]}/#{@params[:zone]}"
end
|