Class: CfRubyClient::ServiceInstance
- Inherits:
-
Base
- Object
- Base
- CfRubyClient::ServiceInstance
show all
- Defined in:
- lib/cf_ruby_client/service_instance.rb
Constant Summary
collapse
- SECURITY_GROUPS_PATH =
"/v2/security_groups"
- SERVICE_INSTANCES_PATH =
"/v2/service_instances"
- APP_RESTARTING_PATH =
"/apps/restart_all/bound_to"
- NAME_PREFIX =
TODO: make this configurable
"guard_"
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#api_endpoint, #authorization_string, #cloud_foundry_config, #delete_entity, #fetch_entities, #logger, #patch_entity, #post_entity, #put_entity, #resource, #uaa_endpoint
Constructor Details
#initialize(service_instance_guid) ⇒ ServiceInstance
Returns a new instance of ServiceInstance.
17
18
19
|
# File 'lib/cf_ruby_client/service_instance.rb', line 17
def initialize(service_instance_guid)
@service_instance_guid = service_instance_guid
end
|
Instance Attribute Details
#service_instance_guid ⇒ Object
Returns the value of attribute service_instance_guid.
15
16
17
|
# File 'lib/cf_ruby_client/service_instance.rb', line 15
def service_instance_guid
@service_instance_guid
end
|
Instance Method Details
#app_guids ⇒ Object
47
48
49
50
|
# File 'lib/cf_ruby_client/service_instance.rb', line 47
def app_guids
return [] if service_bindings.nil? or service_bindings.empty?
service_bindings["resources"].map { |entry| entry["entity"]["app_guid"] }
end
|
#create_security_group(body) ⇒ Object
73
74
75
76
77
78
|
# File 'lib/cf_ruby_client/service_instance.rb', line 73
def create_security_group(body)
logger.debug "cf_ruby_client: Creating Security Group in the Cloud Controller"
url = SECURITY_GROUPS_PATH
post_entity(url, body)
end
|
#delete_security_group(security_group_guid) ⇒ Object
88
89
90
91
92
93
94
|
# File 'lib/cf_ruby_client/service_instance.rb', line 88
def delete_security_group(security_group_guid)
logger.debug "cf_ruby_client: Deleting Security Group in the Cloud Controller"
url = "#{SECURITY_GROUPS_PATH}/#{security_group_guid}"
delete_entity(url)
end
|
#instance ⇒ Object
21
22
23
24
25
|
# File 'lib/cf_ruby_client/service_instance.rb', line 21
def instance
url_path = "#{SERVICE_INSTANCES_PATH}/#{service_instance_guid}"
JSON::parse(fetch_entities(url_path))
end
|
#restart_apps ⇒ Object
restarts all applications running on Cloud Foundry which are bound to the service instance passed in the initializer.
59
60
61
62
63
|
# File 'lib/cf_ruby_client/service_instance.rb', line 59
def restart_apps
url = "#{APP_RESTARTING_PATH}/#{service_instance_guid}"
post_entity(url)
end
|
#security_group(name) ⇒ Object
gets the security group from the cloud controller associated with the service instance
67
68
69
70
71
|
# File 'lib/cf_ruby_client/service_instance.rb', line 67
def security_group(name)
url_path = "#{SECURITY_GROUPS_PATH}?q=name:#{name}"
(JSON::parse(fetch_entities(url_path)))
end
|
#security_group_guid(name) ⇒ Object
52
53
54
55
|
# File 'lib/cf_ruby_client/service_instance.rb', line 52
def security_group_guid(name)
return nil if security_group(name).empty?
security_group(name)[:guid]
end
|
#service_bindings ⇒ Object
41
42
43
44
45
|
# File 'lib/cf_ruby_client/service_instance.rb', line 41
def service_bindings
url_path = "#{SERVICE_INSTANCES_PATH}/#{service_instance_guid}/service_bindings"
JSON::parse(fetch_entities(url_path))
end
|
#shared_to ⇒ Object
32
33
34
35
36
37
38
39
|
# File 'lib/cf_ruby_client/service_instance.rb', line 32
def shared_to
url_path = "#{SERVICE_INSTANCES_PATH}/#{service_instance_guid}/shared_to"
result = JSON::parse(fetch_entities(url_path))
result['resources'] = [] unless result['resources']
result
end
|
#space_guid ⇒ Object
27
28
29
30
|
# File 'lib/cf_ruby_client/service_instance.rb', line 27
def space_guid
return nil if instance.nil? or instance.empty?
instance["entity"]["space_guid"]
end
|
#update_security_group(body, security_group_guid) ⇒ Object
80
81
82
83
84
85
86
|
# File 'lib/cf_ruby_client/service_instance.rb', line 80
def update_security_group(body, security_group_guid)
logger.debug "cf_ruby_client: Updating Security Group in the Cloud Controller"
url = "#{SECURITY_GROUPS_PATH}/#{security_group_guid}"
put_entity(url, body)
end
|