morpheus-cli 2.10.0 → 2.10.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/bin/morpheus +27 -32
  3. data/lib/morpheus/api/accounts_interface.rb +36 -47
  4. data/lib/morpheus/api/api_client.rb +141 -110
  5. data/lib/morpheus/api/app_templates_interface.rb +56 -72
  6. data/lib/morpheus/api/apps_interface.rb +111 -132
  7. data/lib/morpheus/api/auth_interface.rb +30 -0
  8. data/lib/morpheus/api/clouds_interface.rb +71 -76
  9. data/lib/morpheus/api/custom_instance_types_interface.rb +21 -46
  10. data/lib/morpheus/api/dashboard_interface.rb +10 -17
  11. data/lib/morpheus/api/deploy_interface.rb +60 -72
  12. data/lib/morpheus/api/deployments_interface.rb +53 -71
  13. data/lib/morpheus/api/groups_interface.rb +55 -45
  14. data/lib/morpheus/api/instance_types_interface.rb +19 -23
  15. data/lib/morpheus/api/instances_interface.rb +179 -177
  16. data/lib/morpheus/api/key_pairs_interface.rb +11 -17
  17. data/lib/morpheus/api/license_interface.rb +18 -23
  18. data/lib/morpheus/api/load_balancers_interface.rb +54 -69
  19. data/lib/morpheus/api/logs_interface.rb +25 -29
  20. data/lib/morpheus/api/options_interface.rb +13 -17
  21. data/lib/morpheus/api/provision_types_interface.rb +19 -22
  22. data/lib/morpheus/api/roles_interface.rb +75 -94
  23. data/lib/morpheus/api/security_group_rules_interface.rb +28 -37
  24. data/lib/morpheus/api/security_groups_interface.rb +39 -51
  25. data/lib/morpheus/api/servers_interface.rb +113 -115
  26. data/lib/morpheus/api/setup_interface.rb +31 -0
  27. data/lib/morpheus/api/task_sets_interface.rb +36 -38
  28. data/lib/morpheus/api/tasks_interface.rb +56 -69
  29. data/lib/morpheus/api/users_interface.rb +67 -76
  30. data/lib/morpheus/api/virtual_images_interface.rb +61 -61
  31. data/lib/morpheus/api/whoami_interface.rb +12 -15
  32. data/lib/morpheus/cli.rb +71 -60
  33. data/lib/morpheus/cli/accounts.rb +254 -315
  34. data/lib/morpheus/cli/alias_command.rb +219 -0
  35. data/lib/morpheus/cli/app_templates.rb +264 -272
  36. data/lib/morpheus/cli/apps.rb +608 -671
  37. data/lib/morpheus/cli/cli_command.rb +259 -21
  38. data/lib/morpheus/cli/cli_registry.rb +99 -14
  39. data/lib/morpheus/cli/clouds.rb +599 -372
  40. data/lib/morpheus/cli/config_file.rb +126 -0
  41. data/lib/morpheus/cli/credentials.rb +141 -117
  42. data/lib/morpheus/cli/dashboard_command.rb +48 -56
  43. data/lib/morpheus/cli/deployments.rb +254 -268
  44. data/lib/morpheus/cli/deploys.rb +150 -142
  45. data/lib/morpheus/cli/error_handler.rb +38 -0
  46. data/lib/morpheus/cli/groups.rb +551 -179
  47. data/lib/morpheus/cli/hosts.rb +862 -617
  48. data/lib/morpheus/cli/instance_types.rb +103 -95
  49. data/lib/morpheus/cli/instances.rb +1335 -1009
  50. data/lib/morpheus/cli/key_pairs.rb +82 -90
  51. data/lib/morpheus/cli/library.rb +498 -499
  52. data/lib/morpheus/cli/license.rb +83 -101
  53. data/lib/morpheus/cli/load_balancers.rb +314 -300
  54. data/lib/morpheus/cli/login.rb +66 -44
  55. data/lib/morpheus/cli/logout.rb +47 -46
  56. data/lib/morpheus/cli/mixins/accounts_helper.rb +69 -31
  57. data/lib/morpheus/cli/mixins/infrastructure_helper.rb +106 -0
  58. data/lib/morpheus/cli/mixins/print_helper.rb +181 -17
  59. data/lib/morpheus/cli/mixins/provisioning_helper.rb +535 -458
  60. data/lib/morpheus/cli/mixins/whoami_helper.rb +2 -2
  61. data/lib/morpheus/cli/option_parser.rb +35 -0
  62. data/lib/morpheus/cli/option_types.rb +232 -192
  63. data/lib/morpheus/cli/recent_activity_command.rb +61 -65
  64. data/lib/morpheus/cli/remote.rb +446 -199
  65. data/lib/morpheus/cli/roles.rb +884 -906
  66. data/lib/morpheus/cli/security_group_rules.rb +213 -203
  67. data/lib/morpheus/cli/security_groups.rb +237 -192
  68. data/lib/morpheus/cli/shell.rb +338 -231
  69. data/lib/morpheus/cli/tasks.rb +326 -308
  70. data/lib/morpheus/cli/users.rb +457 -462
  71. data/lib/morpheus/cli/version.rb +1 -1
  72. data/lib/morpheus/cli/version_command.rb +16 -18
  73. data/lib/morpheus/cli/virtual_images.rb +526 -345
  74. data/lib/morpheus/cli/whoami.rb +125 -111
  75. data/lib/morpheus/cli/workflows.rb +338 -185
  76. data/lib/morpheus/formatters.rb +8 -1
  77. data/lib/morpheus/logging.rb +1 -1
  78. data/lib/morpheus/rest_client.rb +17 -8
  79. metadata +9 -3
  80. data/lib/morpheus/api/custom_instance_types.rb +0 -55
