Top Level Namespace

Instance Method Summary collapse

Instance Method Details

#create_instance(type) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/res_cli.rb', line 27

def create_instance(type)
    begin
      # Implement create instance logic
      puts "Creating #{type} instance..."
  
      # Run Docker command to create a new instance
      container_name = "#{type}_instance"
      command = ["docker", "run", "--name", container_name, "-d", "expolab/#{type}:arm64"]
  
      output, status = Open3.capture2(*command)
  
      unless status.success?
        raise "Error creating instance: #{output}"
      end
  
      puts "#{type} instance created successfully with container name: #{container_name}"
  
    rescue => error
      $stderr.puts "Error creating instance: #{error}"
    end
end

#delete_instance(instance_id) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/res_cli.rb', line 76

def delete_instance(instance_id)
  begin
    # Implement delete instance logic
    puts "Deleting instance #{instance_id}..."

    # Stop the Docker container
    _, stop_status = Open3.capture2("docker stop #{instance_id}")

    unless stop_status.success?
      raise "Error stopping instance: #{stop_status}"
    end

    # Remove the Docker container
    _, rm_status = Open3.capture2("docker rm #{instance_id}")

    unless rm_status.success?
      raise "Error removing instance: #{rm_status}"
    end

    puts "Instance deleted successfully."

  rescue => error
    $stderr.puts "Error deleting instance: #{error}"
  end
end

#exec_into(instance_id) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/res_cli.rb', line 49

def exec_into(instance_id)
  begin
    command = ["docker", "exec", "-it", instance_id, "bash"]
    Open3.check2(*command)

  rescue => error
    $stderr.puts "Error executing command: #{error}"
  end
end

#get_logged_in_userObject



8
9
10
# File 'lib/res_cli.rb', line 8

def get_logged_in_user
  config['User']['Current_User']
end

#helpObject



17
18
19
20
21
22
23
24
25
# File 'lib/res_cli.rb', line 17

def help
    puts "Usage: #{$PROGRAM_NAME} [options]"
    puts "\nOptions:"
    puts "  -c, --create TYPE     Create a new ResDB or PythonSDK instance"
    puts "  -e, --exec-into INSTANCE_ID  Bash into a running ResDB or PythonSDK instance"
    puts "  -v, --view-instances  View details about running instances"
    puts "  -d, --delete INSTANCE_ID  Delete a running ResDB or PythonSDK instance"
    puts "  -h, --help            Display this help message"
end

#set_logged_in_user(username) ⇒ Object



12
13
14
15
# File 'lib/res_cli.rb', line 12

def set_logged_in_user(username)
  config['User']['Current_User'] = username
  config.write
end

#view_instancesObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/res_cli.rb', line 59

def view_instances
  begin
    docker_command = ["docker", "container", "ls", "--format", "table {{.ID}}\t{{.Image}}\t{{.Names}}"]
    output, status = Open3.capture2(*docker_command)

    unless status.success?
      raise "Error running docker command: #{output}"
    end

    puts output

  rescue => error
    $stderr.puts "An unexpected error occurred: #{error}"
  end
end