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
|
Class Method Details
.all ⇒ Object
10
11
12
13
|
# File 'lib/cf_ruby_client/service_instance.rb', line 10
def self.all
url_path = "#{SERVICE_INSTANCES_PATH}"
JSON::parse(CfRubyClient::Base.new.fetch_entities(url_path))
end
|
Instance Method Details
#app_guids ⇒ Object
38
39
40
41
|
# File 'lib/cf_ruby_client/service_instance.rb', line 38
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
64
65
66
67
68
69
|
# File 'lib/cf_ruby_client/service_instance.rb', line 64
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
79
80
81
82
83
84
85
|
# File 'lib/cf_ruby_client/service_instance.rb', line 79
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.
50
51
52
53
54
|
# File 'lib/cf_ruby_client/service_instance.rb', line 50
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
58
59
60
61
62
|
# File 'lib/cf_ruby_client/service_instance.rb', line 58
def security_group(name)
url_path = "#{SECURITY_GROUPS_PATH}?q=name:#{name}"
(JSON::parse(fetch_entities(url_path)))
end
|
#security_group_guid(name) ⇒ Object
43
44
45
46
|
# File 'lib/cf_ruby_client/service_instance.rb', line 43
def security_group_guid(name)
return nil if security_group(name).empty?
security_group(name)[:guid]
end
|
#service_bindings ⇒ Object
32
33
34
35
36
|
# File 'lib/cf_ruby_client/service_instance.rb', line 32
def service_bindings
url_path = "#{SERVICE_INSTANCES_PATH}/#{service_instance_guid}/service_bindings"
JSON::parse(fetch_entities(url_path))
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
71
72
73
74
75
76
77
|
# File 'lib/cf_ruby_client/service_instance.rb', line 71
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
|