Class: OpsManager::Api::Opsman
- Inherits:
-
Base
- Object
- Base
- OpsManager::Api::Opsman
show all
- Defined in:
- lib/ops_manager/api/opsman.rb
Instance Attribute Summary
Attributes inherited from Base
#silent
Instance Method Summary
collapse
Methods inherited from Base
#add_authentication, #delete, #get, #http_for, #initialize, #multipart_post, #post, #print_green, #put, #say_green, #uri_for
Methods included from Logging
#logger, logger, logger=
Instance Method Details
#add_staged_products(name, version) ⇒ Object
66
67
68
69
70
71
72
73
|
# File 'lib/ops_manager/api/opsman.rb', line 66
def add_staged_products(name, version)
print_green( "====> Adding available product to the installation ...")
body = "name=#{name}&product_version=#{version}"
res = authenticated_post('/api/v0/staged/products', body: body)
raise OpsManager::ProductDeploymentError.new(res.body) if res.code =~ /404|500/
say_green('done')
res
end
|
#create_user ⇒ Object
9
10
11
12
|
# File 'lib/ops_manager/api/opsman.rb', line 9
def create_user
body= "setup[decryption_passphrase]=#{password}&setup[decryption_passphrase_confirmation]=#{password}&setup[eula_accepted]=true&setup[identity_provider]=internal&setup[admin_user_name]=#{username}&setup[admin_password]=#{password}&setup[admin_password_confirmation]=#{password}"
post("/api/v0/setup" , body: body)
end
|
#delete_products(opts = {}) ⇒ Object
52
53
54
55
56
57
|
# File 'lib/ops_manager/api/opsman.rb', line 52
def delete_products(opts = {})
print_green '====> Deleating unused products ...'
res = authenticated_delete('/api/v0/products', opts)
say_green 'done'
res
end
|
#get_available_products ⇒ Object
114
115
116
|
# File 'lib/ops_manager/api/opsman.rb', line 114
def get_available_products
authenticated_get("/api/v0/available_products")
end
|
#get_diagnostic_report ⇒ Object
118
119
120
121
122
|
# File 'lib/ops_manager/api/opsman.rb', line 118
def get_diagnostic_report
authenticated_get("/api/v0/diagnostic_report")
rescue Errno::ETIMEDOUT , Errno::EHOSTUNREACH, Net::HTTPFatalError, Net::OpenTimeout
nil
end
|
#get_installation(id) ⇒ Object
75
76
77
78
79
|
# File 'lib/ops_manager/api/opsman.rb', line 75
def get_installation(id)
res = authenticated_get("/api/v0/installations/#{id}")
raise OpsManager::InstallationError.new(res.body) if res.body =~ /failed/
res
end
|
#get_installation_assets ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/ops_manager/api/opsman.rb', line 44
def get_installation_assets
opts = { write_to: "installation_assets.zip" }
say_green '====> Download installation assets ...'
res = authenticated_get("/api/v0/installation_asset_collection", opts)
say_green 'done'
res
end
|
#get_installation_logs(id) ⇒ Object
81
82
83
|
# File 'lib/ops_manager/api/opsman.rb', line 81
def get_installation_logs(id)
authenticated_get("/api/v0/installations/#{id}/logs")
end
|
#get_installation_settings(opts = {}) ⇒ Object
28
29
30
31
32
33
|
# File 'lib/ops_manager/api/opsman.rb', line 28
def get_installation_settings(opts = {})
print_green '====> Downloading installation settings ...'
res = authenticated_get("/api/installation_settings", opts)
say_green 'done'
res
end
|
#get_installations(opts = {}) ⇒ Object
89
90
91
92
93
94
|
# File 'lib/ops_manager/api/opsman.rb', line 89
def get_installations(opts = {})
print_green '====> Getting installations ...'
res = authenticated_get('/api/v0/installations')
say_green 'done'
res
end
|
#get_staged_products(opts = {}) ⇒ Object
24
25
26
|
# File 'lib/ops_manager/api/opsman.rb', line 24
def get_staged_products(opts = {})
authenticated_get("/api/v0/staged/products", opts)
end
|
#get_staged_products_errands(product_guid) ⇒ Object
85
86
87
|
# File 'lib/ops_manager/api/opsman.rb', line 85
def get_staged_products_errands(product_guid)
authenticated_get("/api/v0/staged/products/#{product_guid}/errands" )
end
|
#get_token ⇒ Object
156
157
158
159
160
161
162
|
# File 'lib/ops_manager/api/opsman.rb', line 156
def get_token
token_issuer.owner_password_grant(username, password, 'opsman.admin').tap do |token|
logger.info "UAA Token: #{token.inspect}"
end
rescue CF::UAA::TargetError
nil
end
|
#import_stemcell(filepath) ⇒ Object
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
# File 'lib/ops_manager/api/opsman.rb', line 124
def import_stemcell(filepath)
return unless filepath
tar = UploadIO.new(filepath, 'multipart/form-data')
print_green "====> Uploading stemcell: #{tar} ..."
opts = { "stemcell[file]" => tar }
res = nil
3.times do
res = authenticated_multipart_post("/api/v0/stemcells", opts)
case res.code
when '200' ; break
when '503' ; sleep(60)
end
end
raise OpsManager::StemcellUploadError.new(res.body) unless res.code == '200'
say_green 'done'
res
end
|
#password ⇒ Object
148
149
150
|
# File 'lib/ops_manager/api/opsman.rb', line 148
def password
@password ||= OpsManager.get_conf(:password)
end
|
#target ⇒ Object
152
153
154
|
# File 'lib/ops_manager/api/opsman.rb', line 152
def target
@target ||= OpsManager.get_conf(:target)
end
|
#trigger_installation(opts = {}) ⇒ Object
59
60
61
62
63
64
|
# File 'lib/ops_manager/api/opsman.rb', line 59
def trigger_installation(opts = {})
print_green('====> Applying changes')
res = authenticated_post('/api/v0/installations', opts)
raise OpsManager::InstallationError.new(res.body) if res.code =~ /422/
res
end
|
#upgrade_product_installation(guid, product_version) ⇒ Object
96
97
98
99
100
101
102
103
|
# File 'lib/ops_manager/api/opsman.rb', line 96
def upgrade_product_installation(guid, product_version)
print_green "====> Bumping product installation #{guid} product_version to #{product_version} ..."
opts = { to_version: product_version }
res = authenticated_put("/api/v0/staged/products/#{guid}", opts)
raise OpsManager::UpgradeError.new(res.body) unless res.code == '200'
say_green 'done'
res
end
|
#upload_installation_assets ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/ops_manager/api/opsman.rb', line 35
def upload_installation_assets
print_green( '====> Uploading installation assets ...')
zip = UploadIO.new("#{Dir.pwd}/installation_assets.zip", 'application/x-zip-compressed')
opts = {:passphrase => @password, "installation[file]" => zip }
res = multipart_post( "/api/v0/installation_asset_collection", opts)
say_green 'done'
res
end
|
#upload_installation_settings(filepath = 'installation_settings.json') ⇒ Object
14
15
16
17
18
19
20
21
22
|
# File 'lib/ops_manager/api/opsman.rb', line 14
def upload_installation_settings(filepath = 'installation_settings.json')
print_green '====> Uploading installation settings ...'
yaml = UploadIO.new(filepath, 'text/yaml')
opts = { "installation[file]" => yaml}
res = authenticated_multipart_post("/api/installation_settings", opts)
raise OpsManager::InstallationSettingsError.new(res.body) unless res.code == '200'
say_green 'done'
res
end
|
#upload_product(filepath) ⇒ Object
105
106
107
108
109
110
111
112
|
# File 'lib/ops_manager/api/opsman.rb', line 105
def upload_product(filepath)
file = "#{filepath}"
cmd = "curl -s -k \"https://#{target}/api/v0/available_products\" -F 'product[file]=@#{file}' -X POST -H 'Authorization: Bearer #{access_token}'"
logger.info "running cmd: #{cmd}"
body = `#{cmd}`
logger.info "Upload product response: #{body}"
raise OpsManager::ProductUploadError if body.include? "error"
end
|
#username ⇒ Object
144
145
146
|
# File 'lib/ops_manager/api/opsman.rb', line 144
def username
@username ||= OpsManager.get_conf(:username)
end
|