package pluginsdk import ( "context" "github.com/Nwflower/reims-go/pkg/pluginproto" ) // The VM methods a plugin may call on VMs the user authorized it for. Every // call is refused before it is sent unless the host advertised the method in // the handshake, so a plugin never depends on a host that cannot serve it. // ListVMs returns the VMs the host shows this plugin. func (s *Server) ListVMs(ctx context.Context) ([]pluginproto.VMView, error) { var res pluginproto.VMListResult if err := s.callFeature(ctx, "host/vm.list", nil, &res); err != nil { return nil, err } return res.VMs, nil } // GetVM reads one VM by name or by canonical driverID:name reference. func (s *Server) GetVM(ctx context.Context, vm string) (pluginproto.VMView, error) { var view pluginproto.VMView err := s.callFeature(ctx, "host/vm.get", pluginproto.VMParams{VM: vm}, &view) return view, err } // StartVM starts a VM. func (s *Server) StartVM(ctx context.Context, vm string) error { return s.callFeature(ctx, "host/vm.start", pluginproto.VMParams{VM: vm}, nil) } // ShutdownVM shuts a VM down, or stops it outright when force is set. func (s *Server) ShutdownVM(ctx context.Context, vm string, force bool) error { return s.callFeature(ctx, "host/vm.shutdown", pluginproto.VMShutdownParams{VM: vm, Force: force}, nil) } // SuspendVM suspends a VM. func (s *Server) SuspendVM(ctx context.Context, vm string) error { return s.callFeature(ctx, "host/vm.suspend", pluginproto.VMParams{VM: vm}, nil) } // ResumeVM resumes a VM. func (s *Server) ResumeVM(ctx context.Context, vm string) error { return s.callFeature(ctx, "host/vm.resume", pluginproto.VMParams{VM: vm}, nil) } // CloneVM clones a VM into a temporary VM this plugin owns. cloneName must // start with __agent- so the host can recognize and clean up the clone. func (s *Server) CloneVM(ctx context.Context, vm, cloneName string) (pluginproto.VMCloneResult, error) { var res pluginproto.VMCloneResult err := s.callFeature(ctx, "host/vm.clone", pluginproto.VMCloneParams{VM: vm, CloneName: cloneName}, &res) return res, err } // DeleteVM deletes a temporary VM this plugin owns. func (s *Server) DeleteVM(ctx context.Context, vm string) error { return s.callFeature(ctx, "host/vm.delete", pluginproto.VMParams{VM: vm}, nil) } // ListSnapshots lists a VM's snapshots. func (s *Server) ListSnapshots(ctx context.Context, vm string) ([]pluginproto.Snapshot, error) { var res pluginproto.SnapshotListResult if err := s.callFeature(ctx, "host/vm.snapshot.list", pluginproto.VMParams{VM: vm}, &res); err != nil { return nil, err } return res.Snapshots, nil } // CreateSnapshot creates a snapshot. func (s *Server) CreateSnapshot(ctx context.Context, vm, name string) error { return s.callFeature(ctx, "host/vm.snapshot.create", pluginproto.SnapshotNameParams{VM: vm, Name: name}, nil) } // RestoreSnapshot restores a snapshot of a temporary VM this plugin owns. func (s *Server) RestoreSnapshot(ctx context.Context, vm, name string) error { return s.callFeature(ctx, "host/vm.snapshot.restore", pluginproto.SnapshotNameParams{VM: vm, Name: name}, nil) }