@@ -1,74 +1,58 @@
1
- require 'json'
2
- require 'rest-client'
1
+ require 'morpheus/api/api_client'
3
2
 
4
3
  class Morpheus::AppTemplatesInterface < Morpheus::APIClient
5
- def initialize(access_token, refresh_token,expires_at = nil, base_url=nil)
6
- @access_token = access_token
7
- @refresh_token = refresh_token
8
- @base_url = base_url
9
- @expires_at = expires_at
10
- end
11
-
12
- def get(id)
13
- raise "#{self.class}.get() passed a blank id!" if id.to_s == ''
14
- url = "#{@base_url}/api/app-templates/#{id}"
15
- headers = { params: {}, authorization: "Bearer #{@access_token}" }
16
- response = Morpheus::RestClient.execute(method: :get, url: url,
17
- timeout: 10, headers: headers)
18
- JSON.parse(response.to_s)
19
- end
20
-
21
- def list(options={})
22
- url = "#{@base_url}/api/app-templates"
23
- headers = { params: {}, authorization: "Bearer #{@access_token}" }
24
- headers[:params].merge!(options)
25
- response = Morpheus::RestClient.execute(method: :get, url: url,
26
- timeout: 10, headers: headers)
27
- JSON.parse(response.to_s)
28
- end
29
-
30
- def create(options)
31
- url = "#{@base_url}/api/app-templates"
32
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
33
- payload = options
34
- response = Morpheus::RestClient.execute(method: :post, url: url,
35
- timeout: 10, headers: headers, payload: payload.to_json)
36
- JSON.parse(response.to_s)
37
- end
38
-
39
- def update(id, options)
40
- url = "#{@base_url}/api/app-templates/#{id}"
41
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
42
- payload = options
43
- response = Morpheus::RestClient.execute(method: :put, url: url,
44
- timeout: 10, headers: headers, payload: payload.to_json)
45
- JSON.parse(response.to_s)
46
- end
47
-
48
- def destroy(id)
49
- url = "#{@base_url}/api/app-templates/#{id}"
50
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
51
- response = Morpheus::RestClient.execute(method: :delete, url: url,
52
- timeout: 10, headers: headers)
53
- JSON.parse(response.to_s)
54
- end
55
-
56
- def list_tiers(options={})
57
- url = "#{@base_url}/api/app-templates/tiers"
58
- headers = { params: {}, authorization: "Bearer #{@access_token}" }
59
- headers[:params].merge!(options)
60
- response = Morpheus::RestClient.execute(method: :get, url: url,
61
- timeout: 10, headers: headers)
62
- JSON.parse(response.to_s)
63
- end
64
-
65
- def list_types(options={})
66
- url = "#{@base_url}/api/app-templates/types"
67
- headers = { params: {}, authorization: "Bearer #{@access_token}" }
68
- headers[:params].merge!(options)
69
- response = Morpheus::RestClient.execute(method: :get, url: url,
70
- timeout: 10, headers: headers)
71
- JSON.parse(response.to_s)
72
- end
73
-
74
- end
4
+ def initialize(access_token, refresh_token,expires_at = nil, base_url=nil)
5
+ @access_token = access_token
6
+ @refresh_token = refresh_token
7
+ @base_url = base_url
8
+ @expires_at = expires_at
9
+ end
10
+
11
+ def get(id)
12
+ raise "#{self.class}.get() passed a blank id!" if id.to_s == ''
13
+ url = "#{@base_url}/api/app-templates/#{id}"
14
+ headers = { params: {}, authorization: "Bearer #{@access_token}" }
15
+ execute(method: :get, url: url, headers: headers)
16
+ end
17
+
18
+ def list(options={})
19
+ url = "#{@base_url}/api/app-templates"
20
+ headers = { params: {}, authorization: "Bearer #{@access_token}" }
21
+ headers[:params].merge!(options)
22
+ execute(method: :get, url: url, headers: headers)
23
+ end
24
+
25
+ def create(options)
26
+ url = "#{@base_url}/api/app-templates"
27
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
28
+ payload = options
29
+ execute(method: :post, url: url, headers: headers, payload: payload.to_json)
30
+ end
31
+
32
+ def update(id, options)
33
+ url = "#{@base_url}/api/app-templates/#{id}"
34
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
35
+ payload = options
36
+ execute(method: :put, url: url, headers: headers, payload: payload.to_json)
37
+ end
38
+
39
+ def destroy(id)
40
+ url = "#{@base_url}/api/app-templates/#{id}"
41
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
42
+ execute(method: :delete, url: url, headers: headers)
43
+ end
44
+
45
+ def list_tiers(options={})
46
+ url = "#{@base_url}/api/app-templates/tiers"
47
+ headers = { params: {}, authorization: "Bearer #{@access_token}" }
48
+ headers[:params].merge!(options)
49
+ execute(method: :get, url: url, headers: headers)
50
+ end
51
+
52
+ def list_types(options={})
53
+ url = "#{@base_url}/api/app-templates/types"
54
+ headers = { params: {}, authorization: "Bearer #{@access_token}" }
55
+ headers[:params].merge!(options)
56
+ execute(method: :get, url: url, headers: headers)
57
+ end
58
+ end
@@ -1,135 +1,114 @@
1
- require 'json'
2
- require 'morpheus/rest_client'
1
+ require 'morpheus/api/api_client'
3
2
 
