ops_manager_ui_drivers 2.14.3 → 2.15.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d8e35fdf9dfff96f59baf9d476fbe393f1dbdc26
4
- data.tar.gz: 7240dd8cd471e988da0ae5ca65833d24a3e329f1
3
+ metadata.gz: c45001ce98bb2a4efab352dab6ffd5ea2c5b187b
4
+ data.tar.gz: a6ef7b349af55bb39712680321d4cdb80d22aebc
5
5
  SHA512:
6
- metadata.gz: ac2c0b7209fcd7adc283f1cafbfb8beb4bb95d054b076fcf77d48c73630b42e4eda21ea4b1d54925f952edea503ea311dbfd224256e4babf230eff0e40076f03
7
- data.tar.gz: c6e08245e59afb8a67d801c2e103692b340e018e5996791d5524c48602b90e0871faca6068f78d2fd432e66f99c333282c8f584138b48b0499f8fcc89ed38932
6
+ metadata.gz: f5750f46ddb83d02a73f35ca00c5a83e2b1c589019e5d5e67eb5590da80bb6c2e46caa495e02d2d6501b4ad88f7bb5eb570daa5ee18c37f56b65af4b15c50365
7
+ data.tar.gz: 1fd9d5be73d833095a53e3e3357a9535ce9eabca1bf218d51135d2d0d870e696b521d9bed1d9e1819957c68816683ec26bc7502118c1b222dd993c1b580da158
@@ -1,3 +1,3 @@
1
1
  module OpsManagerUiDrivers
2
- VERSION = '2.14.3'
2
+ VERSION = '2.15.0'
3
3
  end
@@ -1,9 +1,135 @@
1
1
  require 'ops_manager_ui_drivers/version17/api'
2
2
  require 'uaa'
3
+ require 'net/http/post/multipart'
3
4
 
4
5
  module OpsManagerUiDrivers
5
6
  module Version18
6
7
  class Api < Version17::Api
8
+ SETUP_PATH = 'api/v0/setup'
9
+ PRODUCTS_PATH = 'api/v0/staged/products'
10
+ PRODUCTS_UPLOAD_PATH = 'api/v0/available_products'
11
+ STEMCELLS_UPLOAD_PATH = 'api/v0/stemcells'
12
+ NETWORKS_AND_AZS_PATH = PRODUCTS_PATH + '/:product_id/networks_and_azs'
13
+
14
+
15
+ def internal_setup!
16
+ setup_params = {
17
+ eula_accepted: 'true',
18
+ admin_user_name: @username,
19
+ admin_password: @password,
20
+ admin_password_confirmation: @password,
21
+ decryption_passphrase: @password,
22
+ decryption_passphrase_confirmation: @password,
23
+ identity_provider: 'internal',
24
+ }
25
+
26
+ post_request(endpoint: SETUP_PATH, params: setup_params)
27
+ end
28
+
29
+ def add_product!(name:, product_version:)
30
+ params = {
31
+ name: name,
32
+ product_version: product_version
33
+ }
34
+
35
+ post_request(endpoint: PRODUCTS_PATH, params: params)
36
+ end
37
+
38
+ def upload_product_zip(path:)
39
+ post_file(
40
+ endpoint: PRODUCTS_UPLOAD_PATH,
41
+ path: path,
42
+ type: 'application/zip') do |file_param|
43
+ {
44
+ 'product' => {
45
+ 'file' => file_param
46
+ }
47
+ }
48
+ end
49
+ end
50
+
51
+ def upload_stemcell(path:)
52
+ post_file(
53
+ endpoint: STEMCELLS_UPLOAD_PATH,
54
+ path: path,
55
+ type: 'application/zip') do |file_param|
56
+ {
57
+ 'stemcell' => {
58
+ 'file' => file_param
59
+ }
60
+ }
61
+ end
62
+ end
63
+
64
+ def assign_azs_and_network(product_guid:, singleton_availability_zone:, availability_zones:, network:, service_network: nil)
65
+ params = {
66
+ networks_and_azs: {
67
+ singleton_availability_zone: { name: singleton_availability_zone },
68
+ other_availability_zones: availability_zones.map{|az| { name: az } },
69
+ network: { name: network },
70
+ }
71
+ }
72
+
73
+ params[:networks_and_azs].merge!(service_network: { name: service_network }) if service_network
74
+
75
+ endpoint = url_for_product(product_id: product_guid, route: NETWORKS_AND_AZS_PATH)
76
+ put_request(endpoint: endpoint, params: params)
77
+ end
78
+
79
+ def product_guid(product_name:)
80
+ response = get_request(endpoint: PRODUCTS_PATH)
81
+
82
+ JSON.parse(response.body).find {|product_hash| product_hash['type'] == product_name }['guid']
83
+ end
84
+
85
+ private
86
+
87
+ def url_for_product(product_id:, route:)
88
+ route.gsub(':product_id', product_id)
89
+ end
90
+
91
+ def post_file(endpoint:, path:, type:)
92
+ conn = faraday_connection { |faraday |faraday.request :multipart }
93
+ body = yield(Faraday::UploadIO.new(path, type))
94
+
95
+ faraday_request(method: :post, conn: conn, body: body, endpoint: endpoint)
96
+ end
97
+
98
+ def get_request(endpoint:)
99
+ faraday_request(method: :get, endpoint: endpoint)
100
+ end
101
+
102
+ def post_request(endpoint:, params:)
103
+ json_body = params.to_json
104
+
105
+ faraday_request(method: :post, body: json_body, endpoint: endpoint) do |req|
106
+ req.headers['Content-Type'] = 'application/json'
107
+ end
108
+ end
109
+
110
+ def put_request(endpoint:, params:)
111
+ json_body = params.to_json
112
+
113
+ faraday_request(method: :put, body: json_body, endpoint: endpoint) do |req|
114
+ req.headers['Content-Type'] = 'application/json'
115
+ end
116
+ end
117
+
118
+ def faraday_request(conn: faraday_connection, endpoint:, body: nil, method: )
119
+ conn.send(method) do |req|
120
+ yield(req) if block_given?
121
+ req.body = body if body
122
+ req.url(endpoint)
123
+ req.headers['Authorization'] = uaa_token.auth_header
124
+ end
125
+ end
126
+
127
+ def faraday_connection
128
+ Faraday.new(:url => @host_uri) do |faraday|
129
+ yield(faraday) if block_given?
130
+ faraday.adapter :net_http
131
+ end
132
+ end
7
133
 
8
134
  end
9
135
  end
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency 'capybara-webkit'
24
24
  spec.add_dependency 'selenium-webdriver'
25
25
  spec.add_dependency 'cf-uaa-lib'
26
+ spec.add_dependency 'faraday'
26
27
 
27
28
  spec.add_development_dependency 'bundler'
28
29
  spec.add_development_dependency 'pry'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ops_manager_ui_drivers
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.14.3
4
+ version: 2.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pivotal, Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-12 00:00:00.000000000 Z
11
+ date: 2016-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: bundler
85
99
  requirement: !ruby/object:Gem::Requirement