cwp 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +130 -0
- data/Rakefile +2 -0
- data/bin/cwp +57 -0
- data/cwp.gemspec +22 -0
- data/lib/commands/cwp_api.rb +1 -0
- data/lib/commands/platform.rb +260 -0
- data/lib/cwp/version.rb +3 -0
- data/lib/cwp.rb +59 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MDExZmI2NGM5ZmZiNDFjNzIyZmU4Yjg2MjlmNTgwYTQ4N2Q1NTlhYw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MjIzNGUzZWU5Yjg5Yzk2YTIyNjM4YjZlNGZkNWY1OTNkODdiNjA5Mw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NjhiODJmMDVjMjRmNGViMWQ0MTE1ODI0MmJhYWYwOTM1YjNlNWFiYThmODZi
|
10
|
+
NTA2Y2MzNDlkYjM2NTM2NDI3NjUwMzJlOGY5YzYwMmIwODBkYzc2ZGI0NWI2
|
11
|
+
ZWE0YTU5OTE3YzM5MTc5MTBlZWI4ZDBhYWRiZGY4M2JjYTRmMGQ=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MDFkY2RjZGMyNjU5ZTIzMzFkYmRiMTVhMzcyZGYyNThlN2U1NGM3ZmZkYTZi
|
14
|
+
NTAxMzJiYmY4YzFhOTBjMmQ3MDQxOTJiOGU4NTdlMzdjYzczYzMxN2ZlNGMz
|
15
|
+
ZGZjNTg1MGM1M2VjYmEzZTYyMmVjMjcxM2U5OTAyNTk2NTQ5NGI=
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Nagendra HD
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
# Cloud Web Portal - command line interface [ CLI ]
|
2
|
+
|
3
|
+
Cloud Web Portal Gem is used to trigger commands that facilitate the cloud web portal platform deployment through command line. This Gem-plugin provides full API usage through command line [ CLI ] and helps users to execute commands locally.
|
4
|
+
|
5
|
+
## Installation of Gem
|
6
|
+
|
7
|
+
Follow the below commands to install
|
8
|
+
|
9
|
+
Install it yourself as:
|
10
|
+
|
11
|
+
$ gem install cwp
|
12
|
+
|
13
|
+
Or
|
14
|
+
|
15
|
+
git clone git@sysgit01.lab.services.ingenico.com:nhd/cloud_web_portal_cli.git
|
16
|
+
|
17
|
+
cd cloud_web_portal_cli
|
18
|
+
|
19
|
+
rake install
|
20
|
+
|
21
|
+
NOTE: If there is an error in rake install please install the below rake Gem.
|
22
|
+
|
23
|
+
gem install rake
|
24
|
+
|
25
|
+
Or
|
26
|
+
|
27
|
+
Add this line to your application's Gemfile:
|
28
|
+
|
29
|
+
gem 'cwp'
|
30
|
+
|
31
|
+
And then execute:
|
32
|
+
|
33
|
+
$ bundle
|
34
|
+
|
35
|
+
|
36
|
+
## Commands & Usage Example
|
37
|
+
|
38
|
+
## Help
|
39
|
+
|
40
|
+
cwp help
|
41
|
+
|
42
|
+
This command gives full list of help document and commands list with description.
|
43
|
+
|
44
|
+
## Deploy Platform
|
45
|
+
|
46
|
+
cwp deploy [ ARGUMENTS ]
|
47
|
+
|
48
|
+
This command is used to deploy a platform on cloud web portal.
|
49
|
+
|
50
|
+
*** ARGUMENTS EXAMPLE ***
|
51
|
+
|
52
|
+
a ] Arguments Could be a config_path from user uploading file with YAML contents as follows:
|
53
|
+
|
54
|
+
cwp deploy config_path=custom_file_path
|
55
|
+
|
56
|
+
b ] Arguments could be configuration parameters passed manually as follows:
|
57
|
+
|
58
|
+
cwp deploy reference_name=xxx instance=yyy compute_resource=equador organization=Indecomm blueprint=/home/user/Desktop/blue_pass.yaml login=nagendra password=******* url="http://example.com"
|
59
|
+
|
60
|
+
c ] Configuration parameters can be set in one of the below paths
|
61
|
+
1 ] "/etc/cwp.conf"
|
62
|
+
2 ] "HOME_DIR/user/.cwp/cwp.conf"
|
63
|
+
3 ] "CURRENT_DIRECTORY/cwp.conf"
|
64
|
+
|
65
|
+
Configuiration parameters file format
|
66
|
+
|
67
|
+
parameters:
|
68
|
+
blueprint: "/home/user/Desktop/blueprint.yaml"
|
69
|
+
reference_name: dev
|
70
|
+
baseline: "xxx"
|
71
|
+
instance: "yyy"
|
72
|
+
compute_resource: "equador"
|
73
|
+
organization: "Indecomm"
|
74
|
+
login: "nagendra"
|
75
|
+
password: "*******"
|
76
|
+
url: "http://example.com"
|
77
|
+
|
78
|
+
|
79
|
+
## Check Status Of Platform
|
80
|
+
|
81
|
+
cwp status [ ARGUMENTS ]
|
82
|
+
|
83
|
+
cwp status env=dev-001 login=nagendra password=******
|
84
|
+
|
85
|
+
[ NOTE ] configuration parameters can be set as the same way mentioned in cwp deploy command.
|
86
|
+
|
87
|
+
## Check Status Of Platform with WAIT
|
88
|
+
|
89
|
+
cwp wait [ ARGUMENTS ]
|
90
|
+
|
91
|
+
cwp wait status=completed env=dev-001 login=nagendra password=******
|
92
|
+
|
93
|
+
[ TIMEOUT ] additional configuration parameter can be passed to ovverride timeout
|
94
|
+
|
95
|
+
cwp wait [ ARGUMENT ] timeout= [ 3h or 30m or 3d ]
|
96
|
+
|
97
|
+
Timeout in hours, minutes and days [ DEFAULT is set to 2 hours if timeout parameter is not passed ]
|
98
|
+
|
99
|
+
[ NOTE ] configuration parameters can be set as the same way mentioned in cwp deploy command.
|
100
|
+
|
101
|
+
## Error Codes
|
102
|
+
|
103
|
+
error status is 0 when status=installed
|
104
|
+
error status is 1 when status=failed
|
105
|
+
timeout status 2 hours status=timeout
|
106
|
+
|
107
|
+
## Delete Platform
|
108
|
+
|
109
|
+
This command is used to delete a platform that is deployed.
|
110
|
+
|
111
|
+
cwp delete [ ARGUMENTS ]
|
112
|
+
|
113
|
+
cwp delete env=dev-001 login=nagendra password=******
|
114
|
+
|
115
|
+
[ NOTE ] configuration parameters can be set as the same way mentioned in cwp deploy command.
|
116
|
+
|
117
|
+
## Copyright
|
118
|
+
This program is free software: you can redistribute it and/or modify
|
119
|
+
it under the terms of the GNU General Public License as published by
|
120
|
+
the Free Software Foundation, either version 3 of the License, or
|
121
|
+
(at your option) any later version.
|
122
|
+
|
123
|
+
This program is distributed in the hope that it will be useful,
|
124
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
125
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
126
|
+
GNU General Public License for more details.
|
127
|
+
|
128
|
+
You should have received a copy of the GNU General Public License
|
129
|
+
along with this program. If not, see http://www.gnu.org/licenses/.
|
130
|
+
|
data/Rakefile
ADDED
data/bin/cwp
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'cwp'
|
3
|
+
|
4
|
+
command = Cwp::Command.new
|
5
|
+
if !ARGV[0].nil?
|
6
|
+
settings = Hash.new
|
7
|
+
# configuration file candidates in order of priority
|
8
|
+
candidates =
|
9
|
+
if RUBY_PLATFORM =~ /linux/
|
10
|
+
[ "/etc/cwp.conf", "#{File.expand_path('~')}/.cwp/cwp.conf", "#{File.expand_path('.')}/cwp.conf"]
|
11
|
+
else
|
12
|
+
[]
|
13
|
+
end
|
14
|
+
# populate all the command line parameters in arr
|
15
|
+
arr = []
|
16
|
+
ARGV.each do |value|
|
17
|
+
arr << value.split("=") if value.include?("=")
|
18
|
+
end
|
19
|
+
hash = Hash[arr.collect { |v,f| [v, f] }]
|
20
|
+
if !hash["config_path"].nil?
|
21
|
+
candidates[3] = hash["config_path"]
|
22
|
+
end
|
23
|
+
for candidate in candidates
|
24
|
+
begin
|
25
|
+
settings = YAML.load(File.read("#{candidate}"))
|
26
|
+
rescue Exception => e
|
27
|
+
end
|
28
|
+
end
|
29
|
+
if settings.empty?
|
30
|
+
settings = { "parameters" => Hash[arr.collect { |v,f| [v, f] }] }
|
31
|
+
else
|
32
|
+
hash.each do |key,value|
|
33
|
+
settings["parameters"]["#{key}"] = "#{value}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
if settings["parameters"].empty?
|
37
|
+
puts "[ ERROR ]".colorize(:red)+" There are no configuration parameters passed to deploy command".colorize(:blue)
|
38
|
+
command.configuration_help_text
|
39
|
+
exit
|
40
|
+
else
|
41
|
+
if ARGV[0] == "help"
|
42
|
+
command.help
|
43
|
+
elsif ARGV[0] == "deploy"
|
44
|
+
command.deploy_from_params(settings)
|
45
|
+
elsif ARGV[0] == "delete"
|
46
|
+
command.delete(settings)
|
47
|
+
elsif ARGV[0] == "status"
|
48
|
+
command.status(settings)
|
49
|
+
elsif ARGV[0] == "wait"
|
50
|
+
command.wait(settings)
|
51
|
+
else
|
52
|
+
puts "[ Command Not Found ]".colorize(:red)+" Please enter a valid argument to cwp command ".colorize(:white)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
else
|
56
|
+
command.help
|
57
|
+
end
|
data/cwp.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cwp/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "cwp"
|
8
|
+
s.version = Cwp::VERSION
|
9
|
+
s.authors = ["Nagendra HD"]
|
10
|
+
s.email = ["nagendra.hd@indecomm.net"]
|
11
|
+
s.summary = %q{Command line interface for Cloud Web Portal}
|
12
|
+
s.description = %q{CWP gem allows you to deploy multiple platforms through command line. CWP Gem also facilitates the full usage of Cloud Web Portal API through command line. For more details read the CWP Github ReadMe documentation}
|
13
|
+
s.homepage = ""
|
14
|
+
s.license = "MIT"
|
15
|
+
s.files = `git ls-files`.split($\)
|
16
|
+
s.executables = ["cwp"]
|
17
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
s.add_dependency "colorize","~> 0.7.3"
|
20
|
+
# s.add_development_dependency "bundler", "~> 1.6"
|
21
|
+
# s.add_development_dependency "rake"
|
22
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'commands/platform.rb'
|
@@ -0,0 +1,260 @@
|
|
1
|
+
module Platform
|
2
|
+
# build hash from arguments
|
3
|
+
def self.process_from_arguments(params)
|
4
|
+
if self.validate(params)
|
5
|
+
self.create(params)
|
6
|
+
else
|
7
|
+
exit
|
8
|
+
end
|
9
|
+
end
|
10
|
+
# validate hash either from yaml file or arguments
|
11
|
+
def self.validate(hash)
|
12
|
+
has_error = true
|
13
|
+
if(hash["parameters"]["blueprint"].nil?)
|
14
|
+
has_error = false
|
15
|
+
puts "[ ERROR ]".colorize(:red)+" blueprint is mandatory. Please specify in configuration file or in command line.".colorize(:white)
|
16
|
+
end
|
17
|
+
if(hash["parameters"]["url"].nil?)
|
18
|
+
has_error = false
|
19
|
+
puts "[ ERROR ]".colorize(:red)+" url is mandatory. Please specify in configuration file or in command line.".colorize(:white)
|
20
|
+
end
|
21
|
+
if(hash["parameters"]["reference_name"].nil?)
|
22
|
+
has_error = false
|
23
|
+
puts "[ ERROR ]".colorize(:red)+" reference_name is mandatory. Please specify in configuration file or in command line.".colorize(:white)
|
24
|
+
end
|
25
|
+
if(hash["parameters"]["baseline"].nil?)
|
26
|
+
has_error = false
|
27
|
+
puts "[ ERROR ]".colorize(:red)+" baseline is mandatory. Please specify in configuration file or in command line.".colorize(:white)
|
28
|
+
end
|
29
|
+
if(hash["parameters"]["instance"].nil?)
|
30
|
+
has_error = false
|
31
|
+
puts "[ ERROR ]".colorize(:red)+" instance is mandatory. Please specify in configuration file or in command line.".colorize(:white)
|
32
|
+
end
|
33
|
+
if(hash["parameters"]["compute_resource"].nil?)
|
34
|
+
has_error = false
|
35
|
+
puts "[ ERROR ]".colorize(:red)+" compute_resource is mandatory. Please specify in configuration file or in command line.".colorize(:white)
|
36
|
+
end
|
37
|
+
if(hash["parameters"]["organization"].nil?)
|
38
|
+
has_error = false
|
39
|
+
puts "[ ERROR ]".colorize(:red)+" organization is mandatory. Please specify in configuration file or in command line.".colorize(:white)
|
40
|
+
end
|
41
|
+
if(hash["parameters"]["login"].nil?)
|
42
|
+
has_error = false
|
43
|
+
puts "[ ERROR ]".colorize(:red)+" login is mandatory. Please specify in configuration file or in command line.".colorize(:white)
|
44
|
+
end
|
45
|
+
if(hash["parameters"]["password"].nil?)
|
46
|
+
has_error = false
|
47
|
+
puts "[ ERROR ]".colorize(:red)+" password is mandatory. Please specify in configuration file or in command line.".colorize(:white)
|
48
|
+
end
|
49
|
+
return has_error
|
50
|
+
end
|
51
|
+
# create a new platform on cwp
|
52
|
+
def self.create(hash)
|
53
|
+
bc = self.validate_blueprint(hash["parameters"]["blueprint"])
|
54
|
+
oc = self.organization_and_compute_resource(hash)
|
55
|
+
begin
|
56
|
+
url = URI.parse("#{hash['parameters']['url']}/api/platforms/deploy")
|
57
|
+
http = Net::HTTP.new(url.host, url.port)
|
58
|
+
request = Net::HTTP::Post.new(url.request_uri)
|
59
|
+
request.set_form_data({ "baseline" => hash["parameters"]["baseline"], "instance" => hash["parameters"]["instance"], "reference_name" => hash["parameters"]["reference_name"], "yaml_content" => bc, "compute_resource_id" => oc["compute_resource_id"], "organization_id" => oc["organization_id"] })
|
60
|
+
request.basic_auth(hash["parameters"]['login'],hash["parameters"]['password'])
|
61
|
+
response = http.request(request)
|
62
|
+
rescue Exception => e
|
63
|
+
puts "[ ERROR ]".colorize(:red)+" Invalid url: Please enter a valid url.".colorize(:white)
|
64
|
+
puts "[ EXCEPTION LOG DETAILS ]".colorize(:red)
|
65
|
+
puts e
|
66
|
+
exit
|
67
|
+
end
|
68
|
+
begin
|
69
|
+
# Pretty print response json from API
|
70
|
+
puts "[ RESPONSE CODE ]".colorize(:blue)
|
71
|
+
puts response.code.colorize(:white)
|
72
|
+
puts "[ RESPONSE JSON ]".colorize(:blue)
|
73
|
+
puts JSON.pretty_generate(JSON.parse(response.body)).colorize(:white)
|
74
|
+
rescue Exception => e
|
75
|
+
puts response.body
|
76
|
+
end
|
77
|
+
end
|
78
|
+
# validate the blueprint file path in params
|
79
|
+
def self.validate_blueprint(blueprint)
|
80
|
+
if (File.extname(blueprint) != ".yaml")
|
81
|
+
puts "[ ERROR ]".colorize(:red)+" Invalid blueprint file, File should be of .yaml extension.".colorize(:white)
|
82
|
+
exit
|
83
|
+
else
|
84
|
+
begin
|
85
|
+
File.read(blueprint)
|
86
|
+
rescue Exception => e
|
87
|
+
puts "[ ERROR ]".colorize(:red)+" Could not read blueprint file path, upload a valid file path.".colorize(:white)
|
88
|
+
puts "[ EXCEPTION LOG DETAILS ]".colorize(:red)
|
89
|
+
puts e
|
90
|
+
exit
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
# Set organization and compute resource ID as setters
|
95
|
+
def self.organization_and_compute_resource(params)
|
96
|
+
begin
|
97
|
+
url = URI.parse("#{params['parameters']['url']}/api/organizations/#{params['parameters']['organization']}/compute_resources")
|
98
|
+
http = Net::HTTP.new(url.host, url.port)
|
99
|
+
request = Net::HTTP::Get.new(url.request_uri)
|
100
|
+
request.basic_auth(params["parameters"]['login'],params["parameters"]['password'])
|
101
|
+
response = http.request(request)
|
102
|
+
organization_compute_resources = JSON.parse(response.body)
|
103
|
+
Hash["organization_id" => organization_compute_resources["organization_id"], "compute_resource_id" => self.fetch_compute_resource_id(params, organization_compute_resources["compute_resources"])]
|
104
|
+
rescue Exception => e
|
105
|
+
puts "[ ERROR ]".colorize(:red)+" Invalid url: Please enter a valid url.".colorize(:white)
|
106
|
+
puts "[ EXCEPTION LOG DETAILS ]".colorize(:red)
|
107
|
+
puts e
|
108
|
+
exit
|
109
|
+
end
|
110
|
+
end
|
111
|
+
# Match for right compute resource and fetch the ID
|
112
|
+
def self.fetch_compute_resource_id(params, compute_resources)
|
113
|
+
compute_resource_id = ""
|
114
|
+
unless compute_resources.nil?
|
115
|
+
compute_resources.each do |cr|
|
116
|
+
if cr["compute_resource_name"] == params["parameters"]["compute_resource"]
|
117
|
+
compute_resource_id = cr["compute_resource_id"]
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
return compute_resource_id
|
122
|
+
end
|
123
|
+
# Destroy a platform from cwp
|
124
|
+
def self.validate_delete_platform(hash)
|
125
|
+
if self.validate_delete_and_status_params(hash)
|
126
|
+
begin
|
127
|
+
url = URI.parse("#{hash['parameters']['url']}/api/platforms/#{hash['parameters']['env']} ")
|
128
|
+
http = Net::HTTP.new(url.host, url.port)
|
129
|
+
request = Net::HTTP::Delete.new(url.request_uri)
|
130
|
+
request.basic_auth(hash['parameters']['login'],hash['parameters']['password'])
|
131
|
+
response = http.request(request)
|
132
|
+
rescue Exception => e
|
133
|
+
puts "[ ERROR ]".colorize(:red)+" Invalid url: Please enter a valid url.".colorize(:white)
|
134
|
+
puts "[ EXCEPTION LOG DETAILS ]".colorize(:red)
|
135
|
+
puts e
|
136
|
+
exit
|
137
|
+
end
|
138
|
+
begin
|
139
|
+
# Pretty print response json from API
|
140
|
+
puts "[ RESPONSE CODE ]".colorize(:blue)
|
141
|
+
puts response.code.colorize(:white)
|
142
|
+
puts "[ RESPONSE JSON ]".colorize(:blue)
|
143
|
+
puts JSON.pretty_generate(JSON.parse(response.body)).colorize(:white)
|
144
|
+
rescue Exception => e
|
145
|
+
puts response.body
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
# method to return status log
|
150
|
+
def self.validate_and_check_status(hash)
|
151
|
+
if self.validate_delete_and_status_params(hash)
|
152
|
+
response = self.call_status_api(hash)
|
153
|
+
self.print_status(response)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
# wait status method
|
157
|
+
def self.validate_and_check_wait_status(hash)
|
158
|
+
if hash["parameters"]["status"].nil?
|
159
|
+
puts "[ ERROR ]".colorize(:red)+" Please enter status=xxx".colorize(:white)
|
160
|
+
self.validate_delete_and_status_params(hash)
|
161
|
+
exit
|
162
|
+
else
|
163
|
+
if self.validate_delete_and_status_params(hash)
|
164
|
+
timeout_limit = hash["parameters"]["timeout"].nil? ? "2h".split("") : hash["parameters"]["timeout"].split("")
|
165
|
+
custom_timeout =
|
166
|
+
begin
|
167
|
+
if (timeout_limit[1].downcase == "m")
|
168
|
+
timeout_limit[0].to_i
|
169
|
+
elsif (timeout_limit[1].downcase == "h")
|
170
|
+
( timeout_limit[0].to_i * 60 )
|
171
|
+
elsif (timeout_limit[1].downcase == "d")
|
172
|
+
( 24*60*timeout_limit[0].to_i )
|
173
|
+
else
|
174
|
+
( 2*60 )
|
175
|
+
end
|
176
|
+
rescue Exception => e
|
177
|
+
( 2*60 )
|
178
|
+
end
|
179
|
+
# untill custom timeout is expired.
|
180
|
+
(custom_timeout+1).times do |num|
|
181
|
+
if ( num == custom_timeout )
|
182
|
+
puts "[ TIMEOUT ]".colorize(:red)+" error status code 2".colorize(:white)
|
183
|
+
exit
|
184
|
+
else
|
185
|
+
response = self.call_status_api(hash)
|
186
|
+
begin
|
187
|
+
body = JSON.parse(response.body)
|
188
|
+
if (body["deploy_status"]["status"] == "failed")
|
189
|
+
puts "[ PLATFORM DEPLOYMENT FAILED ]".colorize(:red)+" error status code 1".colorize(:white)
|
190
|
+
self.print_status(response)
|
191
|
+
break
|
192
|
+
else
|
193
|
+
if (body["deploy_status"]["status"] == hash["parameters"]["status"])
|
194
|
+
puts "[ PLATFORM DEPLOYED SUCCESSFULLY ]".colorize(:green)+" error status code 0".colorize(:white)
|
195
|
+
self.print_status(response)
|
196
|
+
break
|
197
|
+
else
|
198
|
+
self.print_status(response)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
rescue Exception => e
|
202
|
+
self.print_status(response)
|
203
|
+
break
|
204
|
+
end
|
205
|
+
end
|
206
|
+
puts "[ CHECKING STATUS PLEASE WAIT ] ".colorize(:yellow)
|
207
|
+
sleep(60)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
# validate delete hash
|
213
|
+
def self.validate_delete_and_status_params(hash)
|
214
|
+
has_error = true
|
215
|
+
if hash["parameters"]["env"].nil?
|
216
|
+
puts "[ ERROR ]".colorize(:red)+" Please enter env=environment_name".colorize(:white)
|
217
|
+
has_error = false
|
218
|
+
end
|
219
|
+
if hash["parameters"]["login"].nil?
|
220
|
+
puts "[ ERROR ]".colorize(:red)+" Please enter login=xyz".colorize(:white)
|
221
|
+
has_error = false
|
222
|
+
end
|
223
|
+
if hash["parameters"]["password"].nil?
|
224
|
+
puts "[ ERROR ]".colorize(:red)+" Please enter password=***".colorize(:white)
|
225
|
+
has_error = false
|
226
|
+
end
|
227
|
+
if hash["parameters"]["url"].nil?
|
228
|
+
puts "[ ERROR ]".colorize(:red)+" Please enter url".colorize(:white)
|
229
|
+
has_error = false
|
230
|
+
end
|
231
|
+
return has_error
|
232
|
+
end
|
233
|
+
# make api call to check platform status.
|
234
|
+
def self.call_status_api(hash)
|
235
|
+
begin
|
236
|
+
url = URI.parse("#{hash['parameters']['url']}/api/platforms/#{hash['parameters']['env']}/status_check")
|
237
|
+
http = Net::HTTP.new(url.host, url.port)
|
238
|
+
request = Net::HTTP::Get.new(url.request_uri)
|
239
|
+
request.basic_auth(hash['parameters']['login'],hash['parameters']['password'])
|
240
|
+
http.request(request)
|
241
|
+
rescue Exception => e
|
242
|
+
puts "[ ERROR ]".colorize(:red)+" Invalid url: Please enter a valid url.".colorize(:white)
|
243
|
+
puts "[ EXCEPTION LOG DETAILS ]".colorize(:red)
|
244
|
+
puts e
|
245
|
+
exit
|
246
|
+
end
|
247
|
+
end
|
248
|
+
# print status check common for wait and status
|
249
|
+
def self.print_status(response)
|
250
|
+
begin
|
251
|
+
# Pretty print response json from API
|
252
|
+
puts "[ RESPONSE CODE ]".colorize(:blue)
|
253
|
+
puts response.code.colorize(:white)
|
254
|
+
puts "[ RESPONSE JSON ]".colorize(:blue)
|
255
|
+
puts JSON.pretty_generate(JSON.parse(response.body)).colorize(:white)
|
256
|
+
rescue Exception => e
|
257
|
+
puts response.body
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
data/lib/cwp/version.rb
ADDED
data/lib/cwp.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require "cwp/version"
|
2
|
+
require "colorize"
|
3
|
+
require 'json'
|
4
|
+
require 'yaml'
|
5
|
+
require "commands/cwp_api"
|
6
|
+
require 'net/http'
|
7
|
+
require 'net/https'
|
8
|
+
require 'uri'
|
9
|
+
|
10
|
+
module Cwp
|
11
|
+
class Command
|
12
|
+
def deploy_from_params(params)
|
13
|
+
Platform.process_from_arguments(params)
|
14
|
+
end
|
15
|
+
def delete(params)
|
16
|
+
Platform.validate_delete_platform(params)
|
17
|
+
end
|
18
|
+
def status(params)
|
19
|
+
Platform.validate_and_check_status(params)
|
20
|
+
end
|
21
|
+
def wait(params)
|
22
|
+
Platform.validate_and_check_wait_status(params)
|
23
|
+
end
|
24
|
+
def help
|
25
|
+
puts "[ CLOUD WEB PORTAL COMMANDS ]".colorize(:blue)
|
26
|
+
puts " - cwp deploy [ ARGUMENTS ]".colorize(:white)
|
27
|
+
puts " - cwp status [ ARGUMENTS ]".colorize(:white)
|
28
|
+
puts " - cwp wait status=completed [ ARGUMENTS ]".colorize(:white)
|
29
|
+
puts " - cwp delete [ ARGUMENTS ]".colorize(:white)
|
30
|
+
puts "FOR DETAIL DOC AND ARGUMENTS LIST REFER BELOW README URL".colorize(:yellow)
|
31
|
+
puts " http://sysgit01.lab.services.ingenico.com/nhd/cloud_web_portal_cli/tree/master".colorize(:white)
|
32
|
+
end
|
33
|
+
def configuration_help_text
|
34
|
+
if RUBY_PLATFORM =~ /linux/
|
35
|
+
puts "Please pass configuration parameters through file by one of the below option".colorize(:white)
|
36
|
+
puts "1 ]".colorize(:white)+" /etc/cwp.conf".colorize(:white)
|
37
|
+
puts "2 ]".colorize(:white)+" /HOME_DIR/.cwp/cwp.conf".colorize(:white)
|
38
|
+
puts "3 ]".colorize(:white)+" CURRENT_DIR/cwp.conf".colorize(:white)
|
39
|
+
puts "4 ]".colorize(:white)+" Pass configuration file path as argument EX:".colorize(:white)+" cwp deploy config_path=PATH_TO_YOUR_CONFIGURATION_FILE".colorize(:yellow)
|
40
|
+
puts "[ NOTE ]".colorize(:blue)+" File format of cwp.conf".colorize(:white)
|
41
|
+
puts "parameters:".colorize(:yellow)
|
42
|
+
puts " login:".colorize(:yellow)+" xxx".colorize(:white)
|
43
|
+
puts " password:".colorize(:yellow)+" yyy".colorize(:white)
|
44
|
+
puts " url:".colorize(:yellow)+" http://example.com".colorize(:white)
|
45
|
+
puts " organization:".colorize(:yellow)+" abc".colorize(:white)
|
46
|
+
puts " compute_resource:".colorize(:yellow)+" peru".colorize(:white)
|
47
|
+
else
|
48
|
+
puts "1 ]".colorize(:white)+" Pass configuration file path as argument EX:".colorize(:white)+" cwp deploy config_path=PATH_TO_YOUR_CONFIGURATION_FILE".colorize(:yellow)
|
49
|
+
puts "[ NOTE ]".colorize(:blue)+" File format of cwp.conf".colorize(:white)
|
50
|
+
puts "parameters:".colorize(:yellow)
|
51
|
+
puts " login:".colorize(:yellow)+" xxx".colorize(:white)
|
52
|
+
puts " password:".colorize(:yellow)+" yyy".colorize(:white)
|
53
|
+
puts " url:".colorize(:yellow)+" http://example.com".colorize(:white)
|
54
|
+
puts " organization:".colorize(:yellow)+" abc".colorize(:white)
|
55
|
+
puts " compute_resource:".colorize(:yellow)+" peru".colorize(:white)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cwp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nagendra HD
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colorize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.7.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.7.3
|
27
|
+
description: CWP gem allows you to deploy multiple platforms through command line.
|
28
|
+
CWP Gem also facilitates the full usage of Cloud Web Portal API through command
|
29
|
+
line. For more details read the CWP Github ReadMe documentation
|
30
|
+
email:
|
31
|
+
- nagendra.hd@indecomm.net
|
32
|
+
executables:
|
33
|
+
- cwp
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- bin/cwp
|
43
|
+
- cwp.gemspec
|
44
|
+
- lib/commands/cwp_api.rb
|
45
|
+
- lib/commands/platform.rb
|
46
|
+
- lib/cwp.rb
|
47
|
+
- lib/cwp/version.rb
|
48
|
+
homepage: ''
|
49
|
+
licenses:
|
50
|
+
- MIT
|
51
|
+
metadata: {}
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 2.2.2
|
69
|
+
signing_key:
|
70
|
+
specification_version: 4
|
71
|
+
summary: Command line interface for Cloud Web Portal
|
72
|
+
test_files: []
|