durable-proxmox-ruby 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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +30 -0
- data/LICENSE +21 -0
- data/README.md +572 -0
- data/durable-proxmox-ruby.gemspec +47 -0
- data/exe/proxmox +218 -0
- data/lib/durable_proxmox/client.rb +262 -0
- data/lib/durable_proxmox/dsl.rb +374 -0
- data/lib/durable_proxmox/errors.rb +44 -0
- data/lib/durable_proxmox/ip_address_group.rb +99 -0
- data/lib/durable_proxmox/node.rb +126 -0
- data/lib/durable_proxmox/version.rb +5 -0
- data/lib/durable_proxmox/vm.rb +200 -0
- data/lib/durable_proxmox.rb +31 -0
- metadata +201 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 77769cb099a33a2cda9e1ddb3c170bce9a642e15e8d31b85c8c833a23c23220e
|
|
4
|
+
data.tar.gz: 4484d3acb3ce9d406d888acec028bc1a9be925ea7eecc9ce4091543b2cc58b08
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 3e4aecb1d8963b1c665f8519b597bfea9f914675d371eedb63cbef446075dc14eb355dbe1c1eb0f9a536942d90050ac46720a98b35a9cc4db6e50c8e6d993307
|
|
7
|
+
data.tar.gz: 65e00f1417e3b4fa036f619ec8ec627363dec685d79033aa7dcea7b8ea78fb07c974682bae5a17dbb6335f4f6da7c4bee6d63ae2c5e42ecce010414e4bfb1bf1
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.0] - 2025-01-26
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial release of durable-proxmox-ruby gem
|
|
12
|
+
- Clean API interface for Proxmox VE interaction
|
|
13
|
+
- Automatic authentication with ticket and CSRF token handling
|
|
14
|
+
- VM lifecycle management (clone, start, stop, delete)
|
|
15
|
+
- Network configuration retrieval (IP addresses, MAC addresses)
|
|
16
|
+
- DHCP/DNS integration with VyOS
|
|
17
|
+
- Caching support for improved performance
|
|
18
|
+
- Task monitoring for asynchronous operations
|
|
19
|
+
- Comprehensive documentation and examples
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
- Refactored from old script-based structure to proper Ruby gem
|
|
23
|
+
- Updated class names to use DurableProxmox module namespace
|
|
24
|
+
- Improved error handling and code documentation
|
|
25
|
+
|
|
26
|
+
### Technical Details
|
|
27
|
+
- Ruby 2.7+ compatibility
|
|
28
|
+
- Dependencies: faraday, json, dotenv, sshkit, ipaddr
|
|
29
|
+
- Modular architecture with autoloading
|
|
30
|
+
- Comprehensive test suite foundation
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Durable Programming LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,572 @@
|
|
|
1
|
+
# durable-proxmox-ruby
|
|
2
|
+
|
|
3
|
+
A pragmatic Ruby library for interacting with Proxmox VE through a clean API, featuring both imperative API methods and a declarative DSL for infrastructure management. Built with a focus on reliability, maintainability, and developer experience.
|
|
4
|
+
|
|
5
|
+
This library solves the problem of programmatically managing Proxmox virtual environments without the complexity of shell scripts or manual API calls. It's designed for system administrators and developers who need to automate VM provisioning, configuration, and infrastructure-as-code workflows.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Clean API Interface**: Interact with Proxmox VE through intuitive Ruby objects (Client, Node, VM)
|
|
10
|
+
- **Declarative DSL**: Define and update Proxmox server configurations using declarative scripts
|
|
11
|
+
- **Export System**: Connect to a running Proxmox server and generate declarative configuration scripts from the current state
|
|
12
|
+
- **Automatic Authentication**: Handles Proxmox API token authentication automatically
|
|
13
|
+
- **VM Lifecycle Management**: Clone, start, stop, and delete virtual machines programmatically
|
|
14
|
+
- **Network Configuration**: Retrieve IP addresses, MAC addresses, and network interface information
|
|
15
|
+
- **DHCP/DNS Integration**: Automatically register VMs with VyOS-based DHCP and DNS services
|
|
16
|
+
- **Caching Support**: Built-in caching for improved performance when querying VM and node data
|
|
17
|
+
- **Task Monitoring**: Wait for asynchronous Proxmox tasks (UPIDs) to complete
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
```ruby
|
|
22
|
+
require 'durable_proxmox'
|
|
23
|
+
|
|
24
|
+
# Create a client (uses ENV['PROXMOX_API_URL_BASE'] by default)
|
|
25
|
+
client = DurableProxmox::Client.new
|
|
26
|
+
|
|
27
|
+
# Get the first node
|
|
28
|
+
node = client.nodes.first
|
|
29
|
+
|
|
30
|
+
# List all VMs
|
|
31
|
+
node.vms.each do |vm|
|
|
32
|
+
puts "#{vm.name} (#{vm.vm_id}): #{vm.status}"
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Clone a VM
|
|
36
|
+
new_vmid = node.spawn_vm('my-new-server')
|
|
37
|
+
puts "Created VM with ID: #{new_vmid}"
|
|
38
|
+
|
|
39
|
+
# Get VM details
|
|
40
|
+
vm = node.vms.find { |v| v.vm_id == new_vmid }
|
|
41
|
+
puts "IP Address: #{vm.get_ip}"
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
### Prerequisites
|
|
47
|
+
|
|
48
|
+
- Ruby 2.7 or higher
|
|
49
|
+
- Access to a Proxmox VE server
|
|
50
|
+
- Valid Proxmox credentials
|
|
51
|
+
|
|
52
|
+
### Setup
|
|
53
|
+
|
|
54
|
+
1. Install the gem:
|
|
55
|
+
```bash
|
|
56
|
+
gem install durable-proxmox-ruby
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Or add to your Gemfile:
|
|
60
|
+
```ruby
|
|
61
|
+
gem 'durable-proxmox-ruby'
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
2. Configure environment variables:
|
|
65
|
+
```bash
|
|
66
|
+
# Required
|
|
67
|
+
export PROXMOX_HOSTNAME='your-proxmox-server'
|
|
68
|
+
export PROXMOX_USERNAME='your-username@pam'
|
|
69
|
+
export PROXMOX_API_TOKEN_NAME='your-token-name'
|
|
70
|
+
export PROXMOX_API_TOKEN_SECRET='your-token-secret'
|
|
71
|
+
|
|
72
|
+
# Optional
|
|
73
|
+
export SOURCE_VMID=911 # Template VM ID for cloning (default: 911)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
3. Load environment variables (using dotenv):
|
|
77
|
+
```ruby
|
|
78
|
+
require 'dotenv'
|
|
79
|
+
Dotenv.load
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Usage
|
|
83
|
+
|
|
84
|
+
### Basic API Usage
|
|
85
|
+
|
|
86
|
+
#### Connecting to Proxmox
|
|
87
|
+
|
|
88
|
+
```ruby
|
|
89
|
+
require_relative './old/init.rb'
|
|
90
|
+
|
|
91
|
+
# Create a client with automatic authentication
|
|
92
|
+
client = DurableProxmoxClient.new
|
|
93
|
+
|
|
94
|
+
# Or specify a custom URL
|
|
95
|
+
client = DurableProxmoxClient.new('https://custom-server:8006/api2/json/')
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
#### Working with Nodes
|
|
99
|
+
|
|
100
|
+
```ruby
|
|
101
|
+
# Get all nodes
|
|
102
|
+
nodes = client.nodes
|
|
103
|
+
|
|
104
|
+
# Access node properties
|
|
105
|
+
node = nodes.first
|
|
106
|
+
puts node.name
|
|
107
|
+
puts node.status
|
|
108
|
+
puts node.cpu
|
|
109
|
+
puts node.memory
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
#### Managing Virtual Machines
|
|
113
|
+
|
|
114
|
+
```ruby
|
|
115
|
+
# List VMs on a node
|
|
116
|
+
vms = node.vms
|
|
117
|
+
|
|
118
|
+
# Access VM properties
|
|
119
|
+
vm = vms.first
|
|
120
|
+
puts vm.name # VM hostname
|
|
121
|
+
puts vm.vm_id # Proxmox VMID
|
|
122
|
+
puts vm.status # running, stopped, etc.
|
|
123
|
+
puts vm.cpu # CPU usage
|
|
124
|
+
puts vm.memory # Memory usage
|
|
125
|
+
|
|
126
|
+
# Get VM configuration
|
|
127
|
+
config = vm.config
|
|
128
|
+
puts config.inspect
|
|
129
|
+
|
|
130
|
+
# Get network information
|
|
131
|
+
mac_addresses = vm.mac_addresses
|
|
132
|
+
ip_addresses = vm.ip_addresses
|
|
133
|
+
network_interfaces = vm.network_interfaces
|
|
134
|
+
|
|
135
|
+
# Start/stop VMs
|
|
136
|
+
vm.start
|
|
137
|
+
vm.stop
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
#### Cloning VMs
|
|
141
|
+
|
|
142
|
+
```ruby
|
|
143
|
+
# Clone from template (uses SOURCE_VMID environment variable)
|
|
144
|
+
new_vmid = node.spawn_vm('new-hostname')
|
|
145
|
+
|
|
146
|
+
# The method automatically:
|
|
147
|
+
# - Generates the next available VMID
|
|
148
|
+
# - Performs a full clone
|
|
149
|
+
# - Waits for the clone operation to complete
|
|
150
|
+
# - Returns the new VMID
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
#### Network Registration
|
|
154
|
+
|
|
155
|
+
```ruby
|
|
156
|
+
# Register VM with DHCP (VyOS integration)
|
|
157
|
+
vm.register_dhcp
|
|
158
|
+
|
|
159
|
+
# Register VM with DNS (VyOS integration)
|
|
160
|
+
vm.register_dns
|
|
161
|
+
|
|
162
|
+
# Get assigned IP address
|
|
163
|
+
ip = vm.get_ip
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
#### Task Management
|
|
167
|
+
|
|
168
|
+
```ruby
|
|
169
|
+
# Wait for an asynchronous Proxmox task to complete
|
|
170
|
+
client.wait_for_upid(node, upid)
|
|
171
|
+
|
|
172
|
+
# This is automatically called by operations like spawn_vm
|
|
173
|
+
# but can be used manually for custom API calls
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Advanced Usage
|
|
177
|
+
|
|
178
|
+
#### Caching
|
|
179
|
+
|
|
180
|
+
The library includes built-in caching to reduce API calls:
|
|
181
|
+
|
|
182
|
+
```ruby
|
|
183
|
+
# First call queries the API
|
|
184
|
+
vms = node.vms
|
|
185
|
+
|
|
186
|
+
# Subsequent calls use cached data
|
|
187
|
+
vms = node.vms # No API call
|
|
188
|
+
|
|
189
|
+
# Clear cache when needed
|
|
190
|
+
node.clear_cache
|
|
191
|
+
|
|
192
|
+
# Per-VM caching
|
|
193
|
+
vm.clear_cache
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
#### Finding Available VMID
|
|
197
|
+
|
|
198
|
+
```ruby
|
|
199
|
+
# Get the next available VMID
|
|
200
|
+
next_id = node.get_next_vmid
|
|
201
|
+
|
|
202
|
+
# This method:
|
|
203
|
+
# - Finds gaps in existing VMIDs
|
|
204
|
+
# - Excludes reserved IDs
|
|
205
|
+
# - Considers both VMs and LXC containers
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
#### Working with IP Addresses
|
|
209
|
+
|
|
210
|
+
```ruby
|
|
211
|
+
# Get all IP addresses for a VM
|
|
212
|
+
ip_group = vm.ip_addresses
|
|
213
|
+
|
|
214
|
+
# Filter by subnet
|
|
215
|
+
local_ips = vm.ip_addresses.in_subnets('192.168.2.0/23')
|
|
216
|
+
|
|
217
|
+
# Get first IP in subnet
|
|
218
|
+
primary_ip = local_ips.octets.first
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Declarative DSL (Planned)
|
|
222
|
+
|
|
223
|
+
The declarative DSL allows you to define infrastructure as code:
|
|
224
|
+
|
|
225
|
+
```ruby
|
|
226
|
+
# Example (future feature)
|
|
227
|
+
Proxmox.configure do
|
|
228
|
+
node 'pve-node-1' do
|
|
229
|
+
vm 'web-server-1' do
|
|
230
|
+
vmid 100
|
|
231
|
+
memory 4096
|
|
232
|
+
cores 2
|
|
233
|
+
disk size: '50G'
|
|
234
|
+
network bridge: 'vmbr0'
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### Export System (Planned)
|
|
241
|
+
|
|
242
|
+
Export current Proxmox configuration to declarative scripts:
|
|
243
|
+
|
|
244
|
+
```ruby
|
|
245
|
+
# Example (future feature)
|
|
246
|
+
client = DurableProxmoxClient.new
|
|
247
|
+
config = client.export_configuration
|
|
248
|
+
|
|
249
|
+
# Save to file
|
|
250
|
+
File.write('proxmox-config.rb', config)
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
## API Reference
|
|
254
|
+
|
|
255
|
+
### DurableProxmox::Client
|
|
256
|
+
|
|
257
|
+
Main client for interacting with Proxmox API.
|
|
258
|
+
|
|
259
|
+
#### Methods
|
|
260
|
+
|
|
261
|
+
- `initialize(url_base = nil)` - Create a new client with automatic authentication
|
|
262
|
+
- `nodes` - Returns array of DurableProxmox::Node objects
|
|
263
|
+
- `get(path)` - Perform authenticated GET request
|
|
264
|
+
- `post(path, params = {})` - Perform authenticated POST request
|
|
265
|
+
- `delete(path)` - Perform authenticated DELETE request
|
|
266
|
+
- `wait_for_upid(node, upid)` - Wait for asynchronous task to complete
|
|
267
|
+
|
|
268
|
+
### DurableProxmox::Node
|
|
269
|
+
|
|
270
|
+
Represents a Proxmox node.
|
|
271
|
+
|
|
272
|
+
#### Attributes
|
|
273
|
+
|
|
274
|
+
- `name` - Node name
|
|
275
|
+
- `node_id` - Node identifier
|
|
276
|
+
- `status` - Node status
|
|
277
|
+
- `cpu` - CPU usage
|
|
278
|
+
- `memory` - Memory usage
|
|
279
|
+
|
|
280
|
+
#### Methods
|
|
281
|
+
|
|
282
|
+
- `vms` - Returns array of DurableProxmox::VM objects
|
|
283
|
+
- `lxcs` - Returns array of LXC container data
|
|
284
|
+
- `spawn_vm(hostname)` - Clone template VM with given hostname
|
|
285
|
+
- `delete_vm(vm)` - Delete a VM
|
|
286
|
+
- `get_next_vmid` - Get next available VMID
|
|
287
|
+
- `clear_cache` - Clear cached data
|
|
288
|
+
|
|
289
|
+
### DurableProxmox::VM
|
|
290
|
+
|
|
291
|
+
Represents a Proxmox virtual machine.
|
|
292
|
+
|
|
293
|
+
#### Attributes
|
|
294
|
+
|
|
295
|
+
- `vm_id` - Proxmox VMID
|
|
296
|
+
- `name` - VM hostname
|
|
297
|
+
- `status` - VM status (running, stopped, etc.)
|
|
298
|
+
- `cpu` - CPU usage
|
|
299
|
+
- `memory` - Memory usage
|
|
300
|
+
- `data` - Raw VM data from API
|
|
301
|
+
|
|
302
|
+
#### Methods
|
|
303
|
+
|
|
304
|
+
- `start` - Start the VM
|
|
305
|
+
- `stop` - Stop the VM
|
|
306
|
+
- `delete` - Delete the VM
|
|
307
|
+
- `config` - Get VM configuration
|
|
308
|
+
- `mac_addresses` - Get array of MAC addresses
|
|
309
|
+
- `network_interfaces` - Get network interface data
|
|
310
|
+
- `ip_addresses` - Get DurableProxmox::IPAddressGroup
|
|
311
|
+
- `mac` - Get first MAC address
|
|
312
|
+
- `get_ip` - Get primary IP address
|
|
313
|
+
- `register_dhcp` - Register with DHCP server (VyOS)
|
|
314
|
+
- `register_dns` - Register with DNS server (VyOS)
|
|
315
|
+
- `clear_cache` - Clear cached data
|
|
316
|
+
|
|
317
|
+
## Configuration
|
|
318
|
+
|
|
319
|
+
Configuration is handled through environment variables:
|
|
320
|
+
|
|
321
|
+
| Variable | Required | Default | Description |
|
|
322
|
+
|----------|----------|---------|-------------|
|
|
323
|
+
| `PROXMOX_HOSTNAME` | No | `fuzzyfireball.durablelan` | Proxmox server hostname |
|
|
324
|
+
| `PROXMOX_USERNAME` | Yes | - | Proxmox username (e.g., `root@pam`) |
|
|
325
|
+
| `PROXMOX_API_TOKEN_NAME` | Yes | - | API token name |
|
|
326
|
+
| `PROXMOX_API_TOKEN_SECRET` | Yes | - | API token secret |
|
|
327
|
+
| `SOURCE_VMID` | No | `911` | Template VM ID for cloning |
|
|
328
|
+
|
|
329
|
+
## Examples
|
|
330
|
+
|
|
331
|
+
### Example 1: Bulk VM Provisioning
|
|
332
|
+
|
|
333
|
+
```ruby
|
|
334
|
+
require 'durable_proxmox'
|
|
335
|
+
|
|
336
|
+
client = DurableProxmox::Client.new
|
|
337
|
+
node = client.nodes.first
|
|
338
|
+
|
|
339
|
+
# Create multiple VMs from hostnames
|
|
340
|
+
hostnames = ['web-01', 'web-02', 'db-01', 'cache-01']
|
|
341
|
+
|
|
342
|
+
hostnames.each do |hostname|
|
|
343
|
+
puts "Creating #{hostname}..."
|
|
344
|
+
|
|
345
|
+
# Check if VM already exists
|
|
346
|
+
existing = node.vms.find { |vm| vm.name == hostname }
|
|
347
|
+
if existing
|
|
348
|
+
puts " #{hostname} already exists, skipping..."
|
|
349
|
+
next
|
|
350
|
+
end
|
|
351
|
+
|
|
352
|
+
# Clone VM
|
|
353
|
+
vmid = node.spawn_vm(hostname)
|
|
354
|
+
node.clear_cache # Refresh VM list
|
|
355
|
+
|
|
356
|
+
# Register with network services
|
|
357
|
+
vm = node.vms.find { |v| v.vm_id == vmid }
|
|
358
|
+
vm.register_dhcp
|
|
359
|
+
vm.register_dns
|
|
360
|
+
|
|
361
|
+
puts " Created #{hostname} (VMID: #{vmid}, IP: #{vm.get_ip})"
|
|
362
|
+
end
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
### Example 2: VM Inventory Report
|
|
366
|
+
|
|
367
|
+
```ruby
|
|
368
|
+
require 'durable_proxmox'
|
|
369
|
+
require 'json'
|
|
370
|
+
|
|
371
|
+
client = DurableProxmox::Client.new
|
|
372
|
+
node = client.nodes.first
|
|
373
|
+
|
|
374
|
+
# Generate inventory report
|
|
375
|
+
inventory = node.vms.map do |vm|
|
|
376
|
+
{
|
|
377
|
+
name: vm.name,
|
|
378
|
+
vmid: vm.vm_id,
|
|
379
|
+
status: vm.status,
|
|
380
|
+
ip: vm.get_ip,
|
|
381
|
+
mac: vm.mac,
|
|
382
|
+
memory: vm.memory,
|
|
383
|
+
cpu: vm.cpu
|
|
384
|
+
}
|
|
385
|
+
end
|
|
386
|
+
|
|
387
|
+
# Output as JSON
|
|
388
|
+
puts JSON.pretty_generate(inventory)
|
|
389
|
+
|
|
390
|
+
# Or save to file
|
|
391
|
+
File.write('vm-inventory.json', JSON.pretty_generate(inventory))
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
### Example 3: Automated VM Cleanup
|
|
395
|
+
|
|
396
|
+
```ruby
|
|
397
|
+
require 'durable_proxmox'
|
|
398
|
+
|
|
399
|
+
client = DurableProxmox::Client.new
|
|
400
|
+
node = client.nodes.first
|
|
401
|
+
|
|
402
|
+
# Find and remove test VMs
|
|
403
|
+
test_vms = node.vms.select { |vm| vm.name.start_with?('test-') }
|
|
404
|
+
|
|
405
|
+
test_vms.each do |vm|
|
|
406
|
+
puts "Removing test VM: #{vm.name} (#{vm.vm_id})"
|
|
407
|
+
|
|
408
|
+
# Stop if running
|
|
409
|
+
vm.stop if vm.status == 'running'
|
|
410
|
+
sleep 5 # Wait for clean shutdown
|
|
411
|
+
|
|
412
|
+
# Delete VM
|
|
413
|
+
node.delete_vm(vm)
|
|
414
|
+
end
|
|
415
|
+
|
|
416
|
+
puts "Removed #{test_vms.length} test VMs"
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
## Architecture
|
|
420
|
+
|
|
421
|
+
This library follows a modular, object-oriented design:
|
|
422
|
+
|
|
423
|
+
```
|
|
424
|
+
DurableProxmoxClient
|
|
425
|
+
├── Authentication (API token)
|
|
426
|
+
├── HTTP client (Faraday)
|
|
427
|
+
└── Node management
|
|
428
|
+
└── DurableProxmoxNode
|
|
429
|
+
├── VM management
|
|
430
|
+
│ └── DurableProxmoxVM
|
|
431
|
+
│ ├── Lifecycle (start/stop/clone)
|
|
432
|
+
│ ├── Network info
|
|
433
|
+
│ └── Integration (DHCP/DNS)
|
|
434
|
+
└── LXC management
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
**Key Design Principles**:
|
|
438
|
+
- **Separation of Concerns**: Client, Node, and VM classes have distinct responsibilities
|
|
439
|
+
- **Lazy Loading**: Data is fetched only when needed
|
|
440
|
+
- **Caching**: Reduce API calls with intelligent caching
|
|
441
|
+
- **Error Handling**: Clear error messages for authentication and API failures
|
|
442
|
+
- **Extensibility**: Easy to add new Proxmox API endpoints
|
|
443
|
+
|
|
444
|
+
## Integration
|
|
445
|
+
|
|
446
|
+
### VyOS Integration
|
|
447
|
+
|
|
448
|
+
The library includes built-in support for VyOS network configuration:
|
|
449
|
+
|
|
450
|
+
```ruby
|
|
451
|
+
# DHCP registration (via VyOS)
|
|
452
|
+
vm.register_dhcp
|
|
453
|
+
|
|
454
|
+
# DNS registration (via VyOS)
|
|
455
|
+
vm.register_dns
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
This requires:
|
|
459
|
+
- A VyOS router accessible to the Ruby process
|
|
460
|
+
- Appropriate SSH credentials configured
|
|
461
|
+
- The `DurableVyosClient` class (see `lib/durable_vyos_client.rb`)
|
|
462
|
+
|
|
463
|
+
## Troubleshooting
|
|
464
|
+
|
|
465
|
+
### Authentication Failures
|
|
466
|
+
|
|
467
|
+
**Problem**: Authentication error
|
|
468
|
+
|
|
469
|
+
**Solution**:
|
|
470
|
+
- Verify `PROXMOX_USERNAME`, `PROXMOX_API_TOKEN_NAME`, and `PROXMOX_API_TOKEN_SECRET` are correct
|
|
471
|
+
- Ensure the API token has appropriate permissions
|
|
472
|
+
- Check that the Proxmox server is accessible at the configured hostname
|
|
473
|
+
- For self-signed certificates, you may need to configure SSL verification
|
|
474
|
+
|
|
475
|
+
### VM Not Found
|
|
476
|
+
|
|
477
|
+
**Problem**: Cannot find VM after creation
|
|
478
|
+
|
|
479
|
+
**Solution**:
|
|
480
|
+
```ruby
|
|
481
|
+
# Clear cache after creating VMs
|
|
482
|
+
node.clear_cache
|
|
483
|
+
vm = node.vms.find { |v| v.vm_id == new_vmid }
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
### Network Information Unavailable
|
|
487
|
+
|
|
488
|
+
**Problem**: `network_interfaces` returns empty array
|
|
489
|
+
|
|
490
|
+
**Solution**:
|
|
491
|
+
- Ensure the VM is running
|
|
492
|
+
- Verify QEMU guest agent is installed and running in the VM
|
|
493
|
+
- Check that the VM has had time to boot and initialize the guest agent
|
|
494
|
+
|
|
495
|
+
## Development
|
|
496
|
+
|
|
497
|
+
### Running Tests
|
|
498
|
+
|
|
499
|
+
```bash
|
|
500
|
+
# Run all tests (when available)
|
|
501
|
+
bundle exec rake test
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
### Code Style
|
|
505
|
+
|
|
506
|
+
This project follows Durable Programming coding standards:
|
|
507
|
+
- Meaningful variable names
|
|
508
|
+
- Clear method responsibilities
|
|
509
|
+
- Comprehensive error handling
|
|
510
|
+
- YARD documentation for public APIs
|
|
511
|
+
|
|
512
|
+
### Contributing
|
|
513
|
+
|
|
514
|
+
We welcome contributions! To contribute:
|
|
515
|
+
|
|
516
|
+
1. Fork the repository
|
|
517
|
+
2. Create a feature branch (`git checkout -b feature/my-feature`)
|
|
518
|
+
3. Make your changes with tests
|
|
519
|
+
4. Ensure code follows style guidelines
|
|
520
|
+
5. Submit a pull request
|
|
521
|
+
|
|
522
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines.
|
|
523
|
+
|
|
524
|
+
## Roadmap
|
|
525
|
+
|
|
526
|
+
### Planned Features
|
|
527
|
+
|
|
528
|
+
- **Declarative DSL**: Define infrastructure as code with a clean Ruby DSL
|
|
529
|
+
- **Export System**: Generate declarative scripts from existing Proxmox configurations
|
|
530
|
+
- **LXC Support**: Full support for LXC container management
|
|
531
|
+
- **Storage Management**: Create and manage storage configurations
|
|
532
|
+
- **Backup Operations**: Trigger and manage VM backups
|
|
533
|
+
- **Snapshot Management**: Create, list, and restore snapshots
|
|
534
|
+
- **User Management**: Manage Proxmox users and permissions
|
|
535
|
+
- **Template Management**: Create and manage VM templates
|
|
536
|
+
- **Cluster Support**: Multi-node cluster operations
|
|
537
|
+
|
|
538
|
+
### Future Improvements
|
|
539
|
+
|
|
540
|
+
- Comprehensive test suite with mocked API responses
|
|
541
|
+
- RubyGems publication for easy installation
|
|
542
|
+
- CLI tool for common operations
|
|
543
|
+
- Enhanced error handling and retry logic
|
|
544
|
+
- Async operation support with callbacks
|
|
545
|
+
- WebSocket support for real-time updates
|
|
546
|
+
|
|
547
|
+
## Philosophy
|
|
548
|
+
|
|
549
|
+
This library embodies Durable Programming principles:
|
|
550
|
+
|
|
551
|
+
- **Pragmatic Problem-Solving**: Solves real infrastructure automation needs without unnecessary complexity
|
|
552
|
+
- **Sustainability**: Designed for long-term maintenance and incremental improvement
|
|
553
|
+
- **Quality**: Clean, well-tested code with comprehensive error handling
|
|
554
|
+
- **Developer Experience**: Intuitive API that makes Proxmox automation approachable
|
|
555
|
+
- **Interoperability**: Works seamlessly with existing Proxmox setups and other tools
|
|
556
|
+
|
|
557
|
+
## License
|
|
558
|
+
|
|
559
|
+
MIT License - See [LICENSE](LICENSE) for details
|
|
560
|
+
|
|
561
|
+
## Support
|
|
562
|
+
|
|
563
|
+
- **Documentation**: This README and inline code documentation
|
|
564
|
+
- **Issues**: [GitHub Issues](https://github.com/yourusername/durable-proxmox-ruby/issues)
|
|
565
|
+
- **Email**: commercial@durableprogramming.com
|
|
566
|
+
|
|
567
|
+
## Credits
|
|
568
|
+
|
|
569
|
+
Built by [Durable Programming LLC](https://durableprogramming.com) with a focus on creating sustainable, maintainable infrastructure automation tools.
|
|
570
|
+
|
|
571
|
+
---
|
|
572
|
+
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/durable_proxmox/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "durable-proxmox-ruby"
|
|
7
|
+
spec.version = DurableProxmox::VERSION
|
|
8
|
+
spec.authors = ["Durable Programming LLC"]
|
|
9
|
+
spec.email = ["commercial@durableprogramming.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "A pragmatic Ruby library for interacting with Proxmox VE through a clean API"
|
|
12
|
+
spec.description = "This library solves the problem of programmatically managing Proxmox virtual environments without the complexity of shell scripts or manual API calls. It's designed for system administrators and developers who need to automate VM provisioning, configuration, and infrastructure-as-code workflows."
|
|
13
|
+
spec.homepage = "https://github.com/durableprogramming/durable-proxmox-ruby"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
spec.required_ruby_version = ">= 2.7.0"
|
|
16
|
+
|
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/durableprogramming/durable-proxmox-ruby"
|
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/durableprogramming/durable-proxmox-ruby/blob/main/CHANGELOG.md"
|
|
20
|
+
|
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
|
22
|
+
spec.files = Dir.chdir(__dir__) do
|
|
23
|
+
Dir.glob("{lib,exe}/**/*", File::FNM_DOTMATCH).reject do |f|
|
|
24
|
+
File.directory?(f)
|
|
25
|
+
end + %w[LICENSE README.md CHANGELOG.md durable-proxmox-ruby.gemspec]
|
|
26
|
+
end
|
|
27
|
+
spec.bindir = "exe"
|
|
28
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
29
|
+
spec.require_paths = ["lib"]
|
|
30
|
+
|
|
31
|
+
# Runtime dependencies
|
|
32
|
+
spec.add_dependency "faraday", "~> 2.0"
|
|
33
|
+
spec.add_dependency "json", "~> 2.0"
|
|
34
|
+
spec.add_dependency "dotenv", "~> 2.0"
|
|
35
|
+
spec.add_dependency "ipaddr", "~> 1.2"
|
|
36
|
+
|
|
37
|
+
# Development dependencies
|
|
38
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
|
39
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
|
40
|
+
spec.add_development_dependency "rubocop", "~> 1.0"
|
|
41
|
+
spec.add_development_dependency "yard", "~> 0.9"
|
|
42
|
+
spec.add_development_dependency "webmock", "~> 3.18"
|
|
43
|
+
spec.add_development_dependency "simplecov", "~> 0.22"
|
|
44
|
+
|
|
45
|
+
# For more information and examples about making a new gem, check out our
|
|
46
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
|
47
|
+
end
|