morpheus-cli 3.6.31 → 3.6.32

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e626a3f013288e30a8d4ba70af229530c011ae2da16eeecc2aae241eb75bb3dc
4
- data.tar.gz: c26157f8f9b06764169ccb18a1875efac63d2a54d2c3a5f345ee0c321704b33b
3
+ metadata.gz: f24803cc6c01bc67cf8ba06e90df80f379738febf629612dab84a29da085f81f
4
+ data.tar.gz: 596305e77aa0b2686b89861e161ff1db294cb7f7e7943167882db00becd7d15a
5
5
  SHA512:
6
- metadata.gz: e009d74e7511730df6aa4ad83db8ab85510e9290404b502e4a185354c007151c87b4a9fab3a9b4f2d38a7efaa308b5100c2ed5a1633c3c9b2b618a4eeb6a4ab5
7
- data.tar.gz: 273a547e43e98bf485424ec8fdb27937de55bd2e82be27d51f046157a432b7136fe785fcd7a9adfb87126452c5646976c2ebb2b4640fb1a467afb7d696ef577d
6
+ metadata.gz: ecfb02f85f8b2893051114407bacf6a78d11ecf3b16eeb01671d5b966e9f87fd60126ad00c763eac27c4d62a8f2e9ecf22c13b33d02c1e77da18abc86d7256bf
7
+ data.tar.gz: 92579b647b4b14b2841250dafdb8712157e5117ece943f54fa9ad24644513b593053555d4cc457a045bc60813ff3568561c686b947661610f73229dee93579d5
@@ -474,6 +474,14 @@ class Morpheus::APIClient
474
474
  Morpheus::ReportsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
475
475
  end
476
476
 
477
+ def environments
478
+ Morpheus::EnvironmentsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
479
+ end
480
+
481
+ def wiki
482
+ Morpheus::WikiInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
483
+ end
484
+
477
485
  # new interfaces get added here
478
486
 
479
487
  end
@@ -127,4 +127,19 @@ class Morpheus::AppsInterface < Morpheus::APIClient
127
127
  opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
128
128
  execute(opts)
129
129
  end