4
3
  class Morpheus::AppsInterface < Morpheus::APIClient
5
- def initialize(access_token, refresh_token,expires_at = nil, base_url=nil)
6
- @access_token = access_token
7
- @refresh_token = refresh_token
8
- @base_url = base_url
9
- @expires_at = expires_at
10
- end
11
-
12
-
13
- def get(options=nil)
14
- url = "#{@base_url}/api/apps"
15
- headers = { params: {}, authorization: "Bearer #{@access_token}" }
16
-
17
- if options.is_a?(Hash)
18
- headers[:params].merge!(options)
19
- elsif options.is_a?(Numeric)
20
- url = "#{@base_url}/api/apps/#{options}"
21
- elsif options.is_a?(String)
22
- headers[:params]['name'] = options
23
- end
24
- response = Morpheus::RestClient.execute(method: :get, url: url,
25
- timeout: 30, headers: headers)
26
- JSON.parse(response.to_s)
27
- end
28
-
29
- def create(options)
30
- url = "#{@base_url}/api/apps"
31
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
32
-
33
- payload = options
34
- response = Morpheus::RestClient.execute(method: :post, url: url,
35
- timeout: 30, headers: headers, payload: payload.to_json)
36
- JSON.parse(response.to_s)
37
- end
38
-
39
- def update(app_id, options)
40
- url = "#{@base_url}/api/apps/#{app_id}"
41
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
42
-
43
- payload = options
44
- response = Morpheus::RestClient.execute(method: :put, url: url,
45
- timeout: 30, headers: headers, payload: payload.to_json)
46
- JSON.parse(response.to_s)
47
- end
48
-
49
- def add_instance(app_id, options)
50
- url = "#{@base_url}/api/apps/#{app_id}/add-instance"
51
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
52
-
53
- payload = options
54
- response = Morpheus::RestClient.execute(method: :post, url: url,
55
- timeout: 30, headers: headers, payload: payload.to_json)
56
- JSON.parse(response.to_s)
57
- end
58
-
59
- def remove_instance(app_id, options)
60
- url = "#{@base_url}/api/apps/#{app_id}/remove-instance"
61
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
62
-
63
- payload = options
64
- response = Morpheus::RestClient.execute(method: :post, url: url,
65
- timeout: 30, headers: headers, payload: payload.to_json)
66
- JSON.parse(response.to_s)
67
- end
68
-
69
- def destroy(id)
70
- url = "#{@base_url}/api/apps/#{id}"
71
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
72
- response = Morpheus::RestClient.execute(method: :delete, url: url,
73
- timeout: 30, headers: headers)
74
- JSON.parse(response.to_s)
75
- end
76
-
77
- =begin
78
- def stop(id)
79
- url = "#{@base_url}/api/apps/#{id}/stop"
80
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
81
- response = Morpheus::RestClient.execute(method: :put, url: url,
82
- timeout: 30, headers: headers)
83
- JSON.parse(response.to_s)
84
- end
85
-
86
- def start(id)
87
- url = "#{@base_url}/api/apps/#{id}/start"
88
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
89
- response = Morpheus::RestClient.execute(method: :put, url: url,
90
- timeout: 30, headers: headers)
91
- JSON.parse(response.to_s)
92
- end
93
-
94
- def restart(id)
95
- url = "#{@base_url}/api/apps/#{id}/restart"
96
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
97
- response = Morpheus::RestClient.execute(method: :put, url: url,
98
- timeout: 30, headers: headers)
99
- JSON.parse(response.to_s)
100
- end
101
- =end
102
-
103
- def firewall_disable(id)
104
- url = "#{@base_url}/api/apps/#{id}/security-groups/disable"
105
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
106
- response = Morpheus::RestClient.execute(method: :put, url: url,
107
- timeout: 30, headers: headers)
108
- JSON.parse(response.to_s)
109
- end
110
-
111
- def firewall_enable(id)
112
- url = "#{@base_url}/api/apps/#{id}/security-groups/enable"
113
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
114
- response = Morpheus::RestClient.execute(method: :put, url: url,
115
- timeout: 30, headers: headers)
116
- JSON.parse(response.to_s)
117
- end
118
-
119
- def security_groups(id)
120
- url = "#{@base_url}/api/apps/#{id}/security-groups"
121
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
122
- response = Morpheus::RestClient.execute(method: :get, url: url,
123
- timeout: 30, headers: headers)
124
- JSON.parse(response.to_s)
125
- end
126
-
127
- def apply_security_groups(id, options)
128
- url = "#{@base_url}/api/apps/#{id}/security-groups"
129
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
130
- payload = options
131
- response = Morpheus::RestClient.execute(method: :post, url: url,
132
- timeout: 30, headers: headers, payload: payload.to_json)
133
- JSON.parse(response.to_s)
134
- end
4
+ def initialize(access_token, refresh_token,expires_at = nil, base_url=nil)
5
+ @access_token = access_token
6
+ @refresh_token = refresh_token
7
+ @base_url = base_url
8
+ @expires_at = expires_at
9
+ end
10
+
11
+
12
+ def get(options=nil)
13
+ url = "#{@base_url}/api/apps"
14
+ headers = { params: {}, authorization: "Bearer #{@access_token}" }
15
+ if options.is_a?(Hash)
16
+ headers[:params].merge!(options)
17
+ elsif options.is_a?(Numeric)
18
+ url = "#{@base_url}/api/apps/#{options}"
19
+ elsif options.is_a?(String)
20
+ headers[:params]['name'] = options
21
+ end
22
+ opts = {method: :get, url: url, headers: headers}
23
+ execute(opts)
24
+ end
25
+
26
+ def create(options)
27
+ url = "#{@base_url}/api/apps"
28
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
29
+ payload = options
30
+ opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
31
+ execute(opts)
32
+ end
33
+
34
+ def update(app_id, options)
35
+ url = "#{@base_url}/api/apps/#{app_id}"
36
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
37
+ payload = options
38
+ opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
39
+ execute(opts)
40
+ end
41
+
42
+ def add_instance(app_id, options)
43
+ url = "#{@base_url}/api/apps/#{app_id}/add-instance"
44
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
45
+ payload = options
46
+ opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
47
+ execute(opts)
48
+ end
49
+
50
+ def remove_instance(app_id, options)
51
+ url = "#{@base_url}/api/apps/#{app_id}/remove-instance"
52
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
53
+ payload = options
54
+ opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
55
+ execute(opts)
56
+ end
57
+
58
+ def destroy(id)
59
+ url = "#{@base_url}/api/apps/#{id}"
60
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
61
+ opts = {method: :delete, url: url, headers: headers}
62
+ execute(opts)
63
+ end
64
+
65
+ def stop(id)
66
+ url = "#{@base_url}/api/apps/#{id}/stop"
67
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
68
+ opts = {method: :put, url: url, headers: headers}
69
+ execute(opts)
70
+ end
71
+
72
+ def start(id)
73
+ url = "#{@base_url}/api/apps/#{id}/start"
74
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
75
+ opts = {method: :put, url: url, headers: headers}
76
+ execute(opts)
77
+ end
78
+
79
+ def restart(id)
80
+ url = "#{@base_url}/api/apps/#{id}/restart"
81
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
82
+ opts = {method: :put, url: url, headers: headers}
83
+ execute(opts)
84
+ end
85
+
86
+ def firewall_disable(id)
87
+ url = "#{@base_url}/api/apps/#{id}/security-groups/disable"
88
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
89
+ opts = {method: :put, url: url, headers: headers}
90
+ execute(opts)
91
+ end
92
+
93
+ def firewall_enable(id)
94
+ url = "#{@base_url}/api/apps/#{id}/security-groups/enable"
95
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
96
+ opts = {method: :put, url: url, headers: headers}
97
+ execute(opts)
98
+ end
99
+
100
+ def security_groups(id)
101
+ url = "#{@base_url}/api/apps/#{id}/security-groups"
102
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
103
+ opts = {method: :get, url: url, headers: headers}
104
+ execute(opts)
105
+ end
106
+
107
+ def apply_security_groups(id, options)
108
+ url = "#{@base_url}/api/apps/#{id}/security-groups"
109
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
110
+ payload = options
111
+ opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
112
+ execute(opts)
113
+ end
135
114
  end
