pcf_pause 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/pcf_pause.rb +18 -0
- data/lib/pcf_pause/ops_man_info.rb +79 -0
- data/lib/pcf_pause/pause.rb +113 -0
- data/lib/pcf_pause/version.rb +17 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d7887dada4698d0764cbfb3e972b96af7789fc74
|
4
|
+
data.tar.gz: 3a360a8e8e55cc855793fa5cdd1f5e852c6e6457
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e4f985e984355a286e81cdae5c109f634379c1864e976b743a53093922d977ecca570320b42baa98d46ea4fef348bcf5a5dedd4419315455c7815495de4d8fb9
|
7
|
+
data.tar.gz: 048902181fdedf126822ec27fb3ba3470ef446d67339ba3c9b1cbf500fec28325920cc0f89ff7a207fcd24f584aceb8135dbe95baec77b4f5fb6fcc197dba803
|
data/lib/pcf_pause.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Copyright (c) 2014-2015 Pivotal Software, Inc. All rights reserved.
|
2
|
+
|
3
|
+
# Unauthorized use, copying or distribution of this source code via any
|
4
|
+
# medium is strictly prohibited without the express written consent of
|
5
|
+
# Pivotal Software, Inc.
|
6
|
+
|
7
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
8
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
9
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
10
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
11
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
12
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
13
|
+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
14
|
+
|
15
|
+
module PcfPause; end
|
16
|
+
|
17
|
+
require_relative 'pcf_pause/ops_man_info'
|
18
|
+
require_relative 'pcf_pause/pause'
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# Copyright (c) 2014-2015 Pivotal Software, Inc. All rights reserved.
|
2
|
+
|
3
|
+
# Unauthorized use, copying or distribution of this source code via any
|
4
|
+
# medium is strictly prohibited without the express written consent of
|
5
|
+
# Pivotal Software, Inc.
|
6
|
+
|
7
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
8
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
9
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
10
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
11
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
12
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
13
|
+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
14
|
+
|
15
|
+
module PcfPause
|
16
|
+
class OpsManInfo
|
17
|
+
attr_reader :url, :token
|
18
|
+
|
19
|
+
def initialize(url, username, password)
|
20
|
+
@url = url
|
21
|
+
@token = auth_header(username, password)
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_products
|
25
|
+
get_info 'deployed/products/'
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_manifest(product_id)
|
29
|
+
get_info "deployed/products/#{product_id}/manifest"
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_vm_credentials(product_id)
|
33
|
+
get_info "deployed/products/#{product_id}/vm_credentials"
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_vm_names(product_id)
|
37
|
+
manifest = get_manifest(product_id)
|
38
|
+
key = if manifest.has_key?('jobs') # 1.7 manifest
|
39
|
+
'jobs'
|
40
|
+
else
|
41
|
+
'instance_groups'
|
42
|
+
end
|
43
|
+
manifest[key].map { |vm| vm['name'] }
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_director_manifest
|
47
|
+
get_info 'deployed/director/manifest'
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_product_id(type)
|
51
|
+
get_products.detect { |product_info| product_info['type'] == type }['guid']
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def get_info(path)
|
57
|
+
get_request = Net::HTTP::Get.new(File.join('/api/v0/', path))
|
58
|
+
get_request['Authorization'] = token
|
59
|
+
response = http_client.request(get_request)
|
60
|
+
fail("Unexpected response: #{response.inspect}") unless response.code == '200'
|
61
|
+
JSON.parse(response.body)
|
62
|
+
end
|
63
|
+
|
64
|
+
def http_client
|
65
|
+
uri = URI.parse(url)
|
66
|
+
Net::HTTP.new(uri.host, uri.port).tap do |http|
|
67
|
+
http.use_ssl = true if url =~ /https/
|
68
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
69
|
+
http.read_timeout = 300
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def auth_header(username, password)
|
74
|
+
CF::UAA::TokenIssuer.new(URI.join(url, 'uaa'), 'opsman', '').tap do |issuer|
|
75
|
+
issuer.skip_ssl_validation = true
|
76
|
+
end.owner_password_grant(username, password).auth_header
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# Copyright (c) 2014-2015 Pivotal Software, Inc. All rights reserved.
|
2
|
+
|
3
|
+
# Unauthorized use, copying or distribution of this source code via any
|
4
|
+
# medium is strictly prohibited without the express written consent of
|
5
|
+
# Pivotal Software, Inc.
|
6
|
+
|
7
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
8
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
9
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
10
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
11
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
12
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
13
|
+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
14
|
+
|
15
|
+
require 'uaa'
|
16
|
+
require 'net/ssh'
|
17
|
+
require_relative 'ops_man_info'
|
18
|
+
|
19
|
+
module PcfPause
|
20
|
+
class Pause
|
21
|
+
attr_reader :logger
|
22
|
+
|
23
|
+
def initialize(logger = Logger.new(STDOUT))
|
24
|
+
@logger = logger
|
25
|
+
end
|
26
|
+
|
27
|
+
TARGET_JOBS = %w(
|
28
|
+
nats consul_server etcd_server diego_database nfs_server router ccdb
|
29
|
+
uaadb consoledb cloud_controller ha_proxy health_manager clock_global
|
30
|
+
cloud_controller_worker collector uaa diego_brain diego_cell doppler
|
31
|
+
loggregator_trafficcontroller
|
32
|
+
)
|
33
|
+
|
34
|
+
def get_job_sequence(bosh_vms_value)
|
35
|
+
bosh_vms_value.select do |vm_name|
|
36
|
+
TARGET_JOBS.any? { |job| vm_name.start_with?(job) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def smoke_tests(url, username, password, key_path='')
|
41
|
+
bosh_command, bosh_vms_value = connect_to_bosh(password, url, username)
|
42
|
+
|
43
|
+
Net::SSH.start(URI.parse(url).host, 'ubuntu', keys: [key_path]) do |ssh|
|
44
|
+
exec_ssh ssh, "#{bosh_command} #{smoke_tests_command}"
|
45
|
+
end
|
46
|
+
logger.info 'Smoke tests have finished'
|
47
|
+
end
|
48
|
+
|
49
|
+
def start(url, username, password, key_path='')
|
50
|
+
bosh_command, bosh_vms_value = connect_to_bosh(password, url, username)
|
51
|
+
|
52
|
+
logger.info("Preparing to start instances")
|
53
|
+
|
54
|
+
Net::SSH.start(URI.parse(url).host, 'ubuntu', keys: [key_path]) do |ssh|
|
55
|
+
exec_ssh ssh, "#{bosh_command} #{start_command}"
|
56
|
+
logger.info "Started"
|
57
|
+
end
|
58
|
+
logger.info 'All instances started'
|
59
|
+
end
|
60
|
+
|
61
|
+
def stop(url, username, password, key_path='')
|
62
|
+
bosh_command, bosh_vms_value = connect_to_bosh(password, url, username)
|
63
|
+
|
64
|
+
stop_sequence = get_job_sequence(bosh_vms_value).reverse
|
65
|
+
|
66
|
+
logger.info("Preparing to stop instances #{stop_sequence.join(', ')}")
|
67
|
+
Net::SSH.start(URI.parse(url).host, 'ubuntu', keys: [key_path]) do |ssh|
|
68
|
+
stop_sequence.each do |job_name|
|
69
|
+
exec_ssh ssh, "#{bosh_command} #{stop_command(job_name)}"
|
70
|
+
logger.info "Stopped #{job_name}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
logger.info 'All instances stopped'
|
74
|
+
end
|
75
|
+
|
76
|
+
def connect_to_bosh(password, url, username)
|
77
|
+
logger.info("Connecting to OpsMan at #{url}")
|
78
|
+
ops_man = PcfPause::OpsManInfo.new(url, username, password)
|
79
|
+
|
80
|
+
manifest = ops_man.get_director_manifest
|
81
|
+
uaa_secret = manifest['jobs'][0]['properties']['uaa']['clients']['ops_manager']['secret']
|
82
|
+
director_ip = manifest['jobs'][0]['properties']['director']['address']
|
83
|
+
|
84
|
+
product_id = ops_man.get_product_id 'cf'
|
85
|
+
bosh_vms_value = ops_man.get_vm_names product_id
|
86
|
+
bosh_command = "BOSH_CLIENT=ops_manager BOSH_CLIENT_SECRET=#{uaa_secret} BUNDLE_GEMFILE=/home/tempest-web/tempest/web/vendor/bosh/Gemfile bundle exec bosh -n --ca-cert /var/tempest/workspaces/default/root_ca_certificate -d /var/tempest/workspaces/default/deployments/#{product_id}.yml -t #{director_ip}"
|
87
|
+
return bosh_command, bosh_vms_value
|
88
|
+
end
|
89
|
+
|
90
|
+
def start_command
|
91
|
+
"start --force"
|
92
|
+
end
|
93
|
+
|
94
|
+
def stop_command(job_name)
|
95
|
+
"stop #{job_name} --hard"
|
96
|
+
end
|
97
|
+
|
98
|
+
def smoke_tests_command
|
99
|
+
"run errand smoke-tests"
|
100
|
+
end
|
101
|
+
|
102
|
+
def exec_ssh(ssh, command)
|
103
|
+
logger.debug 'SSH: executing command'
|
104
|
+
ssh.exec!(command) do |ch, stream, data|
|
105
|
+
puts data
|
106
|
+
ch.on_request "exit-status" do |ch, data|
|
107
|
+
exit_status = data.read_long
|
108
|
+
raise "process terminated with exit status: #{exit_status}" if exit_status != 0
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Copyright (c) 2014-2015 Pivotal Software, Inc. All rights reserved.
|
2
|
+
#
|
3
|
+
# Unauthorized use, copying or distribution of this source code via any
|
4
|
+
# medium is strictly prohibited without the express written consent of
|
5
|
+
# Pivotal Software, Inc.
|
6
|
+
#
|
7
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
8
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
9
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
10
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
11
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
12
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
13
|
+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
14
|
+
|
15
|
+
module PcfPause
|
16
|
+
VERSION = '0.9.0'
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pcf_pause
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- CF London
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: cf-uaa-lib
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.6.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.6.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: net-ssh
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.2.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.2.0
|
41
|
+
description: Tool for stopping & starting ERT
|
42
|
+
email:
|
43
|
+
- cf-london-eng@pivotal.io
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- lib/pcf_pause.rb
|
49
|
+
- lib/pcf_pause/ops_man_info.rb
|
50
|
+
- lib/pcf_pause/pause.rb
|
51
|
+
- lib/pcf_pause/version.rb
|
52
|
+
homepage:
|
53
|
+
licenses:
|
54
|
+
- Nonstandard
|
55
|
+
metadata: {}
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 2.6.4
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: Tool for stopping & starting ERT
|
76
|
+
test_files: []
|