client

package
v0.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 2, 2019 License: Apache-2.0 Imports: 7 Imported by: 1

README

client

Package client is a Go client for Ignite resources.

For example, to list running VMs (the equivalent of "ignite vm ls"), and update the VM with a new IP address:

package main
import (
    "context"
    "fmt"
    "net"
    "github.com/weaveworks/ignite/pkg/client"
)
func main() {
    // List VMs managed by Ignite
    vmList, err := client.VMs().List()
    if err != nil {
        panic(err)
    }
    for _, vm := range vmList {
        // Modify the object
        vm.Status.IPAddresses = append(vm.Status.IPAddresses, net.IP{127,0,0,1})
        // Save the new VM state
        if err := client.VMs().Set(vm); err != nil {
            panic(err)
        }
    }

    // Get a specific image, and print its size
    myImage, err := client.Images().Get("my-image")
    if err != nil {
        panic(err)
    }
    fmt.Printf("Image my-vm size: %s\n", myImage.Spec.Source.Size.String())

    // Use the dynamic client
    myVM, err := client.Dynamic("VM").Get("my-vm")
    if err != nil {
        panic(err)
    }
    fmt.Printf("VM my-vm cpus: %d\n", myVM.Spec.CPUs)
}

Documentation

Overview

Package client is a Go client for Ignite resources.

For example, to list running VMs (the equivalent of "ignite vm ls"), and update the VM with a new IP address:

package main
import (
	"context"
	"fmt"
	"net"
	"github.com/weaveworks/ignite/pkg/client"
)
func main() {
	// List VMs managed by Ignite
	vmList, err := client.VMs().List()
	if err != nil {
		panic(err)
	}
	for _, vm := range vmList {
		// Modify the object
		vm.Status.IPAddresses = append(vm.Status.IPAddresses, net.IP{127,0,0,1})
		// Save the new VM state
		if err := client.VMs().Set(vm); err != nil {
			panic(err)
		}
	}

	// Get a specific image, and print its size
	myImage, err := client.Images().Get("my-image")
	if err != nil {
		panic(err)
	}
	fmt.Printf("Image my-vm size: %s\n", myImage.Spec.Source.Size.String())

	// Use the dynamic client
	myVM, err := client.Dynamic("VM").Get("my-vm")
	if err != nil {
		panic(err)
	}
	fmt.Printf("VM my-vm cpus: %d\n", myVM.Spec.CPUs)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*IgniteInternalClient
}

Client is a struct providing high-level access to objects in a storage The resource-specific client interfaces are automatically generated based off client_resource_template.go. The auto-generation can be done with hack/client.sh At the moment IgniteInternalClient is the default client. If more than this client is created in the future, the IgniteInternalClient will be accessible under Client.IgniteInternal() instead.

func NewClient

func NewClient(s storage.Storage) *Client

NewClient creates a client for the specified storage

type DynamicClient

type DynamicClient interface {
	// New returns a new Object of its kind
	New() runtime.Object
	// Get returns an Object matching the UID from the storage
	Get(runtime.UID) (runtime.Object, error)
	// Set saves an Object into the persistent storage
	Set(runtime.Object) error
	// Patch performs a strategic merge patch on the object with
	// the given UID, using the byte-encoded patch given
	Patch(runtime.UID, []byte) error
	// Find returns an Object based on the given filter, filters can
	// match e.g. the Object's Name, UID or a specific property
	Find(filter filterer.BaseFilter) (runtime.Object, error)
	// FindAll returns multiple Objects based on the given filter, filters can
	// match e.g. the Object's Name, UID or a specific property
	FindAll(filter filterer.BaseFilter) ([]runtime.Object, error)
	// Delete deletes an Object from the storage
	Delete(uid runtime.UID) error
	// List returns a list of all Objects available
	List() ([]runtime.Object, error)
}

DynamicClient is an interface for accessing API types generically

type IgniteInternalClient added in v0.5.0

type IgniteInternalClient struct {
	// contains filtered or unexported fields
}