@@ -0,0 +1,30 @@
1
+ require 'morpheus/api/api_client'
2
+
3
+ class Morpheus::AuthInterface < Morpheus::APIClient
4
+
5
+ attr_reader :access_token
6
+
7
+ def initialize(base_url, access_token=nil)
8
+ @base_url = base_url
9
+ @access_token = access_token
10
+ end
11
+
12
+ def login(username, password)
13
+ @access_token = nil
14
+ url = "#{@base_url}/oauth/token"
15
+ params = {grant_type: 'password', scope:'write', client_id: 'morph-cli', username: username}
16
+ payload = {password: password}
17
+ opts = {method: :post, url: url, headers:{ params: params}, payload: payload, timeout: 10}
18
+ response = execute(opts)
19
+ return response if @dry_run
20
+ @access_token = response['access_token']
21
+ return response
22
+ end
23
+
24
+ def logout()
25
+ if @access_token
26
+ # todo: expire the token
27
+ end
28
+ raise "#{self}.logout() is not yet implemented"
29
+ end
30
+ end
@@ -1,89 +1,84 @@
1
- require 'json'
2
- require 'rest-client'
1
+ require 'morpheus/api/api_client'
3
2
 
4
3
  class Morpheus::CloudsInterface < Morpheus::APIClient
5
- def initialize(access_token, refresh_token,expires_at = nil, base_url=nil)
6
- @access_token = access_token
7
- @refresh_token = refresh_token
8
- @base_url = base_url
9
- @expires_at = expires_at
10
- end
4
+ def initialize(access_token, refresh_token,expires_at = nil, base_url=nil)
5
+ @access_token = access_token
6
+ @refresh_token = refresh_token
7
+ @base_url = base_url
8
+ @expires_at = expires_at
9
+ end
11
10
 
12
- def cloud_types()
13
- url = "#{@base_url}/api/zone-types"
14
- headers = { params: {}, authorization: "Bearer #{@access_token}" }
11
+ def cloud_types()
12
+ url = "#{@base_url}/api/zone-types"
13
+ headers = { params: {}, authorization: "Bearer #{@access_token}" }
14
+ opts = {method: :get, url: url, timeout: 30, headers: headers}
15
+ execute(opts)
16
+ end
15
17
 
16
- response = Morpheus::RestClient.execute(method: :get, url: url,
17
- timeout: 30, headers: headers,verify_ssl: false)
18
- JSON.parse(response.to_s)
19
- end
18
+ def get(options=nil)
19
+ url = "#{@base_url}/api/zones"
20
+ headers = { params: {}, authorization: "Bearer #{@access_token}" }
20
21
 
22
+ if options.is_a?(Hash)
23
+ headers[:params].merge!(options)
24
+ elsif options.is_a?(Numeric)
25
+ url = "#{@base_url}/api/zones/#{options}"
26
+ elsif options.is_a?(String)
27
+ headers[:params]['name'] = options
28
+ end
29
+ opts = {method: :get, url: url, timeout: 30, headers: headers}
30
+ execute(opts)
31
+ end
21
32
 
22
- def get(options=nil)
23
- url = "#{@base_url}/api/zones"
24
- headers = { params: {}, authorization: "Bearer #{@access_token}" }
33
+ def create(options)
34
+ url = "#{@base_url}/api/zones"
35
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
36
+ payload = options
37
+ opts = {method: :post, url: url, timeout: 30, headers: headers, payload: payload.to_json}
38
+ execute(opts)
39
+ end
25
40
 
26
- if options.is_a?(Hash)
27
- headers[:params].merge!(options)
28
- elsif options.is_a?(Numeric)
29
- url = "#{@base_url}/api/zones/#{options}"
30
- elsif options.is_a?(String)
31
- headers[:params]['name'] = options
32
- end
33
- response = Morpheus::RestClient.execute(method: :get, url: url,
34
- timeout: 30, headers: headers,verify_ssl: false)
35
- JSON.parse(response.to_s)
36
- end
41
+ def update(id, options)
42
+ url = "#{@base_url}/api/zones/#{id}"
43
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
44
+ payload = options
45
+ opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
46
+ execute(opts)
47
+ end
37
48
 
49
+ def destroy(id, params={})
50
+ url = "#{@base_url}/api/zones/#{id}"
51
+ headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
52
+ opts = {method: :delete, url: url, timeout: 30, headers: headers}
53
+ execute(opts)
54
+ end
38
55
 
39
- def create(options)
40
- url = "#{@base_url}/api/zones"
41
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
42
-
43
- payload = {zone: options}
44
- response = Morpheus::RestClient.execute(method: :post, url: url,
45
- timeout: 30, headers: headers, payload: payload.to_json,verify_ssl: false)
46
- JSON.parse(response.to_s)
47
- end
56
+ def firewall_disable(id)
57
+ url = "#{@base_url}/api/zones/#{id}/security-groups/disable"
58
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
59
+ opts = {method: :put, url: url, timeout: 30, headers: headers}
60
+ execute(opts)
61
+ end
48
62
 
49
- def destroy(id)
50
- url = "#{@base_url}/api/zones/#{id}"
51
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
52
- response = Morpheus::RestClient.execute(method: :delete, url: url,
53
- timeout: 30, headers: headers,verify_ssl: false)
54
- JSON.parse(response.to_s)
55
- end
63
+ def firewall_enable(id)
64
+ url = "#{@base_url}/api/zones/#{id}/security-groups/enable"
65
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
66
+ opts = {method: :put, url: url, timeout: 30, headers: headers}
67
+ execute(opts)
68
+ end
56
69
 
57
- def firewall_disable(id)
58
- url = "#{@base_url}/api/zones/#{id}/security-groups/disable"
59
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
60
- response = Morpheus::RestClient.execute(method: :put, url: url,
61
- timeout: 30, headers: headers,verify_ssl: false)
62
- JSON.parse(response.to_s)
63
- end
70
+ def security_groups(id)
71
+ url = "#{@base_url}/api/zones/#{id}/security-groups"
72
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
73
+ opts = {method: :get, url: url, timeout: 30, headers: headers}
74
+ execute(opts)
75
+ end
64
76
 
65
- def firewall_enable(id)
66
- url = "#{@base_url}/api/zones/#{id}/security-groups/enable"
67
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
68
- response = Morpheus::RestClient.execute(method: :put, url: url,
69
- timeout: 30, headers: headers,verify_ssl: false)
70
- JSON.parse(response.to_s)
71
- end
72
-
73
- def security_groups(id)
74
- url = "#{@base_url}/api/zones/#{id}/security-groups"
75
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
76
- response = Morpheus::RestClient.execute(method: :get, url: url,
77
- timeout: 30, headers: headers,verify_ssl: false)
78
- JSON.parse(response.to_s)
79
- end
80
-
81
- def apply_security_groups(id, options)
82
- url = "#{@base_url}/api/zones/#{id}/security-groups"
83
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
84
- payload = options
85
- response = Morpheus::RestClient.execute(method: :post, url: url,
86
- timeout: 30, headers: headers, payload: payload.to_json,verify_ssl: false)
87
- JSON.parse(response.to_s)
88
- end
77
+ def apply_security_groups(id, options)
78
+ url = "#{@base_url}/api/zones/#{id}/security-groups"
79
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
80
+ payload = options
81
+ opts = {method: :post, url: url, timeout: 30, headers: headers, payload: payload.to_json}
82
+ execute(opts)
83
+ end
89
84
  end