Browse Source

1.1.1 submit

dev v1.1.1
akumas 2 years ago
parent
commit
4ff04717cf
  1. 24
      CHANGELOG.md
  2. 4
      core_service.go
  3. 4
      core_transaction_manager.go
  4. 30
      daemon.go
  5. 30
      go.mod
  6. 37
      go.sum
  7. 3
      src/imageserver/go.mod
  8. 22
      src/imageserver/http_module.go
  9. 12
      src/imageserver/image_manager.go
  10. 2
      src/imageserver/query_disk_image.go
  11. 2
      src/imageserver/query_media_image.go
  12. 844
      src/modules/api_module.go
  13. 3
      src/modules/go.mod
  14. 6
      src/modules/instance.go
  15. 2
      src/modules/module_interface.go
  16. 155
      src/modules/resource_manager.go
  17. 18
      src/modules/restful_data.go
  18. 2
      src/task/add_address_range.go
  19. 2
      src/task/add_compute_cell.go
  20. 2
      src/task/create_address_pool.go
  21. 2
      src/task/create_compute_pool.go
  22. 2
      src/task/create_disk_image.go
  23. 6
      src/task/create_guest.go
  24. 2
      src/task/create_media_image.go
  25. 2
      src/task/create_migration.go
  26. 2
      src/task/create_snapshot.go
  27. 2
      src/task/create_storage_pool.go
  28. 2
      src/task/delete_address_pool.go
  29. 2
      src/task/delete_compute_pool.go
  30. 2
      src/task/delete_disk_image.go
  31. 2
      src/task/delete_guest.go
  32. 2
      src/task/delete_media_image.go
  33. 2
      src/task/delete_snapshot.go
  34. 2
      src/task/delete_storage_pool.go
  35. 2
      src/task/disable_compute_cell.go
  36. 2
      src/task/eject_media.go
  37. 2
      src/task/enable_compute_cell.go
  38. 2
      src/task/get_address_pool.go
  39. 2
      src/task/get_address_range.go
  40. 2
      src/task/get_auth.go
  41. 2
      src/task/get_batch_create_guest.go
  42. 2
      src/task/get_batch_delete_guest.go
  43. 2
      src/task/get_batch_stop_guest.go
  44. 2
      src/task/get_compute_cell.go
  45. 2
      src/task/get_compute_cell_status.go
  46. 2
      src/task/get_compute_pool.go
  47. 2
      src/task/get_compute_pool_status.go
  48. 2
      src/task/get_disk_image.go
  49. 2
      src/task/get_guest.go
  50. 2
      src/task/get_instance_status.go
  51. 2
      src/task/get_media_image.go
  52. 2
      src/task/get_migration.go
  53. 2
      src/task/get_snapshot.go
  54. 2
      src/task/get_storage_pool.go
  55. 3
      src/task/go.mod
  56. 2
      src/task/handle_address_changed.go
  57. 12
      src/task/handle_cell_available.go
  58. 2
      src/task/handle_cell_disconnected.go
  59. 2
      src/task/handle_cell_status_updated.go
  60. 28
      src/task/handle_guest_created.go
  61. 2
      src/task/handle_guest_deleted.go
  62. 2
      src/task/handle_guest_started.go
  63. 2
      src/task/handle_guest_stopped.go
  64. 2
      src/task/handle_guest_system_reset.go
  65. 2
      src/task/handle_guest_updated.go
  66. 2
      src/task/handle_instance_migrated.go
  67. 2
      src/task/handle_media_attached.go
  68. 2
      src/task/handle_media_detached.go
  69. 2
      src/task/insert_media.go
  70. 2
      src/task/modify_address_pool.go
  71. 2
      src/task/modify_auth.go
  72. 2
      src/task/modify_compute_pool.go
  73. 2
      src/task/modify_core.go
  74. 2
      src/task/modify_disk_image.go
  75. 2
      src/task/modify_guest_disk_threshold.go
  76. 2
      src/task/modify_guest_name.go
  77. 2
      src/task/modify_guest_network_threshold.go
  78. 2
      src/task/modify_guest_priority.go
  79. 2
      src/task/modify_media_image.go
  80. 2
      src/task/modify_memory.go
  81. 2
      src/task/modify_storage_pool.go
  82. 10
      src/task/query_address_pool.go
  83. 2
      src/task/query_address_range.go
  84. 2
      src/task/query_cells_by_pool.go
  85. 2
      src/task/query_compute_cell_status.go
  86. 2
      src/task/query_compute_pool.go
  87. 2
      src/task/query_compute_pool_status.go
  88. 2
      src/task/query_disk_image.go
  89. 2
      src/task/query_guest.go
  90. 2
      src/task/query_instance_status.go
  91. 2
      src/task/query_media_image.go
  92. 2
      src/task/query_migration.go
  93. 2
      src/task/query_snapshot.go
  94. 2
      src/task/query_storage_pool.go
  95. 2
      src/task/query_unallocated_cells.go
  96. 2
      src/task/query_zone_status.go
  97. 2
      src/task/remove_address_range.go
  98. 2
      src/task/remove_compute_cell.go
  99. 2
      src/task/reset_guest_system.go
  100. 2
      src/task/resize_guest_disk.go

