github.com/cloud-foundations/dominator@v0.0.0-20221004181915-6e4fee580046/hypervisor/rpcd/api.go (about) 1 package rpcd 2 3 import ( 4 "io" 5 "net" 6 "sync" 7 8 "github.com/Cloud-Foundations/Dominator/hypervisor/manager" 9 "github.com/Cloud-Foundations/Dominator/lib/log" 10 "github.com/Cloud-Foundations/Dominator/lib/srpc" 11 proto "github.com/Cloud-Foundations/Dominator/proto/hypervisor" 12 ) 13 14 type DhcpServer interface { 15 AddLease(address proto.Address, hostname string) error 16 AddNetbootLease(address proto.Address, hostname string, 17 subnet *proto.Subnet) error 18 MakeAcknowledgmentChannel(ipAddr net.IP) <-chan struct{} 19 RemoveLease(ipAddr net.IP) 20 } 21 22 type ipv4Address [4]byte 23 24 type srpcType struct { 25 dhcpServer DhcpServer 26 logger log.DebugLogger 27 manager *manager.Manager 28 tftpbootServer TftpbootServer 29 mutex sync.Mutex // Protect everything below. 30 externalLeases map[ipv4Address]string // Value: MAC address. 31 manageExternalLeases bool 32 } 33 34 type TftpbootServer interface { 35 RegisterFiles(ipAddr net.IP, files map[string][]byte) 36 UnregisterFiles(ipAddr net.IP) 37 } 38 39 type htmlWriter srpcType 40 41 func (hw *htmlWriter) WriteHtml(writer io.Writer) { 42 hw.writeHtml(writer) 43 } 44 45 func Setup(manager *manager.Manager, dhcpServer DhcpServer, 46 tftpbootServer TftpbootServer, logger log.DebugLogger) ( 47 *htmlWriter, error) { 48 srpcObj := &srpcType{ 49 dhcpServer: dhcpServer, 50 logger: logger, 51 manager: manager, 52 tftpbootServer: tftpbootServer, 53 externalLeases: make(map[ipv4Address]string), 54 } 55 srpc.SetDefaultGrantMethod( 56 func(_ string, authInfo *srpc.AuthInformation) bool { 57 return manager.CheckOwnership(authInfo) 58 }) 59 srpc.RegisterNameWithOptions("Hypervisor", srpcObj, srpc.ReceiverOptions{ 60 PublicMethods: []string{ 61 "AcknowledgeVm", 62 "AddVmVolumes", 63 "BecomePrimaryVmOwner", 64 "ChangeVmConsoleType", 65 "ChangeVmDestroyProtection", 66 "ChangeVmOwnerUsers", 67 "ChangeVmSize", 68 "ChangeVmTags", 69 "CommitImportedVm", 70 "ConnectToVmConsole", 71 "ConnectToVmSerialPort", 72 "CopyVm", 73 "CreateVm", 74 "DeleteVmVolume", 75 "DestroyVm", 76 "DiscardVmAccessToken", 77 "DiscardVmOldImage", 78 "DiscardVmOldUserData", 79 "DiscardVmSnapshot", 80 "ExportLocalVm", 81 "GetRootCookiePath", 82 "GetUpdates", 83 "GetVmAccessToken", 84 "GetVmInfo", 85 "GetVmUserData", 86 "GetVmVolume", 87 "ImportLocalVm", 88 "ListSubnets", 89 "ListVMs", 90 "ListVolumeDirectories", 91 "MigrateVm", 92 "PatchVmImage", 93 "ProbeVmPort", 94 "ReplaceVmImage", 95 "ReplaceVmUserData", 96 "RestoreVmFromSnapshot", 97 "RestoreVmImage", 98 "RestoreVmUserData", 99 "ScanVmRoot", 100 "SnapshotVm", 101 "StartVm", 102 "StopVm", 103 "TraceVmMetadata", 104 }}) 105 return (*htmlWriter)(srpcObj), nil 106 }