130
+
131
+ def wiki(id, params)
132
+ url = "#{@base_url}/api/apps/#{id}/wiki"
133
+ headers = { params: params, authorization: "Bearer #{@access_token}" }
134
+ opts = {method: :get, url: url, headers: headers}
135
+ execute(opts)
136
+ end
137
+
138
+ def update_wiki(id, payload)
139
+ url = "#{@base_url}/api/apps/#{id}/wiki"
140
+ headers = {authorization: "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
141
+ opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
142
+ execute(opts)
143
+ end
144
+
130
145
  end
@@ -78,4 +78,19 @@ class Morpheus::CloudsInterface < Morpheus::APIClient
78
78
  opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
79
79
  execute(opts)
80
80
  end
81
+
82
+ def wiki(id, params)
83
+ url = "#{@base_url}/api/zones/#{id}/wiki"
84
+ headers = { params: params, authorization: "Bearer #{@access_token}" }
85
+ opts = {method: :get, url: url, headers: headers}
86
+ execute(opts)
87
+ end
88
+
89
+ def update_wiki(id, payload)
90
+ url = "#{@base_url}/api/zones/#{id}/wiki"
91
+ headers = {authorization: "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
92
+ opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
93
+ execute(opts)
94
+ end
95
+
81
96
  end
@@ -0,0 +1,54 @@
1
+ require 'morpheus/api/api_client'
2
+
3
+ class Morpheus::EnvironmentsInterface < Morpheus::APIClient
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, params={})
12
+ raise "#{self.class}.get() passed a blank id!" if id.to_s == ''
13
+ url = "#{@base_url}/api/environments/#{id}"
14
+ headers = { params: params, authorization: "Bearer #{@access_token}" }
15
+ opts = {method: :get, url: url, headers: headers}
16
+ execute(opts)
17
+ end
18
+
19
+ def list(params={})
20
+ url = "#{@base_url}/api/environments"
21
+ headers = { params: params, authorization: "Bearer #{@access_token}" }
22
+ opts = {method: :get, url: url, headers: headers}
23
+ execute(opts)
24
+ end
25
+
26
+ def create(payload)
27
+ url = "#{@base_url}/api/environments"
28
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
29
+ opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
30
+ execute(opts)
31
+ end
32
+
33
+ def update(id, payload)
34
+ url = "#{@base_url}/api/environments/#{id}"
35
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
36
+ opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
37
+ execute(opts)
38
+ end
39
+
40
+ def destroy(id, params={})
41
+ url = "#{@base_url}/api/environments/#{id}"
42
+ headers = { params: params, authorization: "Bearer #{@access_token}" }
43
+ opts = {method: :delete, url: url, headers: headers}
44
+ execute(opts)
45
+ end
46
+
47
+ def toggle_active(id, params={})
48
+ url = "#{@base_url}/api/environments/#{id}/toggle-active"
49
+ headers = { params: params, authorization: "Bearer #{@access_token}" }
50
+ opts = {method: :put, url: url, headers: headers}
51
+ execute(opts)
52
+ end
53
+
54
+ end
@@ -54,4 +54,19 @@ class Morpheus::GroupsInterface < Morpheus::APIClient
54
54
  opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
55
55
  execute(opts)
56
56
  end
57
+
58
+ def wiki(id, params)
59
+ url = "#{@base_url}/api/groups/#{id}/wiki"
60
+ headers = { params: params, authorization: "Bearer #{@access_token}" }
61
+ opts = {method: :get, url: url, headers: headers}
62
+ execute(opts)
63
+ end
64
+
65
+ def update_wiki(id, payload)
66
+ url = "#{@base_url}/api/groups/#{id}/wiki"
67
+ headers = {authorization: "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
68
+ opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
69
+ execute(opts)
57
70
  end
71
+
72
+ end
@@ -259,6 +259,7 @@ class Morpheus::InstancesInterface < Morpheus::APIClient
259
259
  execute(opts)
260
260
  end
261
261
 
262
+ # deprecated in 4.0
262
263
  def update_notes(id, payload)
263
264
  url = "#{@base_url}/api/instances/#{id}/notes"
264
265
  headers = {authorization: "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
@@ -287,4 +288,18 @@ class Morpheus::InstancesInterface < Morpheus::APIClient
287
288
  execute(opts)
288
289
  end
289
290
 
291
+ def wiki(id, params)
292
+ url = "#{@base_url}/api/instances/#{id}/wiki"
293
+ headers = { params: params, authorization: "Bearer #{@access_token}" }
294
+ opts = {method: :get, url: url, headers: headers}
295
+ execute(opts)
296
+ end
297
+
298
+ def update_wiki(id, payload)
299
+ url = "#{@base_url}/api/instances/#{id}/wiki"
300
+ headers = {authorization: "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
301
+ opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
302
+ execute(opts)
303
+ end
304
+
290
305
  end
@@ -136,4 +136,18 @@ class Morpheus::ServersInterface < Morpheus::APIClient
136
136
  execute(opts)
137
137
  end
138
138
 
139
+ def wiki(id, params)
140
+ url = "#{@base_url}/api/servers/#{id}/wiki"
141
+ headers = { params: params, authorization: "Bearer #{@access_token}" }
142
+ opts = {method: :get, url: url, headers: headers}
143
+ execute(opts)
144
+ end
145
+
146
+ def update_wiki(id, payload)
147
+ url = "#{@base_url}/api/servers/#{id}/wiki"
148
+ headers = {authorization: "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
149
+ opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
150
+ execute(opts)
151
+ end
152
+
139
153
  end
@@ -0,0 +1,54 @@
1
+ require 'morpheus/api/api_client'
2
+
3
+ class Morpheus::WikiInterface < Morpheus::APIClient
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, params={})
12
+ raise "#{self.class}.get() passed a blank name!" if id.to_s == ''
13
+ url = "#{@base_url}/api/wiki/pages/#{id}"
14
+ headers = { params: params, authorization: "Bearer #{@access_token}" }
15
+ opts = {method: :get, url: url, headers: headers}
16
+ execute(opts)
17
+ end
18
+
19
+ def list(params={})
20
+ url = "#{@base_url}/api/wiki/pages"
21
+ headers = { params: params, authorization: "Bearer #{@access_token}" }
22
+ opts = {method: :get, url: url, headers: headers}
23
+ execute(opts)
24
+ end
25
+
26
+ def create(payload)
27
+ url = "#{@base_url}/api/wiki/pages"
28
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
29
+ opts = {method: :post, url: url, headers: headers, payload: payload.to_json}
30
+ execute(opts)
31
+ end
32
+
33
+ def update(id, payload)
34
+ url = "#{@base_url}/api/wiki/pages/#{id}"
35
+ headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
36
+ opts = {method: :put, url: url, headers: headers, payload: payload.to_json}
37
+ execute(opts)
38
+ end
39
+
40
+ def destroy(id, params={})
41
+ url = "#{@base_url}/api/wiki/pages/#{id}"
42
+ headers = { params: params, authorization: "Bearer #{@access_token}" }
43
+ opts = {method: :delete, url: url, headers: headers}
44
+ execute(opts)
45
+ end
46
+
47
+ def categories(params={})
48
+ url = "#{@base_url}/api/wiki/categories"
49
+ headers = { params: params, authorization: "Bearer #{@access_token}" }
50
+ opts = {method: :get, url: url, headers: headers}
51
+ execute(opts)
52
+ end
53
+
54
+ end
data/lib/morpheus/cli.rb CHANGED
@@ -143,6 +143,8 @@ module Morpheus
143
143
  load 'morpheus/cli/processes_command.rb'
144
144
  load 'morpheus/cli/packages_command.rb'
145
145
  load 'morpheus/cli/reports_command.rb'
146
+ load 'morpheus/cli/environments_command.rb'
147
+ load 'morpheus/cli/wiki_command.rb'
146
148
 
147
149
  # Your new commands go here...
148
150
 
@@ -15,8 +15,10 @@ class Morpheus::Cli::Apps
15
15
  include Morpheus::Cli::ProcessesHelper
16
16
  set_command_name :apps
17
17
  set_command_description "View and manage apps."
18
- register_subcommands :list, :count, :get, :add, :update, :remove, :add_instance, :remove_instance, :logs, :firewall_disable, :firewall_enable, :security_groups, :apply_security_groups, :history
18
+ register_subcommands :list, :count, :get, :add, :update, :remove, :add_instance, :remove_instance, :logs, :security_groups, :apply_security_groups, :history
19
19
  register_subcommands :stop, :start, :restart
20
+ register_subcommands :wiki, :update_wiki
21
+ #register_subcommands :firewall_disable, :firewall_enable
20
22
  #register_subcommands :validate # add --validate instead
21
23
  alias_subcommand :details, :get
22
24
  set_default_subcommand :list
@@ -1487,6 +1489,205 @@ class Morpheus::Cli::Apps
1487
1489
  end
1488
1490
  end
1489
1491
 
1492
+ def wiki(args)
1493
+ options = {}
1494
+ params = {}
1495
+ open_wiki_link = false
1496
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
1497
+ opts.banner = subcommand_usage("[app]")
1498
+ opts.on('--view', '--view', "View wiki page in web browser.") do
1499
+ open_wiki_link = true
1500
+ end
1501
+ build_common_options(opts, options, [:json, :dry_run, :remote])
1502
+ opts.footer = "View wiki page details for an app." + "\n" +
1503
+ "[app] is required. This is the name or id of an app."
1504
+ end
1505
+ optparse.parse!(args)
1506
+ if args.count != 1
1507
+ puts_error "#{Morpheus::Terminal.angry_prompt}wrong number of arguments. Expected 1 and received #{args.count} #{args.inspect}\n#{optparse}"
1508
+ return 1
1509
+ end
1510
+ connect(options)
1511
+
1512
+ begin
1513
+ app = find_app_by_name_or_id(args[0])
1514
+ return 1 if app.nil?
1515
+
1516
+
1517
+ @apps_interface.setopts(options)
1518
+ if options[:dry_run]
1519
+ print_dry_run @apps_interface.dry.wiki(app["id"], params)
1520
+ return
1521
+ end
1522
+ json_response = @apps_interface.wiki(app["id"], params)
1523
+ page = json_response['page']
1524
+
1525
+ render_result = render_with_format(json_response, options, 'page')
1526
+ return 0 if render_result
1527
+
1528
+ if page
1529
+
1530
+ # my_terminal.exec("wiki get #{page['id']}")
1531
+
1532
+ print_h1 "App Wiki Page: #{app['name']}"
1533
+ # print_h1 "Wiki Page Details"
1534
+ print cyan
1535
+
1536
+ print_description_list({
1537
+ "Page ID" => 'id',
1538
+ "Name" => 'name',
1539
+ #"Category" => 'category',
1540
+ #"Ref Type" => 'refType',
1541
+ #"Ref ID" => 'refId',
1542
+ #"Owner" => lambda {|it| it['account'] ? it['account']['name'] : '' },
1543
+ "Created" => lambda {|it| format_local_dt(it['dateCreated']) },
1544
+ "Created By" => lambda {|it| it['createdBy'] ? it['createdBy']['username'] : '' },
1545
+ "Updated" => lambda {|it| format_local_dt(it['lastUpdated']) },
1546
+ "Updated By" => lambda {|it| it['updatedBy'] ? it['updatedBy']['username'] : '' }
1547
+ }, page)
1548
+ print reset,"\n"
1549
+
1550
+ print_h2 "Page Content"
1551
+ print cyan, page['content'], reset, "\n"
1552
+
1553
+ else
1554
+ print "\n"
1555
+ print cyan, "No wiki page found.", reset, "\n"
1556
+ end
1557
+ print reset,"\n"
1558
+
1559
+ if open_wiki_link
1560
+ return view_wiki([args[0]])
1561
+ end
1562
+
1563
+ return 0
1564
+ rescue RestClient::Exception => e
1565
+ print_rest_exception(e, options)
1566
+ exit 1
1567
+ end
1568
+ end
1569
+
1570
+ def view_wiki(args)
1571
+ params = {}
1572
+ options = {}
1573
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
1574
+ opts.banner = subcommand_usage("[id]")
1575
+ build_common_options(opts, options, [:dry_run, :remote])
1576
+ opts.footer = "View app wiki page in a web browser" + "\n" +
1577
+ "[app] is required. This is the name or id of an app."
1578
+ end
1579
+ optparse.parse!(args)
1580
+ if args.count != 1
1581
+ raise_command_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args.join(' ')}\n#{optparse}"
1582
+ end
1583
+ connect(options)
1584
+ begin
1585
+ app = find_app_by_name_or_id(args[0])
1586
+ return 1 if app.nil?
1587
+
1588
+ link = "#{@appliance_url}/login/oauth-redirect?access_token=#{@access_token}\\&redirectUri=/provisioning/apps/#{app['id']}#!wiki"
1589
+
1590
+ open_command = nil
1591
+ if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
1592
+ open_command = "start #{link}"
1593
+ elsif RbConfig::CONFIG['host_os'] =~ /darwin/
1594
+ open_command = "open #{link}"
1595
+ elsif RbConfig::CONFIG['host_os'] =~ /linux|bsd/
1596
+ open_command = "xdg-open #{link}"
1597
+ end
1598
+
1599
+ if options[:dry_run]
1600
+ puts "system: #{open_command}"
1601
+ return 0
1602
+ end
1603
+
1604
+ system(open_command)
1605
+
1606
+ return 0
1607
+ rescue RestClient::Exception => e
1608
+ print_rest_exception(e, options)
1609
+ exit 1
1610
+ end
1611
+ end
1612
+
1613
+ def update_wiki(args)
1614
+ options = {}
1615
+ params = {}
1616
+ optparse = Morpheus::Cli::OptionParser.new do |opts|
1617
+ opts.banner = subcommand_usage("[app] [options]")
1618
+ build_option_type_options(opts, options, update_wiki_page_option_types)
1619
+ opts.on('--file FILE', "File containing the wiki content. This can be used instead of --content") do |filename|
1620
+ full_filename = File.expand_path(filename)
1621
+ if File.exists?(full_filename)
1622
+ params['content'] = File.read(full_filename)
1623
+ else
1624
+ print_red_alert "File not found: #{full_filename}"
1625
+ return 1
1626
+ end
1627
+ # use the filename as the name by default.
1628
+ if !params['name']
1629
+ params['name'] = File.basename(full_filename)
1630
+ end
1631
+ end
1632
+ opts.on(nil, '--clear', "Clear current page content") do |val|
1633
+ params['content'] = ""
1634
+ end
1635
+ build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote])
1636
+ end
1637
+ optparse.parse!(args)
1638
+ if args.count != 1
1639
+ puts_error "#{Morpheus::Terminal.angry_prompt}wrong number of arguments. Expected 1 and received #{args.count} #{args.inspect}\n#{optparse}"
1640
+ return 1
1641
+ end
1642
+ connect(options)
1643
+
1644
+ begin
1645
+ app = find_app_by_name_or_id(args[0])
1646
+ return 1 if app.nil?
1647
+ # construct payload
1648
+ passed_options = options[:options] ? options[:options].reject {|k,v| k.is_a?(Symbol) } : {}
1649
+ payload = nil
1650
+ if options[:payload]
1651
+ payload = options[:payload]
1652
+ payload.deep_merge!({'page' => passed_options}) unless passed_options.empty?
1653
+ else
1654
+ payload = {
1655
+ 'page' => {
1656
+ }
1657
+ }
1658
+ # allow arbitrary -O options
1659
+ payload.deep_merge!({'page' => passed_options}) unless passed_options.empty?
1660
+ # prompt for options
1661
+ #params = Morpheus::Cli::OptionTypes.prompt(update_wiki_page_option_types, options[:options], @api_client, options[:params])
1662
+ #params = passed_options
1663
+ params.deep_merge!(passed_options)
1664
+
1665
+ if params.empty?
1666
+ raise_command_error "Specify at least one option to update.\n#{optparse}"
1667
+ end
1668
+
1669
+ payload.deep_merge!({'page' => params}) unless params.empty?
1670
+ end
1671
+ @apps_interface.setopts(options)
1672
+ if options[:dry_run]
1673
+ print_dry_run @apps_interface.dry.update_wiki(app["id"], payload)
1674
+ return
1675
+ end
1676
+ json_response = @apps_interface.update_wiki(app["id"], payload)
1677
+
1678
+ if options[:json]
1679
+ puts as_json(json_response, options)
1680
+ else
1681
+ print_green_success "Updated wiki page for app #{app['name']}"
1682
+ wiki([app['id']])
1683
+ end
1684
+ return 0
1685
+ rescue RestClient::Exception => e
1686
+ print_rest_exception(e, options)
1687
+ exit 1
1688
+ end
1689
+ end
1690
+
1490
1691
  private
1491
1692
 
1492
1693
  def extract_app_tiers(app)
@@ -1721,7 +1922,6 @@ class Morpheus::Cli::Apps
1721
1922
 
1722
1923
  # lookup scoped instance config in a blueprint
1723
1924
  # this only finds one right now
1724
- # def tmplCfg = getConfigMap(appTemplateConfig?.tiers?.getAt(tierName)?.instances?.getAt(index), opts.environment, opts.group, instanceOpts.instance.cloud?: opts?.defaultCloud?.name)
1725
1925
  def get_scoped_instance_config(instance_config, env_name, group_name, cloud_name)
1726
1926
  config = instance_config.clone
1727
1927
  if env_name.to_s != '' && config['environments'] && config['environments'][env_name]
@@ -1741,23 +1941,11 @@ class Morpheus::Cli::Apps
1741
1941
  return config
1742
1942
  end
1743
1943
 
1744
- # def getConfigMap(instance, env, group, cloud) {
1745
- # def configMap = instance
1746
- # if(env && instance?.environments) {
1747
- # def envName = (env instanceof String? env : env?.name)
1748
- # configMap = instance?.environments?.getAt(envName) ?: instance
1749
- # }
1750
- # if(group && configMap?.groups) {
1751
- # if (group instanceof String) {
1752
- # configMap = configMap?.groups?.getAt(group) ?: configMap
1753
- # }
1754
- # else {
1755
- # configMap = configMap?.groups?.getAt(group?.name) ?: configMap
1756
- # }
1757
- # }
1758
- # if(cloud && configMap?.clouds) {
1759
- # return configMap?.clouds?.getAt(cloud) ?: configMap
1760
- # }
1761
- # return configMap
1762
- # }
1944
+ def update_wiki_page_option_types
1945
+ [
1946
+ {'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => false, 'displayOrder' => 1, 'description' => 'The name of the wiki page for this instance. Default is the instance name.'},
1947
+ #{'fieldName' => 'category', 'fieldLabel' => 'Category', 'type' => 'text', 'required' => false, 'displayOrder' => 2},
1948
+ {'fieldName' => 'content', 'fieldLabel' => 'Content', 'type' => 'textarea', 'required' => false, 'displayOrder' => 3, 'description' => 'The content (markdown) of the wiki page.'}
1949
+ ]
1950
+ end
1763
1951
  end