24
CHANGELOG.md

@ -1,4 +1,28 @@
# Change Log
## [1.1.1] - 2020-01-01
### Added
- Add DNS to API '/address_pools/'(query address pool list)
- Add CreateTime/MAC address to instance/guest
### Fixed
- Search guest in an empty cell return a proper result
- Properly return a pending error of instance when get status
## [1.1.0] - 2019-11-05
### Added
- API signature verify
- Add go mod
### Changed
- Call core API via prefix '/api/v1/'
- Change "/media_image_files/:id" to "/media_images/:id/file/"
- Change "/disk_image_files/:id" to "/disk_images/:id/file/"
## [1.0.0] - 2019-07-02

4
core_service.go

@ -3,11 +3,11 @@ package main
import (
"github.com/project-nano/framework"
"log"
"modules"
"github.com/project-nano/core/modules"
)
const (
CurrentVersion = "1.0.0"
CurrentVersion = "1.1.1"
)
type CoreService struct {

4
core_transaction_manager.go

@ -2,8 +2,8 @@ package main
import (
"github.com/project-nano/framework"
"task"
"modules"
"github.com/project-nano/core/task"
"github.com/project-nano/core/modules"
"net/http"
"crypto/tls"
)

30
daemon.go

@ -1,26 +1,26 @@
package main
import (
"fmt"
"errors"
"encoding/json"
"path/filepath"
"os"
"log"
"github.com/project-nano/framework"
"io/ioutil"
"github.com/project-nano/sonar"
"modules"
"imageserver"
"crypto/rand"
"crypto/rsa"
"crypto/tls"
"crypto/x509"
"math/big"
"crypto/x509/pkix"
"time"
"crypto/rsa"
"encoding/json"
"encoding/pem"
"errors"
"fmt"
"github.com/project-nano/core/imageserver"
"github.com/project-nano/core/modules"
"github.com/project-nano/framework"
"github.com/project-nano/sonar"
"io/ioutil"
"log"
"math/big"
"net"
"crypto/rand"
"os"
"path/filepath"
"time"
)
type DomainConfig struct {

30
go.mod

@ -0,0 +1,30 @@
module github.com/project-nano/core
go 1.13
replace (
github.com/project-nano/core/imageserver => ./src/imageserver
github.com/project-nano/core/modules => ./src/modules
github.com/project-nano/core/task => ./src/task
)
require (
github.com/julienschmidt/httprouter v1.3.0 // indirect
github.com/klauspost/cpuid v1.2.1 // indirect
github.com/klauspost/reedsolomon v1.9.3 // indirect
github.com/pkg/errors v0.8.1 // indirect
github.com/project-nano/core/imageserver v0.0.0-00010101000000-000000000000
github.com/project-nano/core/modules v0.0.0-00010101000000-000000000000
github.com/project-nano/core/task v0.0.0-00010101000000-000000000000
github.com/project-nano/framework v1.0.1
github.com/project-nano/sonar v0.0.0-20190628085230-df7942628d6f
github.com/satori/go.uuid v1.2.0 // indirect
github.com/sevlyar/go-daemon v0.1.5 // indirect
github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161 // indirect
github.com/templexxx/xor v0.0.0-20181023030647-4e92f724b73b // indirect
github.com/tjfoc/gmsm v1.0.1 // indirect
github.com/xtaci/kcp-go v5.4.18+incompatible // indirect
golang.org/x/crypto v0.0.0-20191105034135-c7e5f84aec59 // indirect
golang.org/x/net v0.0.0-20191105084925-a882066a44e0 // indirect
golang.org/x/sys v0.0.0-20191105231009-c1f44814a5cd // indirect
)

37
go.sum

@ -0,0 +1,37 @@
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/klauspost/cpuid v1.2.1 h1:vJi+O/nMdFt0vqm8NZBI6wzALWdA2X+egi0ogNyrC/w=
github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/klauspost/reedsolomon v1.9.3 h1:N/VzgeMfHmLc+KHMD1UL/tNkfXAt8FnUqlgXGIduwAY=
github.com/klauspost/reedsolomon v1.9.3/go.mod h1:CwCi+NUr9pqSVktrkN+Ondf06rkhYZ/pcNv7fu+8Un4=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/project-nano/framework v0.0.0-20190628085503-2d531d8d83ea h1:N4QUSpjN0keic2cceXjRIJ87QsA2ucsJ/JpyK6npwt4=
github.com/project-nano/framework v0.0.0-20190628085503-2d531d8d83ea/go.mod h1:tlK/6uw7c0RfqW9es+nbqhCTlJchGmHcPjTdhNUUxXo=
github.com/project-nano/framework v1.0.1 h1:7UVdCNVMeb9D5wRRACV0SohljlXmcYYFT93cLvXSIR8=
github.com/project-nano/framework v1.0.1/go.mod h1:tlK/6uw7c0RfqW9es+nbqhCTlJchGmHcPjTdhNUUxXo=
github.com/project-nano/sonar v0.0.0-20190628085230-df7942628d6f h1:NorTDWkZl22V1v/2t0gG01ylSACOmjDmrGpN3R/Pbgg=
github.com/project-nano/sonar v0.0.0-20190628085230-df7942628d6f/go.mod h1:VYPy/Adnn0NLwbDfa/7vv12vWbftUqTHZzwt83Q5QAo=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sevlyar/go-daemon v0.1.5 h1:Zy/6jLbM8CfqJ4x4RPr7MJlSKt90f00kNM1D401C+Qk=
github.com/sevlyar/go-daemon v0.1.5/go.mod h1:6dJpPatBT9eUwM5VCw9Bt6CdX9Tk6UWvhW3MebLDRKE=
github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161 h1:89CEmDvlq/F7SJEOqkIdNDGJXrQIhuIx9D2DBXjavSU=
github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161/go.mod h1:wM7WEvslTq+iOEAMDLSzhVuOt5BRZ05WirO+b09GHQU=
github.com/templexxx/xor v0.0.0-20181023030647-4e92f724b73b h1:mnG1fcsIB1d/3vbkBak2MM0u+vhGhlQwpeimUi7QncM=
github.com/templexxx/xor v0.0.0-20181023030647-4e92f724b73b/go.mod h1:5XA7W9S6mni3h5uvOC75dA3m9CCCaS83lltmc0ukdi4=
github.com/tjfoc/gmsm v1.0.1 h1:R11HlqhXkDospckjZEihx9SW/2VW0RgdwrykyWMFOQU=
github.com/tjfoc/gmsm v1.0.1/go.mod h1:XxO4hdhhrzAd+G4CjDqaOkd0hUzmtPR/d3EiBBMn/wc=
github.com/xtaci/kcp-go v5.4.18+incompatible h1:zxzRP8V54vhJ8QAKEjf1b9g96R01prybCRchx6rEmtg=
github.com/xtaci/kcp-go v5.4.18+incompatible/go.mod h1:bN6vIwHQbfHaHtFpEssmWsN45a+AZwO7eyRCmEIbtvE=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191105034135-c7e5f84aec59 h1:PyXRxSVbvzDGuqYXjHndV7xDzJ7w2K8KD9Ef8GB7KOE=
golang.org/x/crypto v0.0.0-20191105034135-c7e5f84aec59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20191105084925-a882066a44e0 h1:QPlSTtPE2k6PZPasQUbzuK3p9JbS+vMXYVto8g/yrsg=
golang.org/x/net v0.0.0-20191105084925-a882066a44e0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191105231009-c1f44814a5cd h1:3x5uuvBgE6oaXJjCOvpCC1IpgJogqQ+PqGGU3ZxAgII=
golang.org/x/sys v0.0.0-20191105231009-c1f44814a5cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

3
src/imageserver/go.mod

@ -0,0 +1,3 @@
module github.com/project-nano/core/imageserver
go 1.13

22
src/imageserver/http_module.go

@ -44,6 +44,10 @@ type ImageServiceConfig struct {
KeyFile string `json:"key_file"`
}
const (
APIRoot = "/api"
APIVersion = 1
)
func CreateHttpModule(configPath, dataPath, host string, image *ImageManager) (module *HttpModule, err error) {
const (
ListenPortRangeBegin = 5801
@ -285,18 +289,20 @@ func (module *HttpModule) GetKeyFilePath() string{
return module.keyFile
}
func apiPath(path string) string{
return fmt.Sprintf("%s/v%d%s", APIRoot, APIVersion, path)
}
func (module *HttpModule) RegisterHandler(router *httprouter.Router){
router.HEAD("/media_image_files/:id", module.CheckMediaImageFile)
router.GET("/media_image_files/:id", module.DownloadMediaImageFile)
router.POST("/media_image_files/:id", module.UploadMediaImageFile)
router.HEAD(apiPath("/media_images/:id/file/"), module.CheckMediaImageFile)
router.GET(apiPath("/media_images/:id/file/"), module.DownloadMediaImageFile)
router.POST(apiPath("/media_images/:id/file/"), module.UploadMediaImageFile)
router.HEAD("/disk_image_files/:id", module.CheckDiskImageFile)
router.GET("/disk_image_files/:id", module.ReadDiskImageFile)
router.PUT("/disk_image_files/:id", module.WriteDiskImageFile)
router.POST("/disk_image_files/:id", module.uploadDiskImageFile)//upload form
router.HEAD(apiPath("/disk_images/:id/file/"), module.CheckDiskImageFile)
router.GET(apiPath("/disk_images/:id/file/"), module.ReadDiskImageFile)
router.PUT(apiPath("/disk_images/:id/file/"), module.WriteDiskImageFile)
router.POST(apiPath("/disk_images/:id/file/"), module.uploadDiskImageFile)//upload form
}
func (module *HttpModule) UploadMediaImageFile(w http.ResponseWriter, r *http.Request, params httprouter.Params){

12
src/imageserver/image_manager.go

@ -437,11 +437,7 @@ func (manager *ImageManager) handleCreateMediaImage(config MediaConfig, respChan
respChan <- ImageResult{Error:err}
return
}
newID, err := uuid.NewV4()
if err != nil{
respChan <- ImageResult{Error:err}
return err
}
var newID = uuid.NewV4()
var image = MediaStatus{}
image.MediaConfig = config
image.ID = newID.String()
@ -699,11 +695,7 @@ func (manager *ImageManager) handleCreateDiskImage(config DiskConfig, respChan c
respChan <- ImageResult{Error:err}
return
}
newID, err := uuid.NewV4()
if err != nil{
respChan <- ImageResult{Error:err}
return err
}
var newID = uuid.NewV4()
var image = DiskStatus{}
image.DiskConfig = config

2
src/imageserver/query_disk_image.go

@ -69,7 +69,7 @@ func (executor *QueryDiskImageExecutor)Execute(id framework.SessionID, request f
resp.SetUIntArray(framework.ParamKeyCount, tagCount)
resp.SetUIntArray(framework.ParamKeyStatus, created)
resp.SetUIntArray(framework.ParamKeyProgress, progress)
log.Printf("[%08X] query disk image success, %d image(s) available", id, len(result.DiskList))
//log.Printf("[%08X] query disk image success, %d image(s) available", id, len(result.DiskList))
return executor.Sender.SendMessage(resp, request.GetSender())
}

2
src/imageserver/query_media_image.go

@ -60,7 +60,7 @@ func (executor *QueryMediaImageExecutor)Execute(id framework.SessionID, request
resp.SetUIntArray(framework.ParamKeySize, size)
resp.SetUIntArray(framework.ParamKeyCount, tagCount)
log.Printf("[%08X] query media image success, %d image(s) available", id, len(result.MediaList))
//log.Printf("[%08X] query media image success, %d image(s) available", id, len(result.MediaList))
return executor.Sender.SendMessage(resp, request.GetSender())
}

844
src/modules/api_module.go
File diff suppressed because it is too large
View File

3
src/modules/go.mod

@ -0,0 +1,3 @@
module github.com/project-nano/core/modules
go 1.13

6
src/modules/instance.go

@ -50,6 +50,7 @@ type InstanceStatus struct {
MonitorProtocol string
MonitorSecret string
CreateTime string
HardwareAddress string
CPUPriority PriorityEnum
WriteSpeed uint64
WriteIOPS uint64
@ -91,7 +92,7 @@ const (
func MarshalInstanceStatusListToMessage(list []InstanceStatus, msg framework.Message) error {
var count = uint(len(list))
msg.SetUInt(framework.ParamKeyCount, count)
var names, ids, pools, cells, users, monitors, addresses, groups, secrets, systems, createTime, internal, external []string
var names, ids, pools, cells, users, monitors, addresses, groups, secrets, systems, createTime, internal, external, hardware []string
var cores, options, enables, progress, status, memories, disks, diskCounts, mediaAttached, cpuPriorities, ioLimits []uint64
for _, ins := range list {
names = append(names, ins.Name)
@ -142,6 +143,7 @@ func MarshalInstanceStatusListToMessage(list []InstanceStatus, msg framework.Mes
systems = append(systems, ins.System)
createTime = append(createTime, ins.CreateTime)
hardware = append(hardware, ins.HardwareAddress)
memories = append(memories, uint64(ins.Memory))
var diskCount = len(ins.Disks)
diskCounts = append(diskCounts, uint64(diskCount))
@ -167,6 +169,7 @@ func MarshalInstanceStatusListToMessage(list []InstanceStatus, msg framework.Mes
msg.SetStringArray(framework.ParamKeyCreate, createTime)
msg.SetStringArray(framework.ParamKeyInternal, internal)
msg.SetStringArray(framework.ParamKeyExternal, external)
msg.SetStringArray(framework.ParamKeyHardware, hardware)
msg.SetStringArray(framework.ParamKeyGroup, groups)
msg.SetUIntArray(framework.ParamKeyCore, cores)
@ -219,6 +222,7 @@ func (config *InstanceStatus) Marshal(msg framework.Message) error {
msg.SetString(framework.ParamKeySecret, config.MonitorSecret)
msg.SetString(framework.ParamKeySystem, config.System)
msg.SetString(framework.ParamKeyCreate, config.CreateTime)
msg.SetString(framework.ParamKeyHardware, config.HardwareAddress)
var internalMonitor = fmt.Sprintf("%s:%d", config.InternalNetwork.MonitorAddress, config.InternalNetwork.MonitorPort)
var externalMonitor = fmt.Sprintf("%s:%d", config.ExternalNetwork.MonitorAddress, config.ExternalNetwork.MonitorPort)
msg.SetStringArray(framework.ParamKeyMonitor, []string{internalMonitor, externalMonitor})

2
src/modules/module_interface.go

@ -314,7 +314,7 @@ type ResourceModule interface {
AllocateInstance(pool string, status InstanceStatus, respChan chan ResourceResult)
//running/create/progress/media only
UpdateInstanceStatus(status InstanceStatus, respChan chan error)
ConfirmInstance(id string, monitorPort uint, monitorSecret string, respChan chan error)
ConfirmInstance(id string, monitorPort uint, monitorSecret, ethernetAddress string, respChan chan error)
DeallocateInstance(id string, err error, respChan chan error)
GetInstanceStatus(id string, respChan chan ResourceResult)

155
src/modules/resource_manager.go

@ -1,22 +1,22 @@
package modules
import (
"time"
"log"
"fmt"
"path/filepath"
"os"
"io/ioutil"
"encoding/json"
"errors"
"github.com/satori/go.uuid"
"sort"
"net"
"bytes"
"math/rand"
"encoding/binary"
"encoding/json"
"errors"
"fmt"
"github.com/project-nano/framework"
uuid "github.com/satori/go.uuid"
"io/ioutil"
"log"
"math/rand"
"net"
"os"
"path/filepath"
"regexp"
"sort"
"time"
)
//config file define
@ -153,38 +153,39 @@ type ResourceManager struct {
type resourceCommand struct {
DiskImageConfig
MigrationParameter
Type commandType
Pool string
Cell string
Address string
Range string
Start string
Instance string
ConfigList []InstanceStatus
Config InstanceStatus
Condition GuestQueryCondition
MonitorPort uint
Name string
Host string
Port int
Group string
Tags []string
Progress uint
Size uint64
Image string
Secret string
Storage string
StorageType string
Target string
Migration string
Error error
Failover bool
IDList []string
PortList []uint64
DiskImages []DiskImageStatus
Type commandType
Pool string
Cell string
Address string
Range string
Start string
Instance string
Hardware string
ConfigList []InstanceStatus
Config InstanceStatus
Condition GuestQueryCondition
MonitorPort uint
Name string
Host string
Port int
Group string
Tags []string
Progress uint
Size uint64
Image string
Secret string
Storage string
StorageType string
Target string
Migration string
Error error
Failover bool
IDList []string
PortList []uint64
DiskImages []DiskImageStatus
AddressPoolConfig
AddressRangeConfig
Batch string
Batch string
BatchCreateRequest
Priority PriorityEnum
ReadSpeed uint64
@ -477,8 +478,8 @@ func (manager *ResourceManager) UpdateInstanceStatus(status InstanceStatus, resp
cmd := resourceCommand{Type: cmdUpdateInstanceStatus, Config: status, ErrorChan: respChan}
manager.commands <- cmd
}
func (manager *ResourceManager) ConfirmInstance(id string, monitor uint, secret string, respChan chan error) {
cmd := resourceCommand{Type: cmdConfirmInstance, Instance: id, MonitorPort: monitor, Secret:secret, ErrorChan: respChan}
func (manager *ResourceManager) ConfirmInstance(id string, monitor uint, secret, ethernetAddress string, respChan chan error) {
cmd := resourceCommand{Type: cmdConfirmInstance, Instance: id, MonitorPort: monitor, Secret:secret, Hardware: ethernetAddress, ErrorChan: respChan}
manager.commands <- cmd
}
@ -914,7 +915,7 @@ func (manager *ResourceManager) handleCommand(cmd resourceCommand) {
case cmdAllocateInstance:
err = manager.handleAllocateInstance(cmd.Pool, cmd.Config, cmd.ResultChan)
case cmdConfirmInstance:
err = manager.handleConfirmInstance(cmd.Instance, cmd.MonitorPort, cmd.Secret, cmd.ErrorChan)
err = manager.handleConfirmInstance(cmd.Instance, cmd.MonitorPort, cmd.Secret, cmd.Hardware, cmd.ErrorChan)
case cmdDeallocateInstance:
err = manager.handleDeallocateInstance(cmd.Instance, cmd.Error, cmd.ErrorChan)
case cmdUpdateInstanceStatus:
@ -1785,9 +1786,6 @@ func (manager *ResourceManager) handleSearchGuestConfig(condition GuestQueryCond
err := fmt.Errorf("invalid cell '%s'", condition.Cell)
respChan <- ResourceResult{Error:err}
return err
} else if 0 == len(cell.Instances) {
respChan <- ResourceResult{}
return fmt.Errorf("no instance available in cell '%s'", condition.Cell)
} else {
for id, _ := range cell.Instances {
idList = append(idList, id)
@ -1926,12 +1924,7 @@ func (manager *ResourceManager) handleAllocateInstance(poolName string, config I
respChan <- ResourceResult{Error: err}
return err
}
newID, err := uuid.NewV4()
if err != nil {
log.Printf("<resource_manager> generate new uuid fail: %s", err.Error())
respChan <- ResourceResult{Error: err}
return err
}
var newID = uuid.NewV4()
config.ID = newID.String()
cellName, err := manager.selectCell(poolName, config.InstanceResource, true)
if err != nil {
@ -2028,7 +2021,7 @@ func (manager *ResourceManager) handleUpdateInstanceStatus(status InstanceStatus
return nil
}
func (manager *ResourceManager) handleConfirmInstance(id string, monitorPort uint, monitorSecret string, respChan chan error) error {
func (manager *ResourceManager) handleConfirmInstance(id string, monitorPort uint, monitorSecret, ethernetAddress string, respChan chan error) error {
status, exists := manager.instances[id]
if !exists {
err := fmt.Errorf("invalid instance '%s'", id)
@ -2052,6 +2045,7 @@ func (manager *ResourceManager) handleConfirmInstance(id string, monitorPort uin
status.InternalNetwork.MonitorPort = monitorPort
status.MonitorSecret = monitorSecret
status.HardwareAddress = ethernetAddress
status.Created = true
status.Progress = 0
status.CreateTime = time.Now().Format(TimeFormatLayout)
@ -2113,20 +2107,22 @@ func (manager *ResourceManager) handleDeallocateInstance(id string, err error, r
return nil
}
func (manager *ResourceManager) handleGetInstanceStatus(id string, respChan chan ResourceResult) error {
if status, exists := manager.instances[id]; !exists {
var err error
if err, exists = manager.pendingError[id]; exists{
//fetch pending error
delete(manager.pendingError, id)
}else{
err = fmt.Errorf("invalid instance '%s'", id)
}
func (manager *ResourceManager) handleGetInstanceStatus(id string, respChan chan ResourceResult) (err error) {
var exists bool
var status InstanceStatus
if err, exists = manager.pendingError[id]; exists{
//fetch pending error
delete(manager.pendingError, id)
respChan <- ResourceResult{Error: err}
return err
} else {
log.Printf("<resource_manager> pending error of instance '%s' fetched", id)
return nil
}else if status, exists = manager.instances[id]; exists{
respChan <- ResourceResult{InstanceStatus: status}
return nil
}else{
err = fmt.Errorf("invalid instance '%s'", id)
respChan <- ResourceResult{Error: err}
return err
}
}
@ -2486,11 +2482,7 @@ func (manager *ResourceManager) handleCreateMigration(params MigrationParameter,
respChan <- ResourceResult{Error:err}
return err
}
newID, err := uuid.NewV4()
if err != nil{
respChan <- ResourceResult{Error:err}
return err
}
var newID = uuid.NewV4()
var M = MigrationStatus{}
M.ID = newID.String()
M.SourcePool = params.SourcePool
@ -3130,12 +3122,7 @@ func (manager *ResourceManager) handleStartBatchCreateGuest(request BatchCreateR
respChan <- ResourceResult{Error: err}
return err
}
newID, err := uuid.NewV4()
if err != nil{
respChan <- ResourceResult{Error: err}
return err
}
var newID = uuid.NewV4()
var task BatchCreateGuestTask
task.Finished = false
task.StartTime = time.Now()
@ -3236,12 +3223,7 @@ func (manager *ResourceManager) handleStartBatchDeleteGuest(id []string, respCha
respChan <- ResourceResult{Error:err}
return err
}
newID, err := uuid.NewV4()
if err != nil{
respChan <- ResourceResult{Error: err}
return err
}
var newID = uuid.NewV4()
var task BatchDeleteGuestTask
task.Finished = false
task.StartTime = time.Now()
@ -3341,12 +3323,7 @@ func (manager *ResourceManager) handleStartBatchStopGuest(id []string, respChan
respChan <- ResourceResult{Error:err}
return err
}
newID, err := uuid.NewV4()
if err != nil{
respChan <- ResourceResult{Error: err}
return err
}
var newID = uuid.NewV4()
var task BatchStopGuestTask
task.Finished = false
task.StartTime = time.Now()

18
src/modules/restful_data.go

@ -69,11 +69,12 @@ const (
func UnmarshalGuestConfigListFromMessage(msg framework.Message) (result []restGuestConfig, err error) {
result = make([]restGuestConfig, 0)
count, err := msg.GetUInt(framework.ParamKeyCount)
if err != nil{
return result, err
}
var names, ids, pools, cells, users, groups, monitors, addresses, systems, createTime, internal, external []string
var names, ids, pools, cells, users, groups, monitors, addresses, systems, createTime, internal, external, hardware []string
var cores, options, enables, progress, status, memories, disks, diskCounts, mediaAttached, cpuPriorities, ioLimits []uint64
if pools, err = msg.GetStringArray(framework.ParamKeyPool); err != nil {
return result, err
@ -105,7 +106,9 @@ func UnmarshalGuestConfigListFromMessage(msg framework.Message) (result []restGu
if external, err = msg.GetStringArray(framework.ParamKeyExternal); err != nil {
return result, err
}
if hardware, err = msg.GetStringArray(framework.ParamKeyHardware); err != nil {
return
}
if cores, err = msg.GetUIntArray(framework.ParamKeyCore); err != nil {
return result, err
}
@ -168,8 +171,6 @@ func UnmarshalGuestConfigListFromMessage(msg framework.Message) (result []restGu
return
}
var guests []restGuestConfig
var diskOffset = 0
for i := 0; i < int(count);i++{
var config restGuestConfig
@ -209,6 +210,7 @@ func UnmarshalGuestConfigListFromMessage(msg framework.Message) (result []restGu
}
config.System = systems[i]
config.CreateTime = createTime[i]
config.EthernetAddress = hardware[i]
switch PriorityEnum(cpuPriorities[i]) {
case PriorityHigh:
config.QoS = restInstanceQoS{CPUPriority: priority_label_high}
@ -226,9 +228,9 @@ func UnmarshalGuestConfigListFromMessage(msg framework.Message) (result []restGu
config.QoS.WriteIOPS = ioLimits[ ValidLimitParametersCount * i + WriteIOPSOffset ]
config.QoS.ReceiveSpeed = ioLimits[ ValidLimitParametersCount * i + ReceiveOffset ]
config.QoS.SendSpeed = ioLimits[ ValidLimitParametersCount * i + SendOffset ]
guests = append(guests, config)
result = append(result, config)
}
return guests, nil
return result, nil
}
func (config *restGuestConfig) Unmarshal(msg framework.Message) (err error) {
@ -320,7 +322,9 @@ func (config *restGuestConfig) Unmarshal(msg framework.Message) (err error) {
if createTime, err := msg.GetString(framework.ParamKeyCreate); err == nil{
config.CreateTime = createTime
}
if hardware, err := msg.GetString(framework.ParamKeyHardware); err == nil{
config.EthernetAddress = hardware
}
if id, err := msg.GetString(framework.ParamKeyInstance);err == nil{
config.ID = id
}

2
src/task/add_address_range.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
)

2
src/task/add_compute_cell.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
"time"
)

2
src/task/create_address_pool.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
)

2
src/task/create_compute_pool.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
"fmt"
)

2
src/task/create_disk_image.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
"fmt"
"net/http"

6
src/task/create_guest.go

@ -4,7 +4,7 @@ import (
"github.com/project-nano/framework"
"log"
"time"
"modules"
"github.com/project-nano/core/modules"
"net/http"
"fmt"
"strconv"
@ -250,10 +250,10 @@ func (executor *CreateGuestExecutor)CancelResource(id string) error{
func (executor *CreateGuestExecutor) getImageSize(id, host string, port int) (size uint64, err error){
const (
Protocol = "https"
Resource = "disk_image_files"
Resource = "disk_images"
LengthHeaderName = "Content-Length"
)
var fileURL = fmt.Sprintf("%s://%s:%d/%s/%s", Protocol, host, port, Resource, id)
var fileURL = fmt.Sprintf("%s://%s:%d/%s/%s/file/", Protocol, host, port, Resource, id)
resp, err := executor.Client.Head(fileURL)
if err != nil{
return

2
src/task/create_media_image.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
"time"
)

2
src/task/create_migration.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"fmt"
"log"
"time"

2
src/task/create_snapshot.go

@ -4,7 +4,7 @@ import (
"github.com/project-nano/framework"
"log"
"time"
"modules"
"github.com/project-nano/core/modules"
"fmt"
)

2
src/task/create_storage_pool.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
"fmt"
)

2
src/task/delete_address_pool.go

@ -3,7 +3,7 @@ package task
import (
"github.com/project-nano/framework"
"log"
"modules"
"github.com/project-nano/core/modules"
)
type DeleteAddressPoolExecutor struct {

2
src/task/delete_compute_pool.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
)

2
src/task/delete_disk_image.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
"time"
)

2
src/task/delete_guest.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
"time"
"fmt"

2
src/task/delete_media_image.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
"time"
)

2
src/task/delete_snapshot.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
"time"
"fmt"

2
src/task/delete_storage_pool.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
)

2
src/task/disable_compute_cell.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
)

2
src/task/eject_media.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
"fmt"
"time"

2
src/task/enable_compute_cell.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
)

2
src/task/get_address_pool.go

@ -3,7 +3,7 @@ package task
import (
"log"
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
)
type GetAddressPoolExecutor struct {

2
src/task/get_address_range.go

@ -1,7 +1,7 @@
package task
import (
"modules"
"github.com/project-nano/core/modules"
"github.com/project-nano/framework"
"log"
)

2
src/task/get_auth.go

@ -4,7 +4,7 @@ import (
"github.com/project-nano/framework"
"log"
"time"
"modules"
"github.com/project-nano/core/modules"
)
type GetGuestPasswordExecutor struct {

2
src/task/get_batch_create_guest.go

@ -1,7 +1,7 @@
package task
import (
"modules"
"github.com/project-nano/core/modules"
"log"
"github.com/project-nano/framework"
)

2
src/task/get_batch_delete_guest.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
)

2
src/task/get_batch_stop_guest.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
)

2
src/task/get_compute_cell.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
"fmt"
"time"

2
src/task/get_compute_cell_status.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
)

2
src/task/get_compute_pool.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
)

2
src/task/get_compute_pool_status.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
)

2
src/task/get_disk_image.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
"time"
)

2
src/task/get_guest.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
)

2
src/task/get_instance_status.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
"time"
"fmt"

2
src/task/get_media_image.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
"time"
)

2
src/task/get_migration.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
)

2
src/task/get_snapshot.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
"time"
"fmt"

2
src/task/get_storage_pool.go

@ -1,7 +1,7 @@
package task
import (
"modules"
"github.com/project-nano/core/modules"
"github.com/project-nano/framework"
"log"
)

3
src/task/go.mod

@ -0,0 +1,3 @@
module github.com/project-nano/core/task
go 1.13

2
src/task/handle_address_changed.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
)

12
src/task/handle_cell_available.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
"time"
"fmt"
@ -166,7 +166,7 @@ func (executor *HandleCellAvailableExecutor)Execute(id framework.SessionID, requ
log.Printf("[%08X] no instance available in cell '%s'", id, cellName)
}else {
var names, ids, users, groups, secrets, addresses, systems, internal, external []string
var names, ids, users, groups, secrets, addresses, systems, internal, external, createTime, hardware []string
var cores, options, enables, progress, status, monitors, memories, disks, diskCounts, cpuPriorities, ioLimits []uint64
if names, err = cellResp.GetStringArray(framework.ParamKeyName); err != nil {
return err
@ -195,6 +195,12 @@ func (executor *HandleCellAvailableExecutor)Execute(id framework.SessionID, requ
if external, err = cellResp.GetStringArray(framework.ParamKeyExternal); err != nil{
return err
}
if createTime, err = cellResp.GetStringArray(framework.ParamKeyCreate); err != nil{
return err
}
if hardware, err = cellResp.GetStringArray(framework.ParamKeyHardware); err != nil{
return err
}
if cores, err = cellResp.GetUIntArray(framework.ParamKeyCore); err != nil {
return err
@ -276,6 +282,8 @@ func (executor *HandleCellAvailableExecutor)Execute(id framework.SessionID, requ
config.InternalNetwork.InstanceAddress = addresses[i]
config.InternalNetwork.AssignedAddress = internal[i]
config.ExternalNetwork.AssignedAddress = external[i]
config.CreateTime = createTime[i]
config.HardwareAddress = hardware[i]
config.CPUPriority = modules.PriorityEnum(cpuPriorities[i])
config.ReadSpeed = ioLimits[ ValidLimitParametersCount * i + ReadSpeedOffset ]
config.WriteSpeed = ioLimits[ ValidLimitParametersCount * i + WriteSpeedOffset ]

2
src/task/handle_cell_disconnected.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
)

2
src/task/handle_cell_status_updated.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
)

28
src/task/handle_guest_created.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
)
@ -12,21 +12,27 @@ type HandleGuestCreatedExecutor struct {
}
func (executor *HandleGuestCreatedExecutor)Execute(id framework.SessionID, event framework.Message,
incoming chan framework.Message, terminate chan bool) error {
instanceID, err := event.GetString(framework.ParamKeyInstance)
if err != nil {
return err
incoming chan framework.Message, terminate chan bool) (err error) {
var instanceID, monitorSecret, ethernet string
var monitorPort uint
if instanceID, err = event.GetString(framework.ParamKeyInstance); err != nil {
return
}
monitorPort, err := event.GetUInt(framework.ParamKeyMonitor)
if err != nil{
return err
if monitorPort, err = event.GetUInt(framework.ParamKeyMonitor); err != nil{
return
}
if monitorSecret, err = event.GetString(framework.ParamKeySecret); err != nil{
return
}
if ethernet, err = event.GetString(framework.ParamKeyHardware); err != nil{
return
}
var monitorSecret = ""
monitorSecret, _ = event.GetString(framework.ParamKeySecret)
log.Printf("[%08X] recv guest '%s' created from %s.[%08X], monitor port %d", id, instanceID,
event.GetSender(), event.GetFromSession(), monitorPort)
var respChan = make(chan error)
executor.ResourceModule.ConfirmInstance(instanceID, monitorPort, monitorSecret, respChan)
executor.ResourceModule.ConfirmInstance(instanceID, monitorPort, monitorSecret, ethernet, respChan)
err = <- respChan
if err != nil{
log.Printf("[%08X] confirm instance fail: %s", id, err.Error())

2
src/task/handle_guest_deleted.go

@ -3,7 +3,7 @@ package task
import (
"github.com/project-nano/framework"
"log"
"modules"
"github.com/project-nano/core/modules"
)
type HandleGuestDeletedExecutor struct {

2
src/task/handle_guest_started.go

@ -3,7 +3,7 @@ package task
import (
"github.com/project-nano/framework"
"log"
"modules"
"github.com/project-nano/core/modules"
)
type HandleGuestStartedExecutor struct {

2
src/task/handle_guest_stopped.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
)

2
src/task/handle_guest_system_reset.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
"errors"
)

2
src/task/handle_guest_updated.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
"errors"
)

2
src/task/handle_instance_migrated.go

@ -2,7 +2,7 @@ package task
import (
"github.com/project-nano/framework"
"modules"
"github.com/project-nano/core/modules"
"log"
)

2