func NewIgniteInternalClient added in v0.5.0

func NewIgniteInternalClient(s storage.Storage) *IgniteInternalClient

func (*IgniteInternalClient) Dynamic added in v0.5.0

func (c *IgniteInternalClient) Dynamic(kind runtime.Kind) (dc DynamicClient)

Dynamic returns the DynamicClient for the Client instance, for the specific kind

func (*IgniteInternalClient) Images added in v0.5.0

func (c *IgniteInternalClient) Images() ImageClient

Images returns the ImageClient for the IgniteInternalClient instance

func (*IgniteInternalClient) Kernels added in v0.5.0

func (c *IgniteInternalClient) Kernels() KernelClient

Kernels returns the KernelClient for the IgniteInternalClient instance

func (*IgniteInternalClient) VMs added in v0.5.0

func (c *IgniteInternalClient) VMs() VMClient

VMs returns the VMClient for the IgniteInternalClient instance

type ImageClient

type ImageClient interface {
	// New returns a new Image
	New() *api.Image
	// Get returns the Image matching given UID from the storage
	Get(runtime.UID) (*api.Image, error)
	// Set saves the given Image into persistent storage
	Set(*api.Image) error
	// Patch performs a strategic merge patch on the object with
	// the given UID, using the byte-encoded patch given
	Patch(runtime.UID, []byte) error
	// Find returns the Image matching the given filter, filters can
	// match e.g. the Object's Name, UID or a specific property
	Find(filter filterer.BaseFilter) (*api.Image, error)
	// FindAll returns multiple Images matching the given filter, filters can
	// match e.g. the Object's Name, UID or a specific property
	FindAll(filter filterer.BaseFilter) ([]*api.Image, error)
	// Delete deletes the Image with the given UID from the storage
	Delete(uid runtime.UID) error
	// List returns a list of all Images available
	List() ([]*api.Image, error)
}

ImageClient is an interface for accessing Image-specific API objects

type KernelClient

type KernelClient interface {
	// New returns a new Kernel
	New() *api.Kernel
	// Get returns the Kernel matching given UID from the storage
	Get(runtime.UID) (*api.Kernel, error)
	// Set saves the given Kernel into persistent storage
	Set(*api.Kernel) error
	// Patch performs a strategic merge patch on the object with
	// the given UID, using the byte-encoded patch given
	Patch(runtime.UID, []byte) error
	// Find returns the Kernel matching the given filter, filters can
	// match e.g. the Object's Name, UID or a specific property
	Find(filter filterer.BaseFilter) (*api.Kernel, error)
	// FindAll returns multiple Kernels matching the given filter, filters can
	// match e.g. the Object's Name, UID or a specific property
	FindAll(filter filterer.BaseFilter) ([]*api.Kernel, error)
	// Delete deletes the Kernel with the given UID from the storage
	Delete(uid runtime.UID) error
	// List returns a list of all Kernels available
	List() ([]*api.Kernel, error)
}

KernelClient is an interface for accessing Kernel-specific API objects

type VMClient

type VMClient interface {
	// New returns a new VM
	New() *api.VM
	// Get returns the VM matching given UID from the storage
	Get(runtime.UID) (*api.VM, error)
	// Set saves the given VM into persistent storage
	Set(*api.VM) error
	// Patch performs a strategic merge patch on the object with
	// the given UID, using the byte-encoded patch given
	Patch(runtime.UID, []byte) error
	// Find returns the VM matching the given filter, filters can
	// match e.g. the Object's Name, UID or a specific property
	Find(filter filterer.BaseFilter) (*api.VM, error)
	// FindAll returns multiple VMs matching the given filter, filters can
	// match e.g. the Object's Name, UID or a specific property
	FindAll(filter filterer.BaseFilter) ([]*api.VM, error)
	// Delete deletes the VM with the given UID from the storage
	Delete(uid runtime.UID) error
	// List returns a list of all VMs available
	List() ([]*api.VM, error)
}

VMClient is an interface for accessing VM-specific API objects

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL