morpheus-cli 5.3.2 → 5.3.2.1

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
  SHA256:
3
- metadata.gz: e776b0e0602c4de27079e0796d270009b0d3a592d571a41721ac936c7537b94e
4
- data.tar.gz: 10f231de3b75dc6a16d5433af35a1cbde2931d1871bf2106040ee49a0812091c
3
+ metadata.gz: e27f28e852866d25457815c852eec19a3f65bd3b0ae8a33d8e055d990f631e79
4
+ data.tar.gz: 5270f5c81e872491cbf9e1e59f33cf78bf233c152c1347fa61cb01c544073e34
5
5
  SHA512:
6
- metadata.gz: 893fd73648238a2a360273fef6a44654b0011075401743f6be61ba5f32c487f8bc5c5936f440cbcbb6be99ce05888ef99e453545e7f435e834a54ade3062851a
7
- data.tar.gz: c558b3e31997546f382b44339183431e6d855be77b82e6c85be623c32dcf3333ae0a34c725b19fb317e308d8ec3ca2963de9f51ceba5b3bd658c7ad013ae9d67
6
+ metadata.gz: 172818b1030b243ebb2c9c7e316b0cefe173b5a198ff8184f7c0b7bce275954e80109b45c426530ef1587635199e6cc17dedc248011cc11626e2d0f5e8f3f1c1
7
+ data.tar.gz: 45bdeca37c208f7e7889bd9ab87b0012fea6623faf1b80628fef2ad0df55182388c8e1cd647f9fdd51628d48a4d6cca715e718bb655c8612683fe4ffc9ede3f8
data/Dockerfile CHANGED
@@ -1,5 +1,5 @@
1
1
  FROM ruby:2.5.1
2
2
 
3
- RUN gem install morpheus-cli -v 5.3.2
3
+ RUN gem install morpheus-cli -v 5.3.2.1
4
4
 
5
5
  ENTRYPOINT ["morpheus"]
@@ -1,35 +1,9 @@
1
- require 'morpheus/api/api_client'
1
+ require 'morpheus/api/rest_interface'
2
2
 
3
- class Morpheus::AccountsInterface < Morpheus::APIClient
4
-
5
- def get(id)
6
- raise "#{self.class}.get() passed a blank id!" if id.to_s == ''
7
- url = "#{@base_url}/api/accounts/#{id}"
8
- headers = { params: {}, authorization: "Bearer #{@access_token}" }
9
- execute(method: :get, url: url, headers: headers)
10
- end
11
-
12
- def list(params={})
13
- url = "#{@base_url}/api/accounts"
14
- headers = { params: params, authorization: "Bearer #{@access_token}" }
15
- execute(method: :get, url: url, headers: headers)
16
- end
3
+ class Morpheus::AccountsInterface < Morpheus::RestInterface
17
4
 
18
- def create(payload)
19
- url = "#{@base_url}/api/accounts"
20
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
21
- execute(method: :post, url: url, headers: headers, payload: payload.to_json)
5
+ def base_path
6
+ "/api/accounts"
22
7
  end
23
8
 
24
- def update(id, payload)
25
- url = "#{@base_url}/api/accounts/#{id}"
26
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
27
- execute(method: :put, url: url, headers: headers, payload: payload.to_json)
28
- end
29
-
30
- def destroy(id)
31
- url = "#{@base_url}/api/accounts/#{id}"
32
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
33
- execute(method: :delete, url: url, headers: headers)
34
- end
35
9
  end
@@ -474,6 +474,18 @@ class Morpheus::APIClient
474
474
  Morpheus::LoadBalancersInterface.new(common_interface_options).setopts(@options)
475
475
  end
476
476
 
477
+ def load_balancer_types
478
+ Morpheus::LoadBalancerTypesInterface.new(common_interface_options).setopts(@options)
479
+ end
480
+
481
+ def load_balancer_virtual_servers
482
+ Morpheus::LoadBalancerVirtualServersInterface.new(common_interface_options).setopts(@options)
483
+ end
484
+
485
+ def load_balancer_pools
486
+ Morpheus::LoadBalancerPoolsInterface.new(common_interface_options).setopts(@options)
487
+ end
488
+
477
489
  def tasks
478
490
  Morpheus::TasksInterface.new(common_interface_options).setopts(@options)
479
491
  end
@@ -0,0 +1,9 @@
1
+ require 'morpheus/api/secondary_rest_interface'
2
+
3
+ class Morpheus::LoadBalancerPoolsInterface < Morpheus::SecondaryRestInterface
4
+
5
+ def base_path(load_balancer_id)
6
+ "/api/load-balancers/#{load_balancer_id}/pools"
7
+ end
8
+
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'morpheus/api/read_interface'
2
+
3
+ class Morpheus::LoadBalancerTypesInterface < Morpheus::ReadInterface
4
+
5
+ def base_path
6
+ "/api/load-balancer-types"
7
+ end
8
+
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'morpheus/api/secondary_rest_interface'
2
+
3
+ class Morpheus::LoadBalancerVirtualServersInterface < Morpheus::SecondaryRestInterface
4
+
5
+ def base_path(load_balancer_id)
6
+ "/api/load-balancers/#{load_balancer_id}/virtual-servers"
7
+ end
8
+
9
+ end
@@ -1,58 +1,9 @@
1
- require 'morpheus/api/api_client'
1
+ require 'morpheus/api/rest_interface'
2
2
 
3
- class Morpheus::LoadBalancersInterface < Morpheus::APIClient
3
+ class Morpheus::LoadBalancersInterface < Morpheus::RestInterface
4
4
 
5
- def load_balancer_types(options={})
6
- url = "#{@base_url}/api/load-balancer-types"
7
- headers = { params: {}, authorization: "Bearer #{@access_token}" }
8
- if options.is_a?(Hash)
9
- headers[:params].merge!(options)
10
- elsif options.is_a?(Numeric)
11
- url = "#{@base_url}/api/load-balancer-types/#{options}"
12
- elsif options.is_a?(String)
13
- headers[:params]['name'] = options
14
- end
15
- execute(method: :get, url: url, headers: headers)
5
+ def base_path
6
+ "/api/load-balancers"
16
7
  end
17
8
 
18
- def list(params={})
19
- url = "#{@base_url}/api/load-balancers"
20
- headers = { params: params, authorization: "Bearer #{@access_token}" }
21
- opts = {method: :get, url: url, headers: headers}
22
- execute(opts)
23
- end
24
-
25
- def get(options=nil)
26
- url = "#{@base_url}/api/load-balancers"
27
- headers = { params: {}, authorization: "Bearer #{@access_token}" }
28
- if options.is_a?(Hash)
29
- headers[:params].merge!(options)
30
- elsif options.is_a?(Numeric)
31
- url = "#{@base_url}/api/load-balancers/#{options}"
32
- elsif options.is_a?(String)
33
- headers[:params]['name'] = options
34
- end
35
- execute(method: :get, url: url, headers: headers)
36
- end
37
-
38
- def update(id, options)
39
- url = "#{@base_url}/api/load-balancers/#{id}"
40
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
41
- payload = options
42
- execute(method: :put, url: url, headers: headers, payload: payload.to_json)
43
- end
44
-
45
-
46
- def create(options)
47
- url = "#{@base_url}/api/load-balancers"
48
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
49
- payload = options
50
- execute(method: :post, url: url, headers: headers, payload: payload.to_json)
51
- end
52
-
53
- def destroy(id)
54
- url = "#{@base_url}/api/load-balancers/#{id}"
55
- headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
56
- execute(method: :delete, url: url, headers: headers)
57
- end
58
9
  end
@@ -59,6 +59,34 @@ class Morpheus::NetworkRoutersInterface < Morpheus::APIClient
59
59
  execute(opts)
60
60
  end
61
61
 
62
+ def list_firewall_rule_groups(router_id, params={})
63
+ url = "#{@base_url}/api/networks/routers/#{router_id}/firewall-rule-groups"
64
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json', params: params }
65
+ opts = {method: :get, url: url, headers: headers}
66
+ execute(opts)
67
+ end
68
+
69
+ def create_firewall_rule_group(router_id, payload={})
70
+ url = "#{@base_url}/api/networks/routers/#{router_id}/firewall-rule-groups"
71
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
72
+ opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
73
+ execute(opts)
74
+ end
75
+
76
+ def update_firewall_rule_group(router_id, group_id, payload={})
77
+ url = "#{@base_url}/api/networks/routers/#{router_id}/firewall-rule-groups/#{group_id}"
78
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
79
+ opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
80
+ execute(opts)
81
+ end
82
+
83
+ def destroy_firewall_rule_group(router_id, group_id, payload={})
84
+ url = "#{@base_url}/api/networks/routers/#{router_id}/firewall-rule-groups/#{group_id}"
85
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
86
+ opts = {method: :delete, url: url, headers: headers, payload: payload.to_json}
87
+ execute(opts)
88
+ end
89
+
62
90
  def create_firewall_rule(router_id, payload={})
63
91
  url = "#{@base_url}/api/networks/routers/#{router_id}/firewall-rules"
64
92
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
@@ -66,6 +94,13 @@ class Morpheus::NetworkRoutersInterface < Morpheus::APIClient
66
94
  execute(opts)
67
95
  end
68
96
 
97
+ def update_firewall_rule(router_id, rule_id, payload={})
98
+ url = "#{@base_url}/api/networks/routers/#{router_id}/firewall-rules/#{rule_id}"
99
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
100
+ opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
101
+ execute(opts)
102
+ end
103
+
69
104
  def destroy_firewall_rule(router_id, rule_id, payload={})
70
105
  url = "#{@base_url}/api/networks/routers/#{router_id}/firewall-rules/#{rule_id}"
71
106
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
@@ -87,6 +122,27 @@ class Morpheus::NetworkRoutersInterface < Morpheus::APIClient
87
122
  execute(opts)
88
123
  end
89
124
 
125
+ def create_nat(router_id, payload={})
126
+ url = "#{@base_url}/api/networks/routers/#{router_id}/nats"
127
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
128
+ opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
129
+ execute(opts)
130
+ end
131
+
132
+ def update_nat(router_id, nat_id, payload={})
133
+ url = "#{@base_url}/api/networks/routers/#{router_id}/nats/#{nat_id}"
134
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
135
+ opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
136
+ execute(opts)
137
+ end
138
+
139
+ def destroy_nat(router_id, nat_id, payload={})
140
+ url = "#{@base_url}/api/networks/routers/#{router_id}/nats/#{nat_id}"
141
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
142
+ opts = {method: :delete, url: url, headers: headers, payload: payload.to_json}
143
+ execute(opts)
144
+ end
145
+
90
146
  def update_permissions(router_id, payload)
91
147
  url = "#{@base_url}/api/networks/routers/#{router_id}/permissions"
92
148
  headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
@@ -0,0 +1,25 @@
1
+ require 'morpheus/api/api_client'
2
+
3
+ # Interface class to be subclassed by interfaces that provide CRUD endpoints
4
+ # for objects underneath another resource
5
+ # Subclasses must override the base_path(resource_id) method
6
+ class Morpheus::SecondaryReadInterface < Morpheus::APIClient
7
+
8
+ # subclasses should override in your interface
9
+ # Example: "/api/things/#{resource_id}/widgets"
10
+ def base_path(resource_id)
11
+ raise "#{self.class} has not defined base_path(resource_id)!"
12
+ end
13
+
14
+ def list(resource_id, params={}, headers={})
15
+ validate_id!(resource_id)
16
+ execute(method: :get, url: "#{base_path(resource_id)}", params: params, headers: headers)
17
+ end
18
+
19
+ def get(resource_id, id, params={}, headers={})
20
+ validate_id!(resource_id)
21
+ validate_id!(id)
22
+ execute(method: :get, url: "#{base_path(resource_id)}/#{id}", params: params, headers: headers)
23
+ end
24
+
25
+ end
@@ -0,0 +1,42 @@
1
+ require 'morpheus/api/api_client'
2
+
3
+ # Interface class to be subclassed by interfaces that provide CRUD endpoints
4
+ # for objects underneath another resource
5
+ # Subclasses must override the base_path(resource_id) method
6
+ class Morpheus::SecondaryRestInterface < Morpheus::APIClient
7
+
8
+ # subclasses should override in your interface
9
+ # Example: "/api/things/#{resource_id}/widgets"
10
+ def base_path(resource_id)
11
+ raise "#{self.class} has not defined base_path(resource_id)!"
12
+ end
13
+
14
+ def list(resource_id, params={}, headers={})
15
+ validate_id!(resource_id)
16
+ execute(method: :get, url: "#{base_path(resource_id)}", params: params, headers: headers)
17
+ end
18
+
19
+ def get(resource_id, id, params={}, headers={})
20
+ validate_id!(resource_id)
21
+ validate_id!(id)
22
+ execute(method: :get, url: "#{base_path(resource_id)}/#{id}", params: params, headers: headers)
23
+ end
24
+
25
+ def create(resource_id, payload, params={}, headers={})
26
+ validate_id!(resource_id)
27
+ execute(method: :post, url: "#{base_path(resource_id)}", params: params, payload: payload, headers: headers)
28
+ end
29
+
30
+ def update(resource_id, id, payload, params={}, headers={})
31
+ validate_id!(resource_id)
32
+ validate_id!(id)
33
+ execute(method: :put, url: "#{base_path(resource_id)}/#{id}", params: params, payload: payload, headers: headers)
34
+ end
35
+
36
+ def destroy(resource_id, id, params = {}, headers={})
37
+ validate_id!(resource_id)
38
+ validate_id!(id)
39
+ execute(method: :delete, url: "#{base_path(resource_id)}/#{id}", params: params, headers: headers)
40
+ end
41
+
42
+ end
data/lib/morpheus/cli.rb CHANGED
@@ -93,6 +93,7 @@ module Morpheus
93
93
  load 'morpheus/cli/cloud_folders_command.rb'
