Class: SharedTools::Tools::DevopsToolkit

Inherits:
RubyLLM::Tool
  • Object
show all
Defined in:
lib/shared_tools/tools/devops_toolkit.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger: nil) ⇒ DevopsToolkit

Returns a new instance of DevopsToolkit.



82
83
84
85
# File 'lib/shared_tools/tools/devops_toolkit.rb', line 82

def initialize(logger: nil)
  @logger = logger || RubyLLM.logger
  @operation_log = []
end

Class Method Details

.nameObject



8
# File 'lib/shared_tools/tools/devops_toolkit.rb', line 8

def self.name = "devops_toolkit"

Instance Method Details

#execute(operation:, environment: "staging", **options) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/shared_tools/tools/devops_toolkit.rb', line 87

def execute(operation:, environment: "staging", **options)
  operation_id = SecureRandom.uuid
  @logger.info("DevOpsToolkit#execute operation=#{operation} environment=#{environment} operation_id=#{operation_id}")

  # Validate environment
  unless valid_environment?(environment)
    return {
      success: false,
      error: "Invalid environment: #{environment}",
      valid_environments: ["development", "staging", "production"]
    }
  end

  # Security: Require explicit production confirmation
  if environment == "production" && !options[:production_confirmed]
    @logger.warn("Production operation attempted without confirmation")
    return {
      success: false,
      error: "Production operations require explicit confirmation",
      required_option: "production_confirmed: true",
      environment: environment
    }
  end

  # Log operation
  log_operation(operation_id, operation, environment, options)

  # Execute operation
  result = case operation
  when "deploy"
    perform_deployment(environment, options, operation_id)
  when "rollback"
    perform_rollback(environment, options, operation_id)
  when "health_check"
    perform_health_check(environment, options, operation_id)
  when "log_analysis"
    analyze_logs(environment, options, operation_id)
  when "metric_collection"
    collect_metrics(environment, options, operation_id)
  else
    {
      success: false,
      error: "Unknown operation: #{operation}",
      valid_operations: ["deploy", "rollback", "health_check", "log_analysis", "metric_collection"]
    }
  end

  # Add operation_id to result
  result[:operation_id] = operation_id
  result
rescue => e
  @logger.error("DevOps operation failed: #{e.message}")
  {
    success: false,
    error: "DevOps operation failed: #{e.message}",
    error_type: e.class.name,
    operation_id: operation_id
  }
end