res_cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/bin/res_cli +5 -0
  3. data/config.ini +6 -0
  4. data/lib/res_cli.rb +126 -0
  5. metadata +47 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0d43f6c2fecb50cf8ee1e1bd5af62b2241ee0706ac817f73cc474b0e7ac5b4ba
4
+ data.tar.gz: 37a3b78c258e9aafbc1fe4a53e92c6d697a813c7644dc1a68d3eb3c14cdb2c3d
5
+ SHA512:
6
+ metadata.gz: c279e2bcfb9a41ece945b5e4214073c4f166dcf452fd9d803867093850fd4bc2ad1b1e9931e927ccd22efa28c71657ca0ca1fa10134247c49399922ded693ddb
7
+ data.tar.gz: '07149701dd95788b6589f00fe23a53031ee68072145e892750a2f83e50a05fa63e2193313c4062e04f2c6a2178c24b5de05ee9c16b24486e69fb25c8f30065ae'
data/bin/res_cli ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/res_cli'
4
+
5
+ ResCLI::CLI.new.call
data/config.ini ADDED
@@ -0,0 +1,6 @@
1
+ [Server]
2
+ flask_base_url =
3
+
4
+ [User]
5
+ current_user =
6
+
data/lib/res_cli.rb ADDED
@@ -0,0 +1,126 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require 'open3'
4
+ require 'inifile'
5
+
6
+ config = IniFile.load('config.ini')
7
+
8
+ def get_logged_in_user
9
+ config['User']['Current_User']
10
+ end
11
+
12
+ def set_logged_in_user(username)
13
+ config['User']['Current_User'] = username
14
+ config.write
15
+ end
16
+
17
+ def help
18
+ puts "Usage: #{$PROGRAM_NAME} [options]"
19
+ puts "\nOptions:"
20
+ puts " -c, --create TYPE Create a new ResDB or PythonSDK instance"
21
+ puts " -e, --exec-into INSTANCE_ID Bash into a running ResDB or PythonSDK instance"
22
+ puts " -v, --view-instances View details about running instances"
23
+ puts " -d, --delete INSTANCE_ID Delete a running ResDB or PythonSDK instance"
24
+ puts " -h, --help Display this help message"
25
+ end
26
+
27
+ def create_instance(type)
28
+ begin
29
+ # Implement create instance logic
30
+ puts "Creating #{type} instance..."
31
+
32
+ # Run Docker command to create a new instance
33
+ container_name = "#{type}_instance"
34
+ command = ["docker", "run", "--name", container_name, "-d", "expolab/#{type}:arm64"]
35
+
36
+ output, status = Open3.capture2(*command)
37
+
38
+ unless status.success?
39
+ raise "Error creating instance: #{output}"
40
+ end
41
+
42
+ puts "#{type} instance created successfully with container name: #{container_name}"
43
+
44
+ rescue => error
45
+ $stderr.puts "Error creating instance: #{error}"
46
+ end
47
+ end
48
+
49
+ def exec_into(instance_id)
50
+ begin
51
+ command = ["docker", "exec", "-it", instance_id, "bash"]
52
+ Open3.check2(*command)
53
+
54
+ rescue => error
55
+ $stderr.puts "Error executing command: #{error}"
56
+ end
57
+ end
58
+
59
+ def view_instances
60
+ begin
61
+ docker_command = ["docker", "container", "ls", "--format", "table {{.ID}}\t{{.Image}}\t{{.Names}}"]
62
+ output, status = Open3.capture2(*docker_command)
63
+
64
+ unless status.success?
65
+ raise "Error running docker command: #{output}"
66
+ end
67
+
68
+ puts output
69
+
70
+ rescue => error
71
+ $stderr.puts "An unexpected error occurred: #{error}"
72
+ end
73
+ end
74
+
75
+
76
+ def delete_instance(instance_id)
77
+ begin
78
+ # Implement delete instance logic
79
+ puts "Deleting instance #{instance_id}..."
80
+
81
+ # Stop the Docker container
82
+ _, stop_status = Open3.capture2("docker stop #{instance_id}")
83
+
84
+ unless stop_status.success?
85
+ raise "Error stopping instance: #{stop_status}"
86
+ end
87
+
88
+ # Remove the Docker container
89
+ _, rm_status = Open3.capture2("docker rm #{instance_id}")
90
+
91
+ unless rm_status.success?
92
+ raise "Error removing instance: #{rm_status}"
93
+ end
94
+
95
+ puts "Instance deleted successfully."
96
+
97
+ rescue => error
98
+ $stderr.puts "Error deleting instance: #{error}"
99
+ end
100
+ end
101
+
102
+ options = {}
103
+ OptionParser.new do |opts|
104
+ opts.banner = "Usage: #{$PROGRAM_NAME} [options]"
105
+
106
+ opts.on('-c', '--create TYPE', [:resdb, :sdk], 'Create a new ResDB or PythonSDK instance') do |type|
107
+ create_instance(type)
108
+ end
109
+
110
+ opts.on('-e', '--exec-into INSTANCE_ID', 'Bash into a running ResDB or PythonSDK instance') do |instance_id|
111
+ exec_into(instance_id)
112
+ end
113
+
114
+ opts.on('-v', '--view-instances', 'View details about running instances') do
115
+ view_instances
116
+ end
117
+
118
+ opts.on('-d', '--delete INSTANCE_ID', 'Delete a running ResDB or PythonSDK instance') do |instance_id|
119
+ delete_instance(instance_id)
120
+ end
121
+
122
+ opts.on('-h', '--help', 'Display this help message') do
123
+ help
124
+ exit
125
+ end
126
+ end.parse!
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: res_cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - gopuman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-02-29 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A command-line interface (CLI) to manage ResilientDB and Python SDK instances.
14
+ email:
15
+ - gopalnambiar2@gmail.com
16
+ executables:
17
+ - res_cli
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - bin/res_cli
22
+ - config.ini
23
+ - lib/res_cli.rb
24
+ homepage: https://github.com/ResilientApp/ResCLI
25
+ licenses:
26
+ - APSL-2.0
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubygems_version: 3.5.3
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: CLI to manage ResilientDB and Python SDK instances
47
+ test_files: []