94
94
  load 'morpheus/cli/hosts.rb'
95
95
  load 'morpheus/cli/load_balancers.rb'
96
+ load 'morpheus/cli/load_balancer_types.rb'
96
97
  load 'morpheus/cli/shell.rb'
97
98
  load 'morpheus/cli/tasks.rb'
98
99
  load 'morpheus/cli/workflows.rb'
@@ -18,11 +18,11 @@ module Morpheus
18
18
  # todo: use delegate
19
19
  module CliCommand
20
20
 
21
- def self.included(klass)
22
- klass.send :include, Morpheus::Cli::PrintHelper
23
- klass.send :include, Morpheus::Benchmarking::HasBenchmarking
24
- klass.extend ClassMethods
25
- Morpheus::Cli::CliRegistry.add(klass, klass.command_name)
21
+ def self.included(base)
22
+ base.send :include, Morpheus::Cli::PrintHelper
23
+ base.send :include, Morpheus::Benchmarking::HasBenchmarking
24
+ base.extend ClassMethods
25
+ Morpheus::Cli::CliRegistry.add(base, base.command_name)
26
26
  end
27
27
 
28
28
  # the beginning of instance variables from optparse !
@@ -983,10 +983,11 @@ module Morpheus
983
983
  out = ""
984
984
  out << usage.to_s.strip if usage
985
985
  out << "\n"
986
- if !subcommands.empty?
986
+ my_subcommands = visible_subcommands
987
+ if !my_subcommands.empty?
987
988
  out << "Commands:"
988
989
  out << "\n"
989
- subcommands.sort.each {|subcmd, method|
990
+ my_subcommands.sort.each {|subcmd, method|
990
991
  desc = get_subcommand_description(subcmd)
991
992
  out << "\t#{subcmd.to_s}"
992
993
  out << "\t#{desc}" if desc
@@ -1527,8 +1528,7 @@ module Morpheus
1527
1528
  cmds = subcommands.clone
1528
1529
  if @hidden_subcommands && !@hidden_subcommands.empty?
1529
1530
  @hidden_subcommands.each do |hidden_cmd|
1530
- cmds.delete(hidden_cmd.to_s)
1531
- cmds.delete(hidden_cmd.to_sym)
1531
+ cmds.delete(hidden_cmd.to_s.gsub('_', '-'))
1532
1532
  end
1533
1533
  end
1534
1534
  cmds
@@ -2565,31 +2565,34 @@ class Morpheus::Cli::Instances
2565
2565
  options = {}
2566
2566
  optparse = Morpheus::Cli::OptionParser.new do |opts|
2567
2567
  opts.banner = subcommand_usage("[instance]")
2568
- build_common_options(opts, options, [:options, :json, :dry_run, :remote])
2568
+ build_standard_update_options(opts, options)
2569
2569
  end
2570
2570
  optparse.parse!(args)
2571
- if args.count < 1
2572
- puts optparse
2573
- exit 1
2574
- end
2571
+ verify_args!(args:args, optparse:optparse, count:1)
2575
2572
  connect(options)
2576
- begin
2577
- instance = find_instance_by_name_or_id(args[0])
2578
-
2579
- group_id = instance['group']['id']
2580
- cloud_id = instance['cloud']['id']
2581
- layout_id = instance['layout']['id']
2582
-
2583
- plan_id = instance['plan']['id']
2573
+ instance = find_instance_by_name_or_id(args[0])
2574
+ return 1, "instance not found" if instance.nil?
2575
+
2576
+ payload = {}
2577
+ if options[:payload]
2578
+ payload = options[:payload]
2579
+ payload.deep_merge!(parse_passed_options(options))
2580
+ else
2584
2581
  payload = {
2585
- :instance => {:id => instance["id"]}
2582
+ "instance" => {:id => instance["id"]}
2586
2583
  }
2584
+ payload.deep_merge!(parse_passed_options(options))
2587
2585
 
2588
2586
  # avoid 500 error
2589
2587
  # payload[:servicePlanOptions] = {}
2590
2588
 
2591
2589
  puts "\nDue to limitations by most Guest Operating Systems, Disk sizes can only be expanded and not reduced.\nIf a smaller plan is selected, memory and CPU (if relevant) will be reduced but storage will not.\n\n"
2592
2590
 
2591
+ group_id = instance['group']['id']
2592
+ cloud_id = instance['cloud']['id']
2593
+ layout_id = instance['layout']['id']
2594
+ plan_id = instance['plan']['id']
2595
+
2593
2596
  # prompt for service plan
2594
2597
  service_plans_json = @instances_interface.service_plans({zoneId: cloud_id, siteId: group_id, layoutId: layout_id})
2595
2598
  service_plans = service_plans_json["plans"]
@@ -2604,7 +2607,7 @@ class Morpheus::Cli::Instances
2604
2607
  new_plan_id = service_plan["id"]
2605
2608
  #payload[:servicePlan] = new_plan_id # ew, this api uses servicePlanId instead
2606
2609
  #payload[:servicePlanId] = new_plan_id
2607
- payload[:instance][:plan] = {id: service_plan["id"]}
2610
+ payload["instance"]["plan"] = {"id" => service_plan["id"]}
2608
2611
 
2609
2612
  volumes_response = @instances_interface.volumes(instance['id'])
2610
2613
  current_volumes = volumes_response['volumes'].sort {|x,y| x['displayOrder'] <=> y['displayOrder'] }
@@ -2612,29 +2615,26 @@ class Morpheus::Cli::Instances
2612
2615
  # prompt for volumes
2613
2616
  volumes = prompt_resize_volumes(current_volumes, service_plan, options)
2614
2617
  if !volumes.empty?
2615
- payload[:volumes] = volumes
2618
+ payload["volumes"] = volumes
2616
2619
  end
2617
2620
 
2618
2621
  # only amazon supports this option
2619
2622
  # for now, always do this
2620
- payload[:deleteOriginalVolumes] = true
2621
- @instances_interface.setopts(options)
2622
- if options[:dry_run]
2623
- print_dry_run @instances_interface.dry.resize(instance['id'], payload)
2624
- return
2625
- end
2626
- json_response = @instances_interface.resize(instance['id'], payload)
2627
- if options[:json]
2628
- puts as_json(json_response, options)
2629
- return 0
2630
- else
2631
- print_green_success "Resizing instance #{instance['name']}"
2632
- #list([])
2633
- end
2634
- rescue RestClient::Exception => e
2635
- print_rest_exception(e, options)
2636
- exit 1
2623
+ payload["deleteOriginalVolumes"] = true
2624
+ end
2625
+
2626
+ @instances_interface.setopts(options)
2627
+ if options[:dry_run]
2628
+ print_dry_run @instances_interface.dry.resize(instance['id'], payload)
2629
+ return
2630
+ end
2631
+ json_response = @instances_interface.resize(instance['id'], payload)
2632
+ render_response(json_response, options, 'snapshots') do
2633
+ print_green_success "Resizing instance #{instance['name']}"
2637
2634
  end
2635
+ return 0, nil
2636
+
2637
+
2638
2638
  end
2639
2639
 
2640
2640
  def backup(args)