Add boot image management with ISO extraction and serving
Upload Proxmox ISOs via API or dashboard UI, extract kernel+initrd using pure-Go iso9660 library, store on disk, and serve over HTTP for PXE booting. Dynamic kernel/initrd filenames per image replace the previous hardcoded paths. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -93,6 +93,34 @@ func (s *Images) SetDefault(ctx context.Context, id int64) error {
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
func (s *Images) GetByName(ctx context.Context, name string) (*model.Image, error) {
|
||||
row := s.DB.QueryRowContext(ctx, `SELECT id, name, kind, version, kernel_path, initrd_path, is_default, created_at FROM images WHERE name = ?`, name)
|
||||
var img model.Image
|
||||
var isDefault int
|
||||
var createdAt string
|
||||
if err := row.Scan(&img.ID, &img.Name, &img.Kind, &img.Version, &img.KernelPath, &img.InitrdPath, &isDefault, &createdAt); err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, ErrNotFound
|
||||
}
|
||||
return nil, fmt.Errorf("get image by name: %w", err)
|
||||
}
|
||||
img.IsDefault = isDefault == 1
|
||||
img.CreatedAt, _ = time.Parse(time.RFC3339, createdAt)
|
||||
return &img, nil
|
||||
}
|
||||
|
||||
func (s *Images) Delete(ctx context.Context, id int64) error {
|
||||
res, err := s.DB.ExecContext(ctx, `DELETE FROM images WHERE id = ?`, id)
|
||||
if err != nil {
|
||||
return fmt.Errorf("delete image: %w", err)
|
||||
}
|
||||
n, _ := res.RowsAffected()
|
||||
if n == 0 {
|
||||
return ErrNotFound
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func boolToInt(b bool) int {
|
||||
if b {
|
||||
return 1
|
||||
|
||||
Reference in New Issue
Block a user