Skip to content

WIP - Feature/v2 initial modules rest client #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Mar 17, 2025

Conversation

iButcat
Copy link
Member

@iButcat iButcat commented Mar 10, 2025

Xen Orchestra Go SDK v2 - REST API Implementation

Overview

This PR introduces v2 of our Xen Orchestra Go SDK, moving from JSON-RPC to REST API. This is a major improvement to our codebase.

Key Features

  • VM Management Operations:
    • Create VMs (with async task handling)
    • List all VMs
    • Get VM details by ID
    • Manage VM lifecycle (start, stop, reboot, etc.)
    • MockGen headers for interfaces

Design Improvements

The v2 implementation brings several important benefits:

  • UUID Type Support: Add package to switch from a string ID to UUID
  • Type Safety: Uses Go generics for type-safe API calls
  • Less Code: Generic functions (TypedGet, TypedPost) remove repetitive code
  • Clean Interfaces: library package has clear interfaces for easy testing
  • Better API: Method chaining (client.VM().Create() instead of client.CreateVM())
  • Context Support: All operations handle context for timeouts
  • Better Logging: Structured logging with dev/prod settings

Implementation Notes

  • Service Naming: The term "service" works well in our SDK context, even though it might have other meanings in different architectures

  • Payload vs. Model: We use "payloads" to show their API communication role, though they also act as data models

  • Task Polling: Currently, async task polling is in the VM service for quick development. Later, we'll move it to its own interface for better separation

Usage Example

// Initialize client with config
config := config.New()
client, _ := v2.New(config)

// List all VMs
vms, _ := client.VM().List(ctx)

// Get VM by ID
vmID := uuid.Must(uuid.FromString("70ad8a24-f51d-5cea-3423-72efd7a8716a"))
vm, _ := client.VM().GetByID(ctx, vmID)

// Create a new VM
newVM := &payloads.VM{
    NameLabel:       "test-vm",
    NameDescription: "Created via Go SDK",
    Template:        templateID,
}
createdVM, _ := client.VM().Create(ctx, newVM)

This PR shows that our v2 approach works well and is cleaner than v1. We'll add more services using this pattern in future PRs.

working-vm-created-sdk

@gCyrille gCyrille changed the title Feature/v2 initial modules rest client WIP - Feature/v2 initial modules rest client Mar 11, 2025
Copy link
Collaborator

@gCyrille gCyrille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great PR. Thanks :)

@iButcat
Copy link
Member Author

iButcat commented Mar 11, 2025

Great PR. Thanks :)

Welcome and thank you ! Sorry it's a bit long to review :(

Copy link
Collaborator

@gCyrille gCyrille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great update and nice documentation!

@gCyrille gCyrille self-requested a review March 17, 2025 10:13
Copy link
Collaborator

@gCyrille gCyrille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :-)

@iButcat iButcat merged commit 1b137a2 into main Mar 17, 2025
3 checks passed
@iButcat iButcat deleted the feature/v2-initial-modules-rest-client branch March 18, 2025 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants