Commit bcf6c6f5 authored by duanjinfei's avatar duanjinfei

optimization nps map network

parent 3d73495b
package asyncLog package asyncLog
import ( import (
"errors"
"fmt" "fmt"
"github.com/astaxie/beego" "github.com/astaxie/beego"
"github.com/astaxie/beego/logs" "github.com/astaxie/beego/logs"
...@@ -11,11 +12,11 @@ import ( ...@@ -11,11 +12,11 @@ import (
"github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/ethclient"
"hashrateNode/cache" "hashrateNode/cache"
hashrateCommon "hashrateNode/common" hashrateCommon "hashrateNode/common"
"hashrateNode/commonApi"
vm "hashrateNode/contract/VmContract" vm "hashrateNode/contract/VmContract"
vmCreate "hashrateNode/contract/VmCreateContract" vmCreate "hashrateNode/contract/VmCreateContract"
"hashrateNode/log" "hashrateNode/log"
"hashrateNode/models" "hashrateNode/models"
"hashrateNode/pveApi"
"hashrateNode/utils" "hashrateNode/utils"
"math/big" "math/big"
"strconv" "strconv"
...@@ -24,9 +25,9 @@ import ( ...@@ -24,9 +25,9 @@ import (
) )
var tranOpts *bind.TransactOpts var tranOpts *bind.TransactOpts
var err error var hostName, fromAddr, vncDefaultPort, sshDefaultPort string
var hostName, fromAddr string
var nonce uint64 var nonce uint64
var err error
func init() { func init() {
tranOpts, err = utils.GetTranOpts() tranOpts, err = utils.GetTranOpts()
...@@ -36,6 +37,8 @@ func init() { ...@@ -36,6 +37,8 @@ func init() {
} }
hostName = beego.AppConfig.String("pve::host_name") hostName = beego.AppConfig.String("pve::host_name")
fromAddr = beego.AppConfig.String("sendTranAddress") fromAddr = beego.AppConfig.String("sendTranAddress")
vncDefaultPort = beego.AppConfig.String("vncDefaultPort")
sshDefaultPort = beego.AppConfig.String("vncDefaultPort")
} }
func VmCreateContractHandler(vLog types.Log) error { func VmCreateContractHandler(vLog types.Log) error {
...@@ -62,12 +65,17 @@ func VmCreateContractHandler(vLog types.Log) error { ...@@ -62,12 +65,17 @@ func VmCreateContractHandler(vLog types.Log) error {
GpuNum: gpuNum, GpuNum: gpuNum,
Memory: memory, Memory: memory,
OsType: rp[9].(string), OsType: rp[9].(string),
Disk: bighundred, Disk: bigHundred,
Name: rp[10].(string),
} }
//vmCreateEvent := &models.VmConfig{} //vmCreateEvent := &models.VmConfig{}
//err = stakeAbiInfo.UnpackIntoInterface(vmCreateEvent, "AddCreateVMInfoEvent", vLog.Data) //err = stakeAbiInfo.UnpackIntoInterface(vmCreateEvent, "AddCreateVMInfoEvent", vLog.Data)
if err != nil { if err != nil {
cache.Redis.LpushByte(hashrateCommon.EventList, utils.Marshal(vmCreateEvent)) err := cache.Redis.LpushByte(hashrateCommon.EventList, utils.Marshal(vmCreateEvent))
if err != nil {
log.Error("cache redis lPush Byte error:", err.Error())
return err
}
} }
if !IsCreateVmCondition(vmCreateEvent.CallerIp) { if !IsCreateVmCondition(vmCreateEvent.CallerIp) {
return nil return nil
...@@ -105,7 +113,7 @@ func snatchTask(vmCfg *models.VmConfig) (bool, error) { ...@@ -105,7 +113,7 @@ func snatchTask(vmCfg *models.VmConfig) (bool, error) {
if err != nil { if err != nil {
return false, err return false, err
} }
vmCreate, err := vmCreate.NewVmCreate(common.HexToAddress(hashrateCommon.VmCreateContract), client) vmCreateInstance, err := vmCreate.NewVmCreate(common.HexToAddress(hashrateCommon.VmCreateContract), client)
if err != nil { if err != nil {
log.Error("New vmCreate error:", err) log.Error("New vmCreate error:", err)
return false, err return false, err
...@@ -113,130 +121,150 @@ func snatchTask(vmCfg *models.VmConfig) (bool, error) { ...@@ -113,130 +121,150 @@ func snatchTask(vmCfg *models.VmConfig) (bool, error) {
// 查询 创建vm的操作系统对应的vmId // 查询 创建vm的操作系统对应的vmId
updateTranOptsNonce(0) updateTranOptsNonce(0)
// 调用合约抢占任务 // 调用合约抢占任务
task, err := vmCreate.SnatchTask(tranOpts, vmCfg.TaskId, vmCfg.Owner) task, err := vmCreateInstance.SnatchTask(tranOpts, vmCfg.TaskId, vmCfg.Owner)
if err != nil { if err != nil {
log.Error("SnatchTask error:", err) log.Error("SnatchTask error:", err)
return false, err return false, err
} }
log.Info("SnatchTask success:", task.Hash()) log.Info("SnatchTask success:", task.Hash())
ticket, err := pveApi.GetCreateVmTicket() ticket, err := commonApi.GetCreateVmTicket()
if err != nil { if err != nil {
return false, err return false, err
} }
vmId, newId := getCloneVmInfo(vmCfg, ticket) vmId, newId, supportType := getCloneVmInfo(vmCfg.OsType, ticket)
if vmId == "" || newId == "" { if vmId == "" || newId == "" {
return false, nil return false, nil
} }
user, password := generateUser() user, password := generateUser()
vm := &models.VM{ vmInfo := &models.VM{
VmId: vmId, VmId: vmId,
NewId: newId, NewId: newId,
VmCfg: vmCfg, VmCfg: vmCfg,
Name: fmt.Sprintf("Clone%s", newId), SupportType: supportType,
User: user, User: user,
Password: password, Password: password,
HeaderInfo: ticket, HeaderInfo: ticket,
} }
updateTranOptsNonce(1) updateTranOptsNonce(1)
updateVmProgress(vmCreate, vm.VmCfg.TaskId, big.NewInt(1), bigTwenty) updateVmProgress(vmCreateInstance, vmInfo.VmCfg.TaskId, big.NewInt(1), bigTwenty)
// 创建VM、并且设置配置 // 创建VM、并且设置配置
_, err = pveApi.CreateVm(vm) _, err = commonApi.CreateVm(vmInfo)
if err != nil { if err != nil {
log.Error("Create vm error:", err.Error())
return false, err return false, err
} }
setRes, err := pveApi.SetVmConfig(vm) setRes, err := commonApi.SetVmConfig(vmInfo)
if err != nil || setRes == nil { if err != nil || setRes == nil {
log.Error("Set vm config error:", err.Error())
return false, err return false, err
} }
updateTranOptsNonce(1) updateTranOptsNonce(1)
updateVmProgress(vmCreate, vm.VmCfg.TaskId, big.NewInt(2), bigThirty) updateVmProgress(vmCreateInstance, vmInfo.VmCfg.TaskId, big.NewInt(2), bigThirty)
// 开启虚拟机 // 开启虚拟机
_, err = pveApi.StartVm(vm) _, err = commonApi.StartVm(vmInfo)
if err != nil { if err != nil {
log.Error("Start vm error:", err.Error())
return false, err return false, err
} }
updateTranOptsNonce(1) updateTranOptsNonce(1)
updateVmProgress(vmCreate, vm.VmCfg.TaskId, big.NewInt(3), bigForty) updateVmProgress(vmCreateInstance, vmInfo.VmCfg.TaskId, big.NewInt(3), bigForty)
// 轮训查询状态 // 轮训查询状态
for { for {
vmStatus, err := pveApi.VmStatus(vm) vmStatus, err := commonApi.VmStatus(vmInfo)
if err != nil { if err != nil {
return false, err return false, err
} }
if vmStatus.Status == hashrateCommon.Running { if vmStatus.Status == hashrateCommon.Running {
updateTranOptsNonce(1) updateTranOptsNonce(1)
updateVmProgress(vmCreate, vm.VmCfg.TaskId, big.NewInt(4), bigSixty) updateVmProgress(vmCreateInstance, vmInfo.VmCfg.TaskId, big.NewInt(4), bigFifty)
break break
} }
time.Sleep(time.Second * 2) time.Sleep(time.Second * 2)
} }
time.Sleep(time.Second * 20) time.Sleep(time.Second * 60)
netWorks, err := pveApi.GetVmNetWork(vm) netWorks, err := commonApi.GetVmNetWork(vmInfo)
if err != nil { if err != nil {
log.Error("Get vm net work info error:", err.Error())
return false, err return false, err
} }
updateTranOptsNonce(1)
updateVmProgress(vmCreateInstance, vmInfo.VmCfg.TaskId, big.NewInt(5), bigEighty)
//loginUser, err := pveApi.SetVmLoginUser(vm) _, err = commonApi.SetVmLoginUser(vmInfo)
//if err != nil { if err != nil {
// return false, err log.Error("Set vm login user error:", err.Error())
//} return false, err
}
updateTranOptsNonce(1)
updateVmProgress(vmCreateInstance, vmInfo.VmCfg.TaskId, big.NewInt(5), bigNinety)
updateVmNetWorkInfo(client, netWorks, vm) updateRes, err := updateVmNetWorkInfo(client, netWorks, vmInfo)
updateVmProgress(vmCreate, vm.VmCfg.TaskId, big.NewInt(5), bighundred) if err != nil {
log.Error("update vm net work info error", err.Error())
return updateRes, err
}
updateTranOptsNonce(1)
updateVmProgress(vmCreateInstance, vmInfo.VmCfg.TaskId, big.NewInt(5), bigHundred)
return true, nil return true, nil
} }
// updateVmNetWorkInfo 更新vm的网络信息 // updateVmNetWorkInfo 更新vm的网络信息
func updateVmNetWorkInfo(client *ethclient.Client, networkInfos []*models.NetworkInfo, vmInfo *models.VM) { func updateVmNetWorkInfo(client *ethclient.Client, networkInfos []*models.NetworkInfo, vmInfo *models.VM) (bool, error) {
internalIp := "" internalIp := ""
for _, netWork := range networkInfos { for _, netWork := range networkInfos {
if netWork.Name == hashrateCommon.Ens18 { //if netWork.Name == hashrateCommon.Ens18 {
for _, ipInfo := range netWork.IpAddresses { for _, ipInfo := range netWork.IpAddresses {
if ipInfo.IpAddressType == hashrateCommon.Ipv4 { if ipInfo.IpAddressType == hashrateCommon.Ipv4 && ipInfo.IpAddress != hashrateCommon.LocalHost {
internalIp = ipInfo.IpAddress internalIp = ipInfo.IpAddress
log.Info("internalIp:", internalIp) log.Info("internalIp:", internalIp)
break break
} }
} }
} //}
} }
if internalIp == "" { if internalIp == "" {
log.Error("In networkInfo is not found ip info") log.Error("In networkInfo is not found ip info")
return return false, errors.New("internalIp is not found")
} }
vmContract, err := vm.NewVm(common.HexToAddress(hashrateCommon.VmContract), client) vmContract, err := vm.NewVm(common.HexToAddress(hashrateCommon.VmContract), client)
if err != nil { if err != nil {
return log.Error("NewVm failed", err.Error())
return false, err
} }
// 调用NPS 映射外网ip // 调用NPS 映射外网ip
externalIp := internalIp vmNetWorkInfo := npsMappingNetwork(internalIp, vmInfo.SupportType)
externalPort := "22" if vmNetWorkInfo == nil {
log.Error("npsMappingNetwork is failed")
return false, errors.New("vmNetWorkInfo is not found")
}
vmId := new(big.Int) vmId := new(big.Int)
vmId.SetString(vmInfo.NewId, 10) vmId.SetString(vmInfo.NewId, 10)
updateTranOptsNonce(1) updateTranOptsNonce(1)
addVirtualMachine, err := vmContract.AddVirtualMachine(tranOpts, vmInfo.VmCfg.Owner, vmInfo.VmCfg.TaskId, vmId, "", vmInfo.VmCfg.TaskId, hostName, vmInfo.Name, "ubuntu") addVirtualMachine, err := vmContract.AddVirtualMachine(tranOpts, vmInfo.VmCfg.Owner, vmId, "", "", hostName, vmInfo.VmCfg.Name, vmInfo.VmCfg.OsType)
if err != nil { if err != nil {
return log.Error("addVirtualMachine failed", err.Error())
return false, err
} }
log.Info("Add virtual machine success:", addVirtualMachine.Hash()) log.Info("Add virtual machine success:", addVirtualMachine.Hash())
updateTranOptsNonce(1) updateTranOptsNonce(1)
updateVmNetworkInfo, err := vmContract.UpdateVmNetworkInfo(tranOpts, vmId, vmNetWorkInfo.InternalIp, vmNetWorkInfo.ExternalIp, vmNetWorkInfo.ExSshPort, vmNetWorkInfo.ExVncPort, strconv.FormatInt(vmNetWorkInfo.InSshPort, 10), strconv.FormatInt(vmNetWorkInfo.InVncPort, 10))
updateVmNetworkInfo, err := vmContract.UpdateVmNetworkInfo(tranOpts, vmId, "", externalIp, externalPort, "", "", "")
if err != nil { if err != nil {
return log.Error("Update virtual machine", err.Error())
return false, err
} }
log.Info("Update virtual machine networkInfo success:", updateVmNetworkInfo.Hash()) log.Info("Update virtual machine networkInfo success:", updateVmNetworkInfo.Hash())
updateTranOptsNonce(1) updateTranOptsNonce(1)
updateVMInfoEvent, err := vmContract.UpdateVMInfoEvent(tranOpts, vmId, vmInfo.VmCfg.Sockets.Uint64(), vmInfo.VmCfg.Memory.Uint64(), vmInfo.VmCfg.GpuNum.Uint64(), vmInfo.VmCfg.Disk) updateVMInfoEvent, err := vmContract.UpdateVmInfo(tranOpts, vmId, vmInfo.VmCfg.Sockets.Uint64(), vmInfo.VmCfg.Memory.Uint64(), vmInfo.VmCfg.GpuNum.Uint64(), vmInfo.VmCfg.Disk)
if err != nil { if err != nil {
return log.Error("Update vm info", err.Error())
return false, err
} }
log.Info("Update virtual machine info success:", updateVMInfoEvent.Hash()) log.Info("Update virtual machine info success:", updateVMInfoEvent.Hash())
...@@ -244,29 +272,139 @@ func updateVmNetWorkInfo(client *ethclient.Client, networkInfos []*models.Networ ...@@ -244,29 +272,139 @@ func updateVmNetWorkInfo(client *ethclient.Client, networkInfos []*models.Networ
userTran, err := vmContract.AddVmUser(tranOpts, vmId, vmInfo.User, vmInfo.Password) userTran, err := vmContract.AddVmUser(tranOpts, vmId, vmInfo.User, vmInfo.Password)
if err != nil { if err != nil {
log.Error("Add vm user error:", err) log.Error("Add vm user error:", err)
return return false, err
} }
log.Info("Update virtual machine info success:", userTran.Hash()) log.Info("Update virtual machine info success:", userTran.Hash())
return true, nil
} }
func npsMappingNetwork(internalIp string, supportType int) *models.VmNetWork {
// 获取本机的外网Ip
externalIp := getExternalIp()
// 获取可用的客户端
clientList := commonApi.GetClientList()
if len(clientList) == 0 {
addClient()
return nil
}
tunnelModel := &models.AddTunnelRequest{
Type: "tcp",
}
for _, clientInfo := range clientList {
if clientInfo.Status && clientInfo.IsConnect {
tunnelModel.ClientId = strconv.FormatInt(clientInfo.Id, 10)
break
}
}
vmNetWorkInfo := &models.VmNetWork{
InternalIp: internalIp,
InSshPort: hashrateCommon.DefaultSshPort,
InVncPort: hashrateCommon.DefaultVncPort,
ExternalIp: externalIp,
SupportType: int64(supportType),
}
unUsePort := getUnUsePort(tunnelModel.ClientId)
tunnelModel.Port = strconv.FormatInt(unUsePort, 10)
if supportType == hashrateCommon.VmSupportConnectVnc {
tunnelModel.Target = fmt.Sprintf("%s:%s", internalIp, vncDefaultPort)
vmNetWorkInfo.ExVncPort = tunnelModel.Port
} else if supportType == hashrateCommon.VmSupportConnectSsh {
tunnelModel.Target = fmt.Sprintf("%s:%s", internalIp, sshDefaultPort)
vmNetWorkInfo.ExSshPort = tunnelModel.Port
}
if supportType == hashrateCommon.VmSupportConnectAll {
// 处理SSH端口
tunnelModel.Target = fmt.Sprintf("%s:%s", internalIp, sshDefaultPort)
addRes := commonApi.AddTunnel(tunnelModel)
if addRes.Status == hashrateCommon.NpsReqFailedStatus {
log.Error("Add ssh tunnel failed error msg:", addRes.Msg)
return nil
}
vmNetWorkInfo.ExSshPort = tunnelModel.Port
// 处理VNC端口
tunnelModel.Port = strconv.FormatInt(unUsePort+1, 10)
tunnelModel.Target = fmt.Sprintf("%s:%s", internalIp, vncDefaultPort)
addRes = commonApi.AddTunnel(tunnelModel)
if addRes.Status == hashrateCommon.NpsReqFailedStatus {
log.Error("Add vnc tunnel failed error msg:", addRes.Msg)
return nil
}
vmNetWorkInfo.ExVncPort = tunnelModel.Port
} else {
addRes := commonApi.AddTunnel(tunnelModel)
if addRes.Status == hashrateCommon.NpsReqFailedStatus {
log.Error("Add tunnel failed error msg:", addRes.Msg)
return nil
}
}
return vmNetWorkInfo
}
func addClient() {
}
func getUnUsePort(clientId string) int64 {
tunnelList := commonApi.GetTunnel(clientId)
var maxPort int64
for _, tunnel := range tunnelList {
if tunnel.Port > maxPort {
maxPort = tunnel.Port
}
}
return maxPort + 1
}
func getExternalIp() string {
externalIp := beego.AppConfig.String("nps::api_host")
if externalIp == "" {
// todo 如果本机没有host 外网ip、则需要通过查找网关进行分配外网ip
return externalIp
}
return externalIp
}
// 生成用户
func generateUser() (string, string) { func generateUser() (string, string) {
return "cloud", "123456" return "wuban", "2023!@#WSX#@!"
} }
// getCloneVmInfo 获取能够克隆的vmId // getCloneVmInfo 获取能够克隆的vmId
func getCloneVmInfo(vmInfo *models.VmConfig, headerInfo *models.HeaderInfo) (string, string) { func getCloneVmInfo(osType string, headerInfo *models.HeaderInfo) (string, string, int) {
qemuList, err := pveApi.GetQemuList(headerInfo) qemuList, err := commonApi.GetQemuList(headerInfo)
if err != nil { if err != nil {
return "", "" log.Error("Get qemu list error:", err.Error())
return "", "", 0
} }
var maxVmId int64 var maxVmId int64
supportType := 0
var cloneId string
for _, qemu := range qemuList { for _, qemu := range qemuList {
if qemu.VmId > maxVmId { if qemu.VmId > maxVmId {
maxVmId = qemu.VmId maxVmId = qemu.VmId
} }
if qemu.Template == 1 {
templateInfo := strings.Split(qemu.Name, hashrateCommon.SplitSupportType)
osNameTem := templateInfo[0]
versionTem := templateInfo[1]
supportTypeTem := templateInfo[2]
supportType, err = strconv.Atoi(supportTypeTem)
if err != nil {
log.Error("strconv os support type type error:", err.Error())
return "", "", 0
}
osInfo := strings.Split(osType, hashrateCommon.SplitSupportType)
osNameReq := osInfo[0]
versionReq := osInfo[1]
if osNameReq == osNameTem && versionTem == versionReq {
cloneId = strconv.FormatInt(qemu.VmId, 10)
}
}
} }
maxVmId++ maxVmId++
return "100", strconv.FormatInt(maxVmId, 10) return cloneId, strconv.FormatInt(maxVmId, 10), supportType
} }
// updateVmProgress 更新vm的创建进度 // updateVmProgress 更新vm的创建进度
...@@ -280,6 +418,7 @@ func updateVmProgress(contractInstance *vmCreate.VmCreate, taskId string, stage ...@@ -280,6 +418,7 @@ func updateVmProgress(contractInstance *vmCreate.VmCreate, taskId string, stage
return true return true
} }
// updateTranOptsNonce 更新Nonce
func updateTranOptsNonce(incrementNum uint64) { func updateTranOptsNonce(incrementNum uint64) {
nonce += incrementNum nonce += incrementNum
nonceUint64 := new(big.Int).SetUint64(nonce) nonceUint64 := new(big.Int).SetUint64(nonce)
......
...@@ -32,7 +32,7 @@ var ( ...@@ -32,7 +32,7 @@ var (
bigSeventy = big.NewInt(70) bigSeventy = big.NewInt(70)
bigEighty = big.NewInt(80) bigEighty = big.NewInt(80)
bigNinety = big.NewInt(90) bigNinety = big.NewInt(90)
bighundred = big.NewInt(100) bigHundred = big.NewInt(100)
bigK = big.NewInt(1000) bigK = big.NewInt(1000)
) )
...@@ -49,7 +49,7 @@ type PullEvent struct { ...@@ -49,7 +49,7 @@ type PullEvent struct {
func init() { func init() {
var err error var err error
rpc := beego.AppConfig.String("chain_rpc_url") rpc := beego.AppConfig.String("chain_rpc_url")
deployBlock := beego.AppConfig.String("deployedBlock") deployedBlock := beego.AppConfig.String("deployedBlock")
log.Info("connect chain rpc url:", rpc) log.Info("connect chain rpc url:", rpc)
pullTask = &PullEvent{contractHandler: make(map[common.Address]logHandler)} pullTask = &PullEvent{contractHandler: make(map[common.Address]logHandler)}
client, err := ethclient.Dial(rpc) client, err := ethclient.Dial(rpc)
...@@ -59,7 +59,7 @@ func init() { ...@@ -59,7 +59,7 @@ func init() {
pullTask.client = client pullTask.client = client
lastBlock := cache.Redis.Get(LastSyncBlockKey) lastBlock := cache.Redis.Get(LastSyncBlockKey)
if len(lastBlock) == 0 { if len(lastBlock) == 0 {
lastBlock = deployBlock lastBlock = deployedBlock
} }
blockNumber, _ := new(big.Int).SetString(lastBlock, 10) blockNumber, _ := new(big.Int).SetString(lastBlock, 10)
pullTask.lastBlock = blockNumber pullTask.lastBlock = blockNumber
...@@ -97,7 +97,7 @@ func (p *PullEvent) GetLogs() { ...@@ -97,7 +97,7 @@ func (p *PullEvent) GetLogs() {
} else if height > 1000 && (height-1000) >= p.lastBlock.Uint64() { } else if height > 1000 && (height-1000) >= p.lastBlock.Uint64() {
query.ToBlock = new(big.Int).Add(p.lastBlock, bigK) query.ToBlock = new(big.Int).Add(p.lastBlock, bigK)
} else if height > 100 && (height-100) >= p.lastBlock.Uint64() { } else if height > 100 && (height-100) >= p.lastBlock.Uint64() {
query.ToBlock = new(big.Int).Add(p.lastBlock, bighundred) query.ToBlock = new(big.Int).Add(p.lastBlock, bigHundred)
} else if height > 10 && (height-10) >= p.lastBlock.Uint64() { } else if height > 10 && (height-10) >= p.lastBlock.Uint64() {
query.ToBlock = new(big.Int).Add(p.lastBlock, bigTen) query.ToBlock = new(big.Int).Add(p.lastBlock, bigTen)
} else { } else {
...@@ -113,12 +113,20 @@ func (p *PullEvent) GetLogs() { ...@@ -113,12 +113,20 @@ func (p *PullEvent) GetLogs() {
for _, vlog := range allLogs { for _, vlog := range allLogs {
handle, exist := p.contractHandler[vlog.Address] handle, exist := p.contractHandler[vlog.Address]
if exist { if exist {
handle(vlog) err := handle(vlog)
if err != nil {
log.Error("handle logs failed", err)
return
}
} }
} }
} }
p.lastBlock = new(big.Int).Add(query.ToBlock, bigOne) p.lastBlock = new(big.Int).Add(query.ToBlock, bigOne)
cache.Redis.Set(LastSyncBlockKey, p.lastBlock.Text(10)) err = cache.Redis.Set(LastSyncBlockKey, p.lastBlock.Text(10))
if err != nil {
log.Error("set last sync block failed", err)
return
}
} }
} }
......
...@@ -7,4 +7,12 @@ const ( ...@@ -7,4 +7,12 @@ const (
Ipv4 = "ipv4" Ipv4 = "ipv4"
Ipv6 = "ipv6" Ipv6 = "ipv6"
SuccessCode = 200 SuccessCode = 200
LocalHost = "127.0.0.1"
DefaultSshPort = 22
DefaultVncPort = 5900
NpsReqFailedStatus int64 = 0
SplitSupportType = "-"
VmSupportConnectVnc = 1
VmSupportConnectSsh = 2
VmSupportConnectAll = 3
) )
...@@ -6,12 +6,11 @@ const ( ...@@ -6,12 +6,11 @@ const (
// VmCreateEvent 虚拟机创建事件 // VmCreateEvent 虚拟机创建事件
const ( const (
VmCreateEvent = "0x7d25d4d054c4e119d70f7f809edd27dfdff08e176a4a4a3f25e7e7ad63d3398e" VmCreateEvent = "0x14cfc769ae51024fff38f2bdd079158750cf8a7676da49060b89e554166c9a2d"
) )
// VmCreateContract 虚拟机创建合约 // VmCreateContract 虚拟机创建合约
const ( const (
VmContract = "0x72C20a56980Ab01e994B810cd8f177609c179Ce8" VmContract = "0x5Ea6719343d035A6695054278c087D7a971CA802"
VmCreateContract = "0xAea46B15eF82be16ef33994Febd6475C073a8b89" VmCreateContract = "0x94186f71FD90486b65aC318ed6C08D4d78042307"
//VmCreateContract = "0xCE80565919c846F87328bFA54bC7443aC07C7fFE"
) )
package common
const (
NpsGetAuthKeyAPI = "/auth/getauthkey"
NpsGetTimeAPI = "/auth/gettime"
NpsGetClientList = "/client/list"
NpsAddTunnel = "/index/add/"
NpsGetTunnel = "/index/gettunnel"
)
package commonApi
import (
"bytes"
"encoding/json"
"fmt"
"github.com/astaxie/beego"
"github.com/mitchellh/mapstructure"
hashrateCommon "hashrateNode/common"
"hashrateNode/log"
"hashrateNode/models"
"hashrateNode/utils"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"strconv"
)
var npsApi string
var lastRequestAuthKeyTime int64
var authKey string
var timeStamp int64
func init() {
npsApi = fmt.Sprintf("http://%s%s%s", beego.AppConfig.String("nps::api_host"), ":", beego.AppConfig.String("nps::api_port"))
}
func GetClientList() []*models.NpsClientInfo {
getClientListApi := npsApi + hashrateCommon.NpsGetClientList
formData := make(map[string]interface{})
formData["start"] = "0"
formData["limit"] = "10"
formData["order"] = "asc"
request, res, err := sendNpsPostRequest(getClientListApi, formData)
if err != nil || !request {
log.Error("Nps send get client list req err:", err.Error())
return nil
}
npsClientArr := make([]*models.NpsClientInfo, 0)
marshal, err := json.Marshal(res["rows"])
if err != nil {
log.Error("GetClientList json marshal error:", err.Error())
return nil
}
err = json.Unmarshal(marshal, &npsClientArr)
if err != nil {
log.Error("GetClientList json Unmarshal error:", err.Error())
return nil
}
return npsClientArr
}
func GetTunnel(clientId string) []*models.TcpTunnelInfo {
getTunnelsApi := npsApi + hashrateCommon.NpsGetTunnel
formData := make(map[string]interface{})
formData["client_id"] = clientId
formData["type"] = "tcp"
formData["offset"] = "0"
formData["limit"] = "10"
formData["order"] = "asc"
request, resMap, err := sendNpsPostRequest(getTunnelsApi, formData)
if !request || err != nil {
log.Errorf("Nps AddTunnel error, error:%s", err.Error())
return nil
}
res := make([]*models.TcpTunnelInfo, 0)
tunnelList, err := json.Marshal(resMap["rows"])
if err != nil {
log.Error("GetTunnel json marshal error:", err.Error())
return nil
}
err = json.Unmarshal(tunnelList, &res)
if err != nil {
log.Error("GetTunnel json unmarshal error:", err.Error())
return nil
}
return res
}
func AddTunnel(tunnelRequest *models.AddTunnelRequest) *models.NpsOperateResp {
addTunnelApi := npsApi + hashrateCommon.NpsAddTunnel
mapReq := make(map[string]interface{})
marshal, err := json.Marshal(tunnelRequest)
if err != nil {
return nil
}
err = json.Unmarshal(marshal, &mapReq)
if err != nil {
return nil
}
request, resMap, err := sendNpsPostRequest(addTunnelApi, mapReq)
if !request || err != nil {
log.Errorf("Nps AddTunnel error, isSuccess:%s error:%s", request, err.Error())
return nil
}
res := &models.NpsOperateResp{}
err = mapstructure.Decode(resMap, res)
if err != nil {
log.Errorf("Nps AddTunnel mapStructure decode error:", err.Error())
return nil
}
return res
}
func getAuthKey() (string, int64) {
nowTimestampUri := npsApi + hashrateCommon.NpsGetTimeAPI
authKeyUri := npsApi + hashrateCommon.NpsGetAuthKeyAPI
isSuccess, res, err := sendNpsPostRequest(nowTimestampUri, nil)
if err != nil || !isSuccess {
return "", 0
}
timeStruct := &models.UnixTime{}
marshalTimeStruct, err := json.Marshal(res)
if err != nil {
return "", 0
}
err = json.Unmarshal(marshalTimeStruct, timeStruct)
if err != nil {
return "", 0
}
isSuccess, res, err = sendNpsPostRequest(authKeyUri, nil)
if err != nil || !isSuccess {
return "", 0
}
authKeyStruct := &models.AuthKey{}
marshalAuthKeyStruct, err := json.Marshal(res)
if err != nil {
return "", 0
}
err = json.Unmarshal(marshalAuthKeyStruct, authKeyStruct)
if err != nil {
return "", 0
}
return utils.GetAuthKey(authKeyStruct.CryptAuthKey, timeStruct.Timestamp), timeStruct.Timestamp
}
func sendNpsPostRequest(uri string, formData map[string]interface{}) (bool, map[string]interface{}, error) {
payload := &bytes.Buffer{}
writer := multipart.NewWriter(payload)
if formData != nil {
for key, value := range formData {
if strValue, ok := value.(string); ok {
_ = writer.WriteField(key, strValue)
}
}
authKey, timeStamp = getAuthKey()
if authKey == "" || timeStamp == 0 {
return false, nil, nil
}
_ = writer.WriteField("auth_key", authKey)
_ = writer.WriteField("timestamp", strconv.FormatInt(timeStamp, 10))
lastRequestAuthKeyTime = timeStamp
log.Info("Get auth key timestamp:", lastRequestAuthKeyTime)
}
err := writer.Close()
if err != nil {
fmt.Println("Error closing writer:", err)
return false, nil, err
}
request, err := http.NewRequest("POST", uri, payload)
request.Header.Set("Content-Type", writer.FormDataContentType())
if err != nil {
log.Error("Nps api new request error:", err.Error())
return false, nil, nil
}
resp, err := client.Do(request)
if err != nil {
log.Errorf("Nps api send post request uri:%s , error:%s", uri, err.Error())
return false, nil, nil
}
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
log.Error("Nps api close body error:", err.Error())
return
}
}(resp.Body)
if resp.StatusCode != hashrateCommon.SuccessCode {
log.Error("Nps api Send post request failed:", resp.Status)
return false, nil, nil
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return false, nil, err
}
var res map[string]interface{}
err = json.Unmarshal(body, &res)
if err != nil {
log.Error("Nps api unmarshal resp error:", err.Error())
return false, nil, err
}
return true, res, nil
}
package pveApi package commonApi
import ( import (
"bytes" "bytes"
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
hashrateCommon "hashrateNode/common" hashrateCommon "hashrateNode/common"
"hashrateNode/log" "hashrateNode/log"
"hashrateNode/models" "hashrateNode/models"
"io"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
...@@ -23,9 +24,9 @@ func init() { ...@@ -23,9 +24,9 @@ func init() {
port := beego.AppConfig.String("pve::port") port := beego.AppConfig.String("pve::port")
path := beego.AppConfig.String("pve::ticket_api") path := beego.AppConfig.String("pve::ticket_api")
hostName = beego.AppConfig.String("pve::host_name") hostName = beego.AppConfig.String("pve::host_name")
url := "https://" + ip + ":" + port pveUrl := "https://" + ip + ":" + port
pveNodesPrefixApi = url + beego.AppConfig.String("pve::nodes_api") + fmt.Sprintf("/%s/qemu", hostName) pveNodesPrefixApi = pveUrl + beego.AppConfig.String("pve::nodes_api") + fmt.Sprintf("/%s/qemu", hostName)
pveTicketApi = url + path pveTicketApi = pveUrl + path
tr := &http.Transport{ tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // 忽略 SSL 证书错误 TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // 忽略 SSL 证书错误
} }
...@@ -37,7 +38,7 @@ func GetCreateVmTicket() (*models.HeaderInfo, error) { ...@@ -37,7 +38,7 @@ func GetCreateVmTicket() (*models.HeaderInfo, error) {
data := url.Values{} data := url.Values{}
data.Set("username", beego.AppConfig.String("pve::user")) data.Set("username", beego.AppConfig.String("pve::user"))
data.Set("password", beego.AppConfig.String("pve::pass")) data.Set("password", beego.AppConfig.String("pve::pass"))
isSuccess, _, result, err := sendPostForm(pveTicketApi, data, nil) isSuccess, _, result, err := sendPvePostForm(pveTicketApi, data, nil)
if err != nil || !isSuccess { if err != nil || !isSuccess {
return nil, err return nil, err
} }
...@@ -62,7 +63,7 @@ func StartVm(vm *models.VM) (interface{}, error) { ...@@ -62,7 +63,7 @@ func StartVm(vm *models.VM) (interface{}, error) {
data := url.Values{} data := url.Values{}
data.Set("node", hostName) data.Set("node", hostName)
data.Set("vmid", vm.NewId) data.Set("vmid", vm.NewId)
isSuccess, _, result, err := sendPostForm(uri, data, vm.HeaderInfo) isSuccess, _, result, err := sendPvePostForm(uri, data, vm.HeaderInfo)
if err != nil || !isSuccess { if err != nil || !isSuccess {
return nil, err return nil, err
} }
...@@ -77,8 +78,8 @@ func CreateVm(vm *models.VM) (interface{}, error) { ...@@ -77,8 +78,8 @@ func CreateVm(vm *models.VM) (interface{}, error) {
data.Set("node", hostName) data.Set("node", hostName)
data.Set("vmid", vm.VmId) data.Set("vmid", vm.VmId)
data.Set("newid", vm.NewId) data.Set("newid", vm.NewId)
data.Set("name", vm.Name) data.Set("name", vm.VmCfg.Name)
isSuccess, _, result, err := sendPostForm(uri, data, vm.HeaderInfo) isSuccess, _, result, err := sendPvePostForm(uri, data, vm.HeaderInfo)
if err != nil || !isSuccess { if err != nil || !isSuccess {
return nil, err return nil, err
} }
...@@ -95,7 +96,7 @@ func SetVmConfig(vm *models.VM) (interface{}, error) { ...@@ -95,7 +96,7 @@ func SetVmConfig(vm *models.VM) (interface{}, error) {
data.Set("cores", vm.VmCfg.Cores.String()) data.Set("cores", vm.VmCfg.Cores.String())
data.Set("sockets", vm.VmCfg.Sockets.String()) data.Set("sockets", vm.VmCfg.Sockets.String())
data.Set("memory", vm.VmCfg.Memory.String()) data.Set("memory", vm.VmCfg.Memory.String())
isSuccess, _, result, err := sendPostForm(uri, data, vm.HeaderInfo) isSuccess, _, result, err := sendPvePostForm(uri, data, vm.HeaderInfo)
if err != nil || !isSuccess { if err != nil || !isSuccess {
return nil, err return nil, err
} }
...@@ -105,7 +106,7 @@ func SetVmConfig(vm *models.VM) (interface{}, error) { ...@@ -105,7 +106,7 @@ func SetVmConfig(vm *models.VM) (interface{}, error) {
func GetVmNetWork(vm *models.VM) ([]*models.NetworkInfo, error) { func GetVmNetWork(vm *models.VM) ([]*models.NetworkInfo, error) {
uriSuffix := fmt.Sprintf("/%s/agent/network-get-interfaces", vm.NewId) uriSuffix := fmt.Sprintf("/%s/agent/network-get-interfaces", vm.NewId)
uri := pveNodesPrefixApi + uriSuffix uri := pveNodesPrefixApi + uriSuffix
isSuccess, _, resp, err := sendGetRequest(uri, vm.HeaderInfo) isSuccess, _, resp, err := sendPveGetRequest(uri, vm.HeaderInfo)
if err != nil || !isSuccess { if err != nil || !isSuccess {
return nil, err return nil, err
} }
...@@ -125,7 +126,7 @@ func GetVmNetWork(vm *models.VM) ([]*models.NetworkInfo, error) { ...@@ -125,7 +126,7 @@ func GetVmNetWork(vm *models.VM) ([]*models.NetworkInfo, error) {
func VmStatus(vm *models.VM) (*models.VmStatusRep, error) { func VmStatus(vm *models.VM) (*models.VmStatusRep, error) {
uriSuffix := fmt.Sprintf("/%s/status/current", vm.NewId) uriSuffix := fmt.Sprintf("/%s/status/current", vm.NewId)
uri := pveNodesPrefixApi + uriSuffix uri := pveNodesPrefixApi + uriSuffix
isSuccess, _, resp, err := sendGetRequest(uri, vm.HeaderInfo) isSuccess, _, resp, err := sendPveGetRequest(uri, vm.HeaderInfo)
if err != nil || !isSuccess { if err != nil || !isSuccess {
return nil, err return nil, err
} }
...@@ -142,7 +143,7 @@ func VmStatus(vm *models.VM) (*models.VmStatusRep, error) { ...@@ -142,7 +143,7 @@ func VmStatus(vm *models.VM) (*models.VmStatusRep, error) {
} }
func GetQemuList(headerInfo *models.HeaderInfo) ([]*models.QemuList, error) { func GetQemuList(headerInfo *models.HeaderInfo) ([]*models.QemuList, error) {
isSuccess, responseArr, _, err := sendGetRequest(pveNodesPrefixApi, headerInfo) isSuccess, responseArr, _, err := sendPveGetRequest(pveNodesPrefixApi, headerInfo)
if err != nil || !isSuccess { if err != nil || !isSuccess {
return nil, err return nil, err
} }
...@@ -170,15 +171,15 @@ func SetVmLoginUser(vm *models.VM) (interface{}, error) { ...@@ -170,15 +171,15 @@ func SetVmLoginUser(vm *models.VM) (interface{}, error) {
data.Set("vmid", vm.NewId) data.Set("vmid", vm.NewId)
data.Set("password", vm.VmCfg.Cores.String()) data.Set("password", vm.VmCfg.Cores.String())
data.Set("username", vm.VmCfg.Sockets.String()) data.Set("username", vm.VmCfg.Sockets.String())
isSuccess, _, result, err := sendPostForm(uri, data, vm.HeaderInfo) isSuccess, _, result, err := sendPvePostForm(uri, data, vm.HeaderInfo)
if err != nil || !isSuccess { if err != nil || !isSuccess {
return nil, err return nil, err
} }
return result, nil return result, nil
} }
// sendPostForm 发送postForm请求 // sendPvePostForm 发送postForm请求
func sendPostForm(uri string, data url.Values, headInfo *models.HeaderInfo) (bool, []interface{}, map[string]interface{}, error) { func sendPvePostForm(uri string, data url.Values, headInfo *models.HeaderInfo) (bool, []interface{}, map[string]interface{}, error) {
request, err := http.NewRequest("POST", uri, bytes.NewBufferString(data.Encode())) request, err := http.NewRequest("POST", uri, bytes.NewBufferString(data.Encode()))
if err != nil { if err != nil {
return false, nil, nil, err return false, nil, nil, err
...@@ -196,8 +197,8 @@ func sendPostForm(uri string, data url.Values, headInfo *models.HeaderInfo) (boo ...@@ -196,8 +197,8 @@ func sendPostForm(uri string, data url.Values, headInfo *models.HeaderInfo) (boo
return isSuccess, responseArr, response, nil return isSuccess, responseArr, response, nil
} }
// sendGetRequest 发送Get请求 // sendPveGetRequest 发送Get请求
func sendGetRequest(uri string, headInfo *models.HeaderInfo) (bool, []interface{}, map[string]interface{}, error) { func sendPveGetRequest(uri string, headInfo *models.HeaderInfo) (bool, []interface{}, map[string]interface{}, error) {
request, err := http.NewRequest("GET", uri, nil) request, err := http.NewRequest("GET", uri, nil)
if headInfo != nil { if headInfo != nil {
request.Header.Set("Cookie", headInfo.Ticket) request.Header.Set("Cookie", headInfo.Ticket)
...@@ -218,7 +219,12 @@ func handlerResponse(request *http.Request) (bool, []interface{}, map[string]int ...@@ -218,7 +219,12 @@ func handlerResponse(request *http.Request) (bool, []interface{}, map[string]int
log.Errorf("Send get request error: %s , uri: %s", err.Error(), request.URL.String()) log.Errorf("Send get request error: %s , uri: %s", err.Error(), request.URL.String())
return false, nil, nil, err return false, nil, nil, err
} }
defer resp.Body.Close() defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
log.Errorf("IO error closing error body: %s", err.Error())
}
}(resp.Body)
if resp.StatusCode != hashrateCommon.SuccessCode { if resp.StatusCode != hashrateCommon.SuccessCode {
log.Error("Send post request failed:", resp.Status) log.Error("Send post request failed:", resp.Status)
return false, nil, nil, nil return false, nil, nil, nil
......
...@@ -2,21 +2,25 @@ appname = hashrateNode ...@@ -2,21 +2,25 @@ appname = hashrateNode
httpport = 8080 httpport = 8080
runmode = dev runmode = dev
chain_rpc_url = http://192.168.1.109:7545 chain_rpc_url = http://192.168.1.125:7545
chainID = 5777 chainID = 1337
# chain_rpc_url = http://15.161.177.5:26658 # chain_rpc_url = http://15.161.177.5:26658
# chainID = 256256 # chainID = 256256
local_ip = 192.168.1.125 local_ip = 192.168.1.125
secret = bdcd61d5-6d48-4a0b-ac74-509ec0c3ecde secret = bdcd61d5-6d48-4a0b-ac74-509ec0c3ecde
sendTranAddress = 0x4BCA676dc7140DE25217780892a763262967Ee41 sendTranAddress = 0x257A1F95F3C09a0A2F4d82d3f916E8DbCE084659
sendTranPrv = 0x23384e00f2faa72b5a632f2c6bd5d23ba3e4c16b3c279dc850fd52c442d50d78 sendTranPrv = 0xfd5cc6f5e7e2805e920ac5dc83d5af1106f9c92f0c04f9d5e1fd4261b4b4464a
deployedBlock = 1
# sendTranAddress = 0x40EC4256fcBCA69CdbAc942594caeC79FBE10494 vncDefaultPort = 5900
# sendTranPrv = 0x37871f094f89fc95599e73d72d3008c828bb76d0864759011fa14dbaf6cf3c06 sshDefaultPort = 22
deployedBlock = 1 [nps]
api_host = http://124.193.167.71
api_port = 8090
auth_crypt_key = 90ac0231b59d4f7e
[pve] [pve]
ip = 192.168.1.60 ip = 192.168.1.60
......
[ [
{ {
"inputs": [ "inputs": [
{ {
...@@ -133,7 +133,7 @@ ...@@ -133,7 +133,7 @@
{ {
"indexed": false, "indexed": false,
"internalType": "uint64", "internalType": "uint64",
"name": "memoryNum", "name": "memorySize",
"type": "uint64" "type": "uint64"
}, },
{ {
...@@ -145,7 +145,7 @@ ...@@ -145,7 +145,7 @@
{ {
"indexed": false, "indexed": false,
"internalType": "uint256", "internalType": "uint256",
"name": "disk", "name": "diskSize",
"type": "uint256" "type": "uint256"
} }
], ],
...@@ -185,11 +185,6 @@ ...@@ -185,11 +185,6 @@
"name": "owner", "name": "owner",
"type": "address" "type": "address"
}, },
{
"internalType": "string",
"name": "taskId",
"type": "string"
},
{ {
"internalType": "uint256", "internalType": "uint256",
"name": "vmId", "name": "vmId",
...@@ -265,9 +260,33 @@ ...@@ -265,9 +260,33 @@
{ {
"inputs": [ "inputs": [
{ {
"internalType": "string", "internalType": "uint8",
"name": "taskId", "name": "start",
"type": "string" "type": "uint8"
},
{
"internalType": "uint8",
"name": "count",
"type": "uint8"
}
],
"name": "getVmIds",
"outputs": [
{
"internalType": "uint256[]",
"name": "res",
"type": "uint256[]"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "vmId",
"type": "uint256"
} }
], ],
"name": "getVmInfo", "name": "getVmInfo",
...@@ -279,7 +298,36 @@ ...@@ -279,7 +298,36 @@
}, },
{ {
"internalType": "string", "internalType": "string",
"name": "externalPort", "name": "ex_ssh_port",
"type": "string"
},
{
"internalType": "string",
"name": "ex_vnc_port",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "vmId",
"type": "uint256"
}
],
"name": "getVmUser",
"outputs": [
{
"internalType": "string",
"name": "username",
"type": "string"
},
{
"internalType": "string",
"name": "password",
"type": "string" "type": "string"
} }
], ],
...@@ -398,7 +446,7 @@ ...@@ -398,7 +446,7 @@
}, },
{ {
"internalType": "uint64", "internalType": "uint64",
"name": "memoryNum", "name": "memorySize",
"type": "uint64" "type": "uint64"
}, },
{ {
...@@ -408,11 +456,11 @@ ...@@ -408,11 +456,11 @@
}, },
{ {
"internalType": "uint256", "internalType": "uint256",
"name": "disk", "name": "diskSize",
"type": "uint256" "type": "uint256"
} }
], ],
"name": "updateVMInfoEvent", "name": "updateVmInfo",
"outputs": [], "outputs": [],
"stateMutability": "nonpayable", "stateMutability": "nonpayable",
"type": "function" "type": "function"
...@@ -473,7 +521,31 @@ ...@@ -473,7 +521,31 @@
"type": "uint256" "type": "uint256"
} }
], ],
"name": "vmData", "name": "vmConigData",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"name": "vmInfo",
"outputs": [ "outputs": [
{ {
"internalType": "string", "internalType": "string",
......
...@@ -30,7 +30,7 @@ var ( ...@@ -30,7 +30,7 @@ var (
// VmMetaData contains all meta data concerning the Vm contract. // VmMetaData contains all meta data concerning the Vm contract.
var VmMetaData = &bind.MetaData{ var VmMetaData = &bind.MetaData{
ABI: "[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"const\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"vmId\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"intranetIp\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"externalIp\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"exSshPort\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"exVncPort\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"inSshPort\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"inVncPort\",\"type\":\"string\"}],\"name\":\"UpdateNetworkInfoEvent\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"vmId\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"cpuCost\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"memoryCost\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"gpuCost\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"diskCost\",\"type\":\"string\"}],\"name\":\"UpdateResourceInfoEvent\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"vmId\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint64\",\"name\":\"cpuNum\",\"type\":\"uint64\"},{\"indexed\":false,\"internalType\":\"uint64\",\"name\":\"memoryNum\",\"type\":\"uint64\"},{\"indexed\":false,\"internalType\":\"uint64\",\"name\":\"gpuNum\",\"type\":\"uint64\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"disk\",\"type\":\"uint256\"}],\"name\":\"UpdateVMInfoEvent\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"_const\",\"outputs\":[{\"internalType\":\"contractICloudConstant\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_admin\",\"type\":\"address\"}],\"name\":\"addAdmin\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"taskId\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"vmId\",\"type\":\"uint256\"},{\"internalType\":\"string\",\"name\":\"clusterId\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"globalIdentify\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"hostId\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"vmName\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"os\",\"type\":\"string\"}],\"name\":\"addVirtualMachine\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"vmid\",\"type\":\"uint256\"},{\"internalType\":\"string\",\"name\":\"user\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"pwd\",\"type\":\"string\"}],\"name\":\"addVmUser\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_admin\",\"type\":\"address\"}],\"name\":\"delAdmin\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"taskId\",\"type\":\"string\"}],\"name\":\"getVmInfo\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"externalIp\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"externalPort\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_addr\",\"type\":\"address\"}],\"name\":\"isAdmin\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"const\",\"type\":\"address\"}],\"name\":\"setConstant\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"vmId\",\"type\":\"uint256\"},{\"internalType\":\"string\",\"name\":\"cpuCost\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"memoryCost\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"gpuCost\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"diskCost\",\"type\":\"string\"}],\"name\":\"updateResourceInfo\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"vmId\",\"type\":\"uint256\"},{\"internalType\":\"uint64\",\"name\":\"cpuNum\",\"type\":\"uint64\"},{\"internalType\":\"uint64\",\"name\":\"memoryNum\",\"type\":\"uint64\"},{\"internalType\":\"uint64\",\"name\":\"gpuNum\",\"type\":\"uint64\"},{\"internalType\":\"uint256\",\"name\":\"disk\",\"type\":\"uint256\"}],\"name\":\"updateVMInfoEvent\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"vmId\",\"type\":\"uint256\"},{\"internalType\":\"string\",\"name\":\"intranetIp\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"externalIp\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"exSshPort\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"exVncPort\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"inSshPort\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"inVncPort\",\"type\":\"string\"}],\"name\":\"updateVmNetworkInfo\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"vmData\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]", ABI: "[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"const\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"vmId\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"intranetIp\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"externalIp\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"exSshPort\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"exVncPort\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"inSshPort\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"inVncPort\",\"type\":\"string\"}],\"name\":\"UpdateNetworkInfoEvent\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"vmId\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"cpuCost\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"memoryCost\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"gpuCost\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"diskCost\",\"type\":\"string\"}],\"name\":\"UpdateResourceInfoEvent\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"vmId\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint64\",\"name\":\"cpuNum\",\"type\":\"uint64\"},{\"indexed\":false,\"internalType\":\"uint64\",\"name\":\"memorySize\",\"type\":\"uint64\"},{\"indexed\":false,\"internalType\":\"uint64\",\"name\":\"gpuNum\",\"type\":\"uint64\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"diskSize\",\"type\":\"uint256\"}],\"name\":\"UpdateVMInfoEvent\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"_const\",\"outputs\":[{\"internalType\":\"contractICloudConstant\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_admin\",\"type\":\"address\"}],\"name\":\"addAdmin\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"vmId\",\"type\":\"uint256\"},{\"internalType\":\"string\",\"name\":\"clusterId\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"globalIdentify\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"hostId\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"vmName\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"os\",\"type\":\"string\"}],\"name\":\"addVirtualMachine\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"vmid\",\"type\":\"uint256\"},{\"internalType\":\"string\",\"name\":\"user\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"pwd\",\"type\":\"string\"}],\"name\":\"addVmUser\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_admin\",\"type\":\"address\"}],\"name\":\"delAdmin\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"start\",\"type\":\"uint8\"},{\"internalType\":\"uint8\",\"name\":\"count\",\"type\":\"uint8\"}],\"name\":\"getVmIds\",\"outputs\":[{\"internalType\":\"uint256[]\",\"name\":\"res\",\"type\":\"uint256[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"vmId\",\"type\":\"uint256\"}],\"name\":\"getVmInfo\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"externalIp\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"ex_ssh_port\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"ex_vnc_port\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"vmId\",\"type\":\"uint256\"}],\"name\":\"getVmUser\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"username\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"password\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_addr\",\"type\":\"address\"}],\"name\":\"isAdmin\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"const\",\"type\":\"address\"}],\"name\":\"setConstant\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"vmId\",\"type\":\"uint256\"},{\"internalType\":\"string\",\"name\":\"cpuCost\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"memoryCost\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"gpuCost\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"diskCost\",\"type\":\"string\"}],\"name\":\"updateResourceInfo\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"vmId\",\"type\":\"uint256\"},{\"internalType\":\"uint64\",\"name\":\"cpuNum\",\"type\":\"uint64\"},{\"internalType\":\"uint64\",\"name\":\"memorySize\",\"type\":\"uint64\"},{\"internalType\":\"uint64\",\"name\":\"gpuNum\",\"type\":\"uint64\"},{\"internalType\":\"uint256\",\"name\":\"diskSize\",\"type\":\"uint256\"}],\"name\":\"updateVmInfo\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"vmId\",\"type\":\"uint256\"},{\"internalType\":\"string\",\"name\":\"intranetIp\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"externalIp\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"exSshPort\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"exVncPort\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"inSshPort\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"inVncPort\",\"type\":\"string\"}],\"name\":\"updateVmNetworkInfo\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"vmConigData\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"vmInfo\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]",
} }
// VmABI is the input ABI used to generate the binding from. // VmABI is the input ABI used to generate the binding from.
...@@ -210,49 +210,130 @@ func (_Vm *VmCallerSession) Const() (common.Address, error) { ...@@ -210,49 +210,130 @@ func (_Vm *VmCallerSession) Const() (common.Address, error) {
return _Vm.Contract.Const(&_Vm.CallOpts) return _Vm.Contract.Const(&_Vm.CallOpts)
} }
// GetVmInfo is a free data retrieval call binding the contract method 0x165e73cd. // GetVmIds is a free data retrieval call binding the contract method 0xf76fcb91.
// //
// Solidity: function getVmInfo(string taskId) view returns(string externalIp, string externalPort) // Solidity: function getVmIds(uint8 start, uint8 count) view returns(uint256[] res)
func (_Vm *VmCaller) GetVmInfo(opts *bind.CallOpts, taskId string) (struct { func (_Vm *VmCaller) GetVmIds(opts *bind.CallOpts, start uint8, count uint8) ([]*big.Int, error) {
var out []interface{}
err := _Vm.contract.Call(opts, &out, "getVmIds", start, count)
if err != nil {
return *new([]*big.Int), err
}
out0 := *abi.ConvertType(out[0], new([]*big.Int)).(*[]*big.Int)
return out0, err
}
// GetVmIds is a free data retrieval call binding the contract method 0xf76fcb91.
//
// Solidity: function getVmIds(uint8 start, uint8 count) view returns(uint256[] res)
func (_Vm *VmSession) GetVmIds(start uint8, count uint8) ([]*big.Int, error) {
return _Vm.Contract.GetVmIds(&_Vm.CallOpts, start, count)
}
// GetVmIds is a free data retrieval call binding the contract method 0xf76fcb91.
//
// Solidity: function getVmIds(uint8 start, uint8 count) view returns(uint256[] res)
func (_Vm *VmCallerSession) GetVmIds(start uint8, count uint8) ([]*big.Int, error) {
return _Vm.Contract.GetVmIds(&_Vm.CallOpts, start, count)
}
// GetVmInfo is a free data retrieval call binding the contract method 0xa3d06708.
//
// Solidity: function getVmInfo(uint256 vmId) view returns(string externalIp, string ex_ssh_port, string ex_vnc_port)
func (_Vm *VmCaller) GetVmInfo(opts *bind.CallOpts, vmId *big.Int) (struct {
ExternalIp string ExternalIp string
ExternalPort string ExSshPort string
ExVncPort string
}, error) { }, error) {
var out []interface{} var out []interface{}
err := _Vm.contract.Call(opts, &out, "getVmInfo", taskId) err := _Vm.contract.Call(opts, &out, "getVmInfo", vmId)
outstruct := new(struct { outstruct := new(struct {
ExternalIp string ExternalIp string
ExternalPort string ExSshPort string
ExVncPort string
}) })
if err != nil { if err != nil {
return *outstruct, err return *outstruct, err
} }
outstruct.ExternalIp = *abi.ConvertType(out[0], new(string)).(*string) outstruct.ExternalIp = *abi.ConvertType(out[0], new(string)).(*string)
outstruct.ExternalPort = *abi.ConvertType(out[1], new(string)).(*string) outstruct.ExSshPort = *abi.ConvertType(out[1], new(string)).(*string)
outstruct.ExVncPort = *abi.ConvertType(out[2], new(string)).(*string)
return *outstruct, err return *outstruct, err
} }
// GetVmInfo is a free data retrieval call binding the contract method 0x165e73cd. // GetVmInfo is a free data retrieval call binding the contract method 0xa3d06708.
// //
// Solidity: function getVmInfo(string taskId) view returns(string externalIp, string externalPort) // Solidity: function getVmInfo(uint256 vmId) view returns(string externalIp, string ex_ssh_port, string ex_vnc_port)
func (_Vm *VmSession) GetVmInfo(taskId string) (struct { func (_Vm *VmSession) GetVmInfo(vmId *big.Int) (struct {
ExternalIp string ExternalIp string
ExternalPort string ExSshPort string
ExVncPort string
}, error) { }, error) {
return _Vm.Contract.GetVmInfo(&_Vm.CallOpts, taskId) return _Vm.Contract.GetVmInfo(&_Vm.CallOpts, vmId)
} }
// GetVmInfo is a free data retrieval call binding the contract method 0x165e73cd. // GetVmInfo is a free data retrieval call binding the contract method 0xa3d06708.
// //
// Solidity: function getVmInfo(string taskId) view returns(string externalIp, string externalPort) // Solidity: function getVmInfo(uint256 vmId) view returns(string externalIp, string ex_ssh_port, string ex_vnc_port)
func (_Vm *VmCallerSession) GetVmInfo(taskId string) (struct { func (_Vm *VmCallerSession) GetVmInfo(vmId *big.Int) (struct {
ExternalIp string ExternalIp string
ExternalPort string ExSshPort string
ExVncPort string
}, error) { }, error) {
return _Vm.Contract.GetVmInfo(&_Vm.CallOpts, taskId) return _Vm.Contract.GetVmInfo(&_Vm.CallOpts, vmId)
}
// GetVmUser is a free data retrieval call binding the contract method 0xb67a266a.
//
// Solidity: function getVmUser(uint256 vmId) view returns(string username, string password)
func (_Vm *VmCaller) GetVmUser(opts *bind.CallOpts, vmId *big.Int) (struct {
Username string
Password string
}, error) {
var out []interface{}
err := _Vm.contract.Call(opts, &out, "getVmUser", vmId)
outstruct := new(struct {
Username string
Password string
})
if err != nil {
return *outstruct, err
}
outstruct.Username = *abi.ConvertType(out[0], new(string)).(*string)
outstruct.Password = *abi.ConvertType(out[1], new(string)).(*string)
return *outstruct, err
}
// GetVmUser is a free data retrieval call binding the contract method 0xb67a266a.
//
// Solidity: function getVmUser(uint256 vmId) view returns(string username, string password)
func (_Vm *VmSession) GetVmUser(vmId *big.Int) (struct {
Username string
Password string
}, error) {
return _Vm.Contract.GetVmUser(&_Vm.CallOpts, vmId)
}
// GetVmUser is a free data retrieval call binding the contract method 0xb67a266a.
//
// Solidity: function getVmUser(uint256 vmId) view returns(string username, string password)
func (_Vm *VmCallerSession) GetVmUser(vmId *big.Int) (struct {
Username string
Password string
}, error) {
return _Vm.Contract.GetVmUser(&_Vm.CallOpts, vmId)
} }
// IsAdmin is a free data retrieval call binding the contract method 0x24d7806c. // IsAdmin is a free data retrieval call binding the contract method 0x24d7806c.
...@@ -317,12 +398,43 @@ func (_Vm *VmCallerSession) Owner() (common.Address, error) { ...@@ -317,12 +398,43 @@ func (_Vm *VmCallerSession) Owner() (common.Address, error) {
return _Vm.Contract.Owner(&_Vm.CallOpts) return _Vm.Contract.Owner(&_Vm.CallOpts)
} }
// VmData is a free data retrieval call binding the contract method 0x2d9d87d7. // VmConigData is a free data retrieval call binding the contract method 0xde4e9adc.
//
// Solidity: function vmConigData(uint256 , uint256 ) view returns(uint256)
func (_Vm *VmCaller) VmConigData(opts *bind.CallOpts, arg0 *big.Int, arg1 *big.Int) (*big.Int, error) {
var out []interface{}
err := _Vm.contract.Call(opts, &out, "vmConigData", arg0, arg1)
if err != nil {
return *new(*big.Int), err
}
out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int)
return out0, err
}
// VmConigData is a free data retrieval call binding the contract method 0xde4e9adc.
//
// Solidity: function vmConigData(uint256 , uint256 ) view returns(uint256)
func (_Vm *VmSession) VmConigData(arg0 *big.Int, arg1 *big.Int) (*big.Int, error) {
return _Vm.Contract.VmConigData(&_Vm.CallOpts, arg0, arg1)
}
// VmConigData is a free data retrieval call binding the contract method 0xde4e9adc.
//
// Solidity: function vmConigData(uint256 , uint256 ) view returns(uint256)
func (_Vm *VmCallerSession) VmConigData(arg0 *big.Int, arg1 *big.Int) (*big.Int, error) {
return _Vm.Contract.VmConigData(&_Vm.CallOpts, arg0, arg1)
}
// VmInfo is a free data retrieval call binding the contract method 0x90aa095b.
// //
// Solidity: function vmData(uint256 , uint256 ) view returns(string) // Solidity: function vmInfo(uint256 , uint256 ) view returns(string)
func (_Vm *VmCaller) VmData(opts *bind.CallOpts, arg0 *big.Int, arg1 *big.Int) (string, error) { func (_Vm *VmCaller) VmInfo(opts *bind.CallOpts, arg0 *big.Int, arg1 *big.Int) (string, error) {
var out []interface{} var out []interface{}
err := _Vm.contract.Call(opts, &out, "vmData", arg0, arg1) err := _Vm.contract.Call(opts, &out, "vmInfo", arg0, arg1)
if err != nil { if err != nil {
return *new(string), err return *new(string), err
...@@ -334,18 +446,18 @@ func (_Vm *VmCaller) VmData(opts *bind.CallOpts, arg0 *big.Int, arg1 *big.Int) ( ...@@ -334,18 +446,18 @@ func (_Vm *VmCaller) VmData(opts *bind.CallOpts, arg0 *big.Int, arg1 *big.Int) (
} }
// VmData is a free data retrieval call binding the contract method 0x2d9d87d7. // VmInfo is a free data retrieval call binding the contract method 0x90aa095b.
// //
// Solidity: function vmData(uint256 , uint256 ) view returns(string) // Solidity: function vmInfo(uint256 , uint256 ) view returns(string)
func (_Vm *VmSession) VmData(arg0 *big.Int, arg1 *big.Int) (string, error) { func (_Vm *VmSession) VmInfo(arg0 *big.Int, arg1 *big.Int) (string, error) {
return _Vm.Contract.VmData(&_Vm.CallOpts, arg0, arg1) return _Vm.Contract.VmInfo(&_Vm.CallOpts, arg0, arg1)
} }
// VmData is a free data retrieval call binding the contract method 0x2d9d87d7. // VmInfo is a free data retrieval call binding the contract method 0x90aa095b.
// //
// Solidity: function vmData(uint256 , uint256 ) view returns(string) // Solidity: function vmInfo(uint256 , uint256 ) view returns(string)
func (_Vm *VmCallerSession) VmData(arg0 *big.Int, arg1 *big.Int) (string, error) { func (_Vm *VmCallerSession) VmInfo(arg0 *big.Int, arg1 *big.Int) (string, error) {
return _Vm.Contract.VmData(&_Vm.CallOpts, arg0, arg1) return _Vm.Contract.VmInfo(&_Vm.CallOpts, arg0, arg1)
} }
// AddAdmin is a paid mutator transaction binding the contract method 0x70480275. // AddAdmin is a paid mutator transaction binding the contract method 0x70480275.
...@@ -369,25 +481,25 @@ func (_Vm *VmTransactorSession) AddAdmin(_admin common.Address) (*types.Transact ...@@ -369,25 +481,25 @@ func (_Vm *VmTransactorSession) AddAdmin(_admin common.Address) (*types.Transact
return _Vm.Contract.AddAdmin(&_Vm.TransactOpts, _admin) return _Vm.Contract.AddAdmin(&_Vm.TransactOpts, _admin)
} }
// AddVirtualMachine is a paid mutator transaction binding the contract method 0x7c95f48f. // AddVirtualMachine is a paid mutator transaction binding the contract method 0x6ce96e90.
// //
// Solidity: function addVirtualMachine(address owner, string taskId, uint256 vmId, string clusterId, string globalIdentify, string hostId, string vmName, string os) returns() // Solidity: function addVirtualMachine(address owner, uint256 vmId, string clusterId, string globalIdentify, string hostId, string vmName, string os) returns()
func (_Vm *VmTransactor) AddVirtualMachine(opts *bind.TransactOpts, owner common.Address, taskId string, vmId *big.Int, clusterId string, globalIdentify string, hostId string, vmName string, os string) (*types.Transaction, error) { func (_Vm *VmTransactor) AddVirtualMachine(opts *bind.TransactOpts, owner common.Address, vmId *big.Int, clusterId string, globalIdentify string, hostId string, vmName string, os string) (*types.Transaction, error) {
return _Vm.contract.Transact(opts, "addVirtualMachine", owner, taskId, vmId, clusterId, globalIdentify, hostId, vmName, os) return _Vm.contract.Transact(opts, "addVirtualMachine", owner, vmId, clusterId, globalIdentify, hostId, vmName, os)
} }
// AddVirtualMachine is a paid mutator transaction binding the contract method 0x7c95f48f. // AddVirtualMachine is a paid mutator transaction binding the contract method 0x6ce96e90.
// //
// Solidity: function addVirtualMachine(address owner, string taskId, uint256 vmId, string clusterId, string globalIdentify, string hostId, string vmName, string os) returns() // Solidity: function addVirtualMachine(address owner, uint256 vmId, string clusterId, string globalIdentify, string hostId, string vmName, string os) returns()
func (_Vm *VmSession) AddVirtualMachine(owner common.Address, taskId string, vmId *big.Int, clusterId string, globalIdentify string, hostId string, vmName string, os string) (*types.Transaction, error) { func (_Vm *VmSession) AddVirtualMachine(owner common.Address, vmId *big.Int, clusterId string, globalIdentify string, hostId string, vmName string, os string) (*types.Transaction, error) {
return _Vm.Contract.AddVirtualMachine(&_Vm.TransactOpts, owner, taskId, vmId, clusterId, globalIdentify, hostId, vmName, os) return _Vm.Contract.AddVirtualMachine(&_Vm.TransactOpts, owner, vmId, clusterId, globalIdentify, hostId, vmName, os)
} }
// AddVirtualMachine is a paid mutator transaction binding the contract method 0x7c95f48f. // AddVirtualMachine is a paid mutator transaction binding the contract method 0x6ce96e90.
// //
// Solidity: function addVirtualMachine(address owner, string taskId, uint256 vmId, string clusterId, string globalIdentify, string hostId, string vmName, string os) returns() // Solidity: function addVirtualMachine(address owner, uint256 vmId, string clusterId, string globalIdentify, string hostId, string vmName, string os) returns()
func (_Vm *VmTransactorSession) AddVirtualMachine(owner common.Address, taskId string, vmId *big.Int, clusterId string, globalIdentify string, hostId string, vmName string, os string) (*types.Transaction, error) { func (_Vm *VmTransactorSession) AddVirtualMachine(owner common.Address, vmId *big.Int, clusterId string, globalIdentify string, hostId string, vmName string, os string) (*types.Transaction, error) {
return _Vm.Contract.AddVirtualMachine(&_Vm.TransactOpts, owner, taskId, vmId, clusterId, globalIdentify, hostId, vmName, os) return _Vm.Contract.AddVirtualMachine(&_Vm.TransactOpts, owner, vmId, clusterId, globalIdentify, hostId, vmName, os)
} }
// AddVmUser is a paid mutator transaction binding the contract method 0x388911d6. // AddVmUser is a paid mutator transaction binding the contract method 0x388911d6.
...@@ -516,25 +628,25 @@ func (_Vm *VmTransactorSession) UpdateResourceInfo(vmId *big.Int, cpuCost string ...@@ -516,25 +628,25 @@ func (_Vm *VmTransactorSession) UpdateResourceInfo(vmId *big.Int, cpuCost string
return _Vm.Contract.UpdateResourceInfo(&_Vm.TransactOpts, vmId, cpuCost, memoryCost, gpuCost, diskCost) return _Vm.Contract.UpdateResourceInfo(&_Vm.TransactOpts, vmId, cpuCost, memoryCost, gpuCost, diskCost)
} }
// UpdateVMInfoEvent is a paid mutator transaction binding the contract method 0xa33d9a98. // UpdateVmInfo is a paid mutator transaction binding the contract method 0xe5418d02.
// //
// Solidity: function updateVMInfoEvent(uint256 vmId, uint64 cpuNum, uint64 memoryNum, uint64 gpuNum, uint256 disk) returns() // Solidity: function updateVmInfo(uint256 vmId, uint64 cpuNum, uint64 memorySize, uint64 gpuNum, uint256 diskSize) returns()
func (_Vm *VmTransactor) UpdateVMInfoEvent(opts *bind.TransactOpts, vmId *big.Int, cpuNum uint64, memoryNum uint64, gpuNum uint64, disk *big.Int) (*types.Transaction, error) { func (_Vm *VmTransactor) UpdateVmInfo(opts *bind.TransactOpts, vmId *big.Int, cpuNum uint64, memorySize uint64, gpuNum uint64, diskSize *big.Int) (*types.Transaction, error) {
return _Vm.contract.Transact(opts, "updateVMInfoEvent", vmId, cpuNum, memoryNum, gpuNum, disk) return _Vm.contract.Transact(opts, "updateVmInfo", vmId, cpuNum, memorySize, gpuNum, diskSize)
} }
// UpdateVMInfoEvent is a paid mutator transaction binding the contract method 0xa33d9a98. // UpdateVmInfo is a paid mutator transaction binding the contract method 0xe5418d02.
// //
// Solidity: function updateVMInfoEvent(uint256 vmId, uint64 cpuNum, uint64 memoryNum, uint64 gpuNum, uint256 disk) returns() // Solidity: function updateVmInfo(uint256 vmId, uint64 cpuNum, uint64 memorySize, uint64 gpuNum, uint256 diskSize) returns()
func (_Vm *VmSession) UpdateVMInfoEvent(vmId *big.Int, cpuNum uint64, memoryNum uint64, gpuNum uint64, disk *big.Int) (*types.Transaction, error) { func (_Vm *VmSession) UpdateVmInfo(vmId *big.Int, cpuNum uint64, memorySize uint64, gpuNum uint64, diskSize *big.Int) (*types.Transaction, error) {
return _Vm.Contract.UpdateVMInfoEvent(&_Vm.TransactOpts, vmId, cpuNum, memoryNum, gpuNum, disk) return _Vm.Contract.UpdateVmInfo(&_Vm.TransactOpts, vmId, cpuNum, memorySize, gpuNum, diskSize)
} }
// UpdateVMInfoEvent is a paid mutator transaction binding the contract method 0xa33d9a98. // UpdateVmInfo is a paid mutator transaction binding the contract method 0xe5418d02.
// //
// Solidity: function updateVMInfoEvent(uint256 vmId, uint64 cpuNum, uint64 memoryNum, uint64 gpuNum, uint256 disk) returns() // Solidity: function updateVmInfo(uint256 vmId, uint64 cpuNum, uint64 memorySize, uint64 gpuNum, uint256 diskSize) returns()
func (_Vm *VmTransactorSession) UpdateVMInfoEvent(vmId *big.Int, cpuNum uint64, memoryNum uint64, gpuNum uint64, disk *big.Int) (*types.Transaction, error) { func (_Vm *VmTransactorSession) UpdateVmInfo(vmId *big.Int, cpuNum uint64, memorySize uint64, gpuNum uint64, diskSize *big.Int) (*types.Transaction, error) {
return _Vm.Contract.UpdateVMInfoEvent(&_Vm.TransactOpts, vmId, cpuNum, memoryNum, gpuNum, disk) return _Vm.Contract.UpdateVmInfo(&_Vm.TransactOpts, vmId, cpuNum, memorySize, gpuNum, diskSize)
} }
// UpdateVmNetworkInfo is a paid mutator transaction binding the contract method 0xfea9da61. // UpdateVmNetworkInfo is a paid mutator transaction binding the contract method 0xfea9da61.
...@@ -1060,15 +1172,15 @@ func (it *VmUpdateVMInfoEventIterator) Close() error { ...@@ -1060,15 +1172,15 @@ func (it *VmUpdateVMInfoEventIterator) Close() error {
type VmUpdateVMInfoEvent struct { type VmUpdateVMInfoEvent struct {
VmId *big.Int VmId *big.Int
CpuNum uint64 CpuNum uint64
MemoryNum uint64 MemorySize uint64
GpuNum uint64 GpuNum uint64
Disk *big.Int DiskSize *big.Int
Raw types.Log // Blockchain specific contextual infos Raw types.Log // Blockchain specific contextual infos
} }
// FilterUpdateVMInfoEvent is a free log retrieval operation binding the contract event 0xe7eca197713d046c5838b32bdc1fac83a9de5a9ca65a070482955f7953f6aab1. // FilterUpdateVMInfoEvent is a free log retrieval operation binding the contract event 0xe7eca197713d046c5838b32bdc1fac83a9de5a9ca65a070482955f7953f6aab1.
// //
// Solidity: event UpdateVMInfoEvent(uint256 vmId, uint64 cpuNum, uint64 memoryNum, uint64 gpuNum, uint256 disk) // Solidity: event UpdateVMInfoEvent(uint256 vmId, uint64 cpuNum, uint64 memorySize, uint64 gpuNum, uint256 diskSize)
func (_Vm *VmFilterer) FilterUpdateVMInfoEvent(opts *bind.FilterOpts) (*VmUpdateVMInfoEventIterator, error) { func (_Vm *VmFilterer) FilterUpdateVMInfoEvent(opts *bind.FilterOpts) (*VmUpdateVMInfoEventIterator, error) {
logs, sub, err := _Vm.contract.FilterLogs(opts, "UpdateVMInfoEvent") logs, sub, err := _Vm.contract.FilterLogs(opts, "UpdateVMInfoEvent")
...@@ -1080,7 +1192,7 @@ func (_Vm *VmFilterer) FilterUpdateVMInfoEvent(opts *bind.FilterOpts) (*VmUpdate ...@@ -1080,7 +1192,7 @@ func (_Vm *VmFilterer) FilterUpdateVMInfoEvent(opts *bind.FilterOpts) (*VmUpdate
// WatchUpdateVMInfoEvent is a free log subscription operation binding the contract event 0xe7eca197713d046c5838b32bdc1fac83a9de5a9ca65a070482955f7953f6aab1. // WatchUpdateVMInfoEvent is a free log subscription operation binding the contract event 0xe7eca197713d046c5838b32bdc1fac83a9de5a9ca65a070482955f7953f6aab1.
// //
// Solidity: event UpdateVMInfoEvent(uint256 vmId, uint64 cpuNum, uint64 memoryNum, uint64 gpuNum, uint256 disk) // Solidity: event UpdateVMInfoEvent(uint256 vmId, uint64 cpuNum, uint64 memorySize, uint64 gpuNum, uint256 diskSize)
func (_Vm *VmFilterer) WatchUpdateVMInfoEvent(opts *bind.WatchOpts, sink chan<- *VmUpdateVMInfoEvent) (event.Subscription, error) { func (_Vm *VmFilterer) WatchUpdateVMInfoEvent(opts *bind.WatchOpts, sink chan<- *VmUpdateVMInfoEvent) (event.Subscription, error) {
logs, sub, err := _Vm.contract.WatchLogs(opts, "UpdateVMInfoEvent") logs, sub, err := _Vm.contract.WatchLogs(opts, "UpdateVMInfoEvent")
...@@ -1117,7 +1229,7 @@ func (_Vm *VmFilterer) WatchUpdateVMInfoEvent(opts *bind.WatchOpts, sink chan<- ...@@ -1117,7 +1229,7 @@ func (_Vm *VmFilterer) WatchUpdateVMInfoEvent(opts *bind.WatchOpts, sink chan<-
// ParseUpdateVMInfoEvent is a log parse operation binding the contract event 0xe7eca197713d046c5838b32bdc1fac83a9de5a9ca65a070482955f7953f6aab1. // ParseUpdateVMInfoEvent is a log parse operation binding the contract event 0xe7eca197713d046c5838b32bdc1fac83a9de5a9ca65a070482955f7953f6aab1.
// //
// Solidity: event UpdateVMInfoEvent(uint256 vmId, uint64 cpuNum, uint64 memoryNum, uint64 gpuNum, uint256 disk) // Solidity: event UpdateVMInfoEvent(uint256 vmId, uint64 cpuNum, uint64 memorySize, uint64 gpuNum, uint256 diskSize)
func (_Vm *VmFilterer) ParseUpdateVMInfoEvent(log types.Log) (*VmUpdateVMInfoEvent, error) { func (_Vm *VmFilterer) ParseUpdateVMInfoEvent(log types.Log) (*VmUpdateVMInfoEvent, error) {
event := new(VmUpdateVMInfoEvent) event := new(VmUpdateVMInfoEvent)
if err := _Vm.contract.UnpackLog(event, "UpdateVMInfoEvent", log); err != nil { if err := _Vm.contract.UnpackLog(event, "UpdateVMInfoEvent", log); err != nil {
......
[ [
{ {
"inputs": [ "inputs": [
{ {
...@@ -72,6 +72,12 @@ ...@@ -72,6 +72,12 @@
"internalType": "string", "internalType": "string",
"name": "os", "name": "os",
"type": "string" "type": "string"
},
{
"indexed": false,
"internalType": "string",
"name": "vmName",
"type": "string"
} }
], ],
"name": "AddCreateVMInfoEvent", "name": "AddCreateVMInfoEvent",
...@@ -186,13 +192,18 @@ ...@@ -186,13 +192,18 @@
}, },
{ {
"internalType": "uint64", "internalType": "uint64",
"name": "memNum", "name": "memSize",
"type": "uint64" "type": "uint64"
}, },
{ {
"internalType": "string", "internalType": "string",
"name": "os", "name": "os",
"type": "string" "type": "string"
},
{
"internalType": "string",
"name": "vmName",
"type": "string"
} }
], ],
"name": "addVirtualMachine", "name": "addVirtualMachine",
...@@ -214,13 +225,47 @@ ...@@ -214,13 +225,47 @@
"type": "function" "type": "function"
}, },
{ {
"inputs": [], "inputs": [
"name": "getTaskId", {
"outputs": [ "internalType": "address",
"name": "owner",
"type": "address"
},
{ {
"internalType": "string", "internalType": "string",
"name": "", "name": "taskId",
"type": "string" "type": "string"
},
{
"internalType": "uint256",
"name": "vmId",
"type": "uint256"
}
],
"name": "finishTask",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint8",
"name": "start",
"type": "uint8"
},
{
"internalType": "uint8",
"name": "count",
"type": "uint8"
}
],
"name": "getTaskId",
"outputs": [
{
"internalType": "string[]",
"name": "res",
"type": "string[]"
} }
], ],
"stateMutability": "view", "stateMutability": "view",
...@@ -250,6 +295,25 @@ ...@@ -250,6 +295,25 @@
"stateMutability": "view", "stateMutability": "view",
"type": "function" "type": "function"
}, },
{
"inputs": [
{
"internalType": "string",
"name": "taskId",
"type": "string"
}
],
"name": "getVmId",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{ {
"inputs": [ "inputs": [
{ {
......
...@@ -30,7 +30,7 @@ var ( ...@@ -30,7 +30,7 @@ var (
// VmCreateMetaData contains all meta data concerning the VmCreate contract. // VmCreateMetaData contains all meta data concerning the VmCreate contract.
var VmCreateMetaData = &bind.MetaData{ var VmCreateMetaData = &bind.MetaData{
ABI: "[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"const\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"string\",\"name\":\"taskId\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"callerIp\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"cpuModel\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"uint64\",\"name\":\"cpuNum\",\"type\":\"uint64\"},{\"indexed\":false,\"internalType\":\"uint64\",\"name\":\"cpuCores\",\"type\":\"uint64\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"gpuModel\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"uint64\",\"name\":\"gpuNum\",\"type\":\"uint64\"},{\"indexed\":false,\"internalType\":\"uint64\",\"name\":\"memNum\",\"type\":\"uint64\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"os\",\"type\":\"string\"}],\"name\":\"AddCreateVMInfoEvent\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"string\",\"name\":\"taskId\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"creater\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"snatcher\",\"type\":\"address\"}],\"name\":\"SnatchTaskEvent\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"_const\",\"outputs\":[{\"internalType\":\"contractICloudConstant\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_admin\",\"type\":\"address\"}],\"name\":\"addAdmin\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"taskId\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"callerIp\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"cpuModel\",\"type\":\"string\"},{\"internalType\":\"uint64\",\"name\":\"cpuNum\",\"type\":\"uint64\"},{\"internalType\":\"uint64\",\"name\":\"cpuCores\",\"type\":\"uint64\"},{\"internalType\":\"string\",\"name\":\"gpuModel\",\"type\":\"string\"},{\"internalType\":\"uint64\",\"name\":\"gpuNum\",\"type\":\"uint64\"},{\"internalType\":\"uint64\",\"name\":\"memNum\",\"type\":\"uint64\"},{\"internalType\":\"string\",\"name\":\"os\",\"type\":\"string\"}],\"name\":\"addVirtualMachine\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_admin\",\"type\":\"address\"}],\"name\":\"delAdmin\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"getTaskId\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"taskId\",\"type\":\"string\"}],\"name\":\"getVmCreateProgress\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_addr\",\"type\":\"address\"}],\"name\":\"isAdmin\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"const\",\"type\":\"address\"}],\"name\":\"setConstant\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"taskId\",\"type\":\"string\"},{\"internalType\":\"address\",\"name\":\"creater\",\"type\":\"address\"}],\"name\":\"snatchTask\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"},{\"internalType\":\"uint8\",\"name\":\"\",\"type\":\"uint8\"}],\"name\":\"taskProgress\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"taskId\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"createStage\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"createProgress\",\"type\":\"uint256\"}],\"name\":\"updateVmCreateProgress\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]", ABI: "[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"const\",\"type\":\"address\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"string\",\"name\":\"taskId\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"callerIp\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"cpuModel\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"uint64\",\"name\":\"cpuNum\",\"type\":\"uint64\"},{\"indexed\":false,\"internalType\":\"uint64\",\"name\":\"cpuCores\",\"type\":\"uint64\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"gpuModel\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"uint64\",\"name\":\"gpuNum\",\"type\":\"uint64\"},{\"indexed\":false,\"internalType\":\"uint64\",\"name\":\"memNum\",\"type\":\"uint64\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"os\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"string\",\"name\":\"vmName\",\"type\":\"string\"}],\"name\":\"AddCreateVMInfoEvent\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"address\",\"name\":\"previousOwner\",\"type\":\"address\"},{\"indexed\":true,\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"OwnershipTransferred\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"string\",\"name\":\"taskId\",\"type\":\"string\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"creater\",\"type\":\"address\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"snatcher\",\"type\":\"address\"}],\"name\":\"SnatchTaskEvent\",\"type\":\"event\"},{\"inputs\":[],\"name\":\"_const\",\"outputs\":[{\"internalType\":\"contractICloudConstant\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_admin\",\"type\":\"address\"}],\"name\":\"addAdmin\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"taskId\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"callerIp\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"cpuModel\",\"type\":\"string\"},{\"internalType\":\"uint64\",\"name\":\"cpuNum\",\"type\":\"uint64\"},{\"internalType\":\"uint64\",\"name\":\"cpuCores\",\"type\":\"uint64\"},{\"internalType\":\"string\",\"name\":\"gpuModel\",\"type\":\"string\"},{\"internalType\":\"uint64\",\"name\":\"gpuNum\",\"type\":\"uint64\"},{\"internalType\":\"uint64\",\"name\":\"memSize\",\"type\":\"uint64\"},{\"internalType\":\"string\",\"name\":\"os\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"vmName\",\"type\":\"string\"}],\"name\":\"addVirtualMachine\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_admin\",\"type\":\"address\"}],\"name\":\"delAdmin\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"owner\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"taskId\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"vmId\",\"type\":\"uint256\"}],\"name\":\"finishTask\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint8\",\"name\":\"start\",\"type\":\"uint8\"},{\"internalType\":\"uint8\",\"name\":\"count\",\"type\":\"uint8\"}],\"name\":\"getTaskId\",\"outputs\":[{\"internalType\":\"string[]\",\"name\":\"res\",\"type\":\"string[]\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"taskId\",\"type\":\"string\"}],\"name\":\"getVmCreateProgress\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"taskId\",\"type\":\"string\"}],\"name\":\"getVmId\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_addr\",\"type\":\"address\"}],\"name\":\"isAdmin\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"renounceOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"const\",\"type\":\"address\"}],\"name\":\"setConstant\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"taskId\",\"type\":\"string\"},{\"internalType\":\"address\",\"name\":\"creater\",\"type\":\"address\"}],\"name\":\"snatchTask\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"},{\"internalType\":\"uint8\",\"name\":\"\",\"type\":\"uint8\"}],\"name\":\"taskProgress\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"newOwner\",\"type\":\"address\"}],\"name\":\"transferOwnership\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"taskId\",\"type\":\"string\"},{\"internalType\":\"uint256\",\"name\":\"createStage\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"createProgress\",\"type\":\"uint256\"}],\"name\":\"updateVmCreateProgress\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]",
} }
// VmCreateABI is the input ABI used to generate the binding from. // VmCreateABI is the input ABI used to generate the binding from.
...@@ -210,35 +210,35 @@ func (_VmCreate *VmCreateCallerSession) Const() (common.Address, error) { ...@@ -210,35 +210,35 @@ func (_VmCreate *VmCreateCallerSession) Const() (common.Address, error) {
return _VmCreate.Contract.Const(&_VmCreate.CallOpts) return _VmCreate.Contract.Const(&_VmCreate.CallOpts)
} }
// GetTaskId is a free data retrieval call binding the contract method 0x13859688. // GetTaskId is a free data retrieval call binding the contract method 0xf8800fcc.
// //
// Solidity: function getTaskId() view returns(string) // Solidity: function getTaskId(uint8 start, uint8 count) view returns(string[] res)
func (_VmCreate *VmCreateCaller) GetTaskId(opts *bind.CallOpts) (string, error) { func (_VmCreate *VmCreateCaller) GetTaskId(opts *bind.CallOpts, start uint8, count uint8) ([]string, error) {
var out []interface{} var out []interface{}
err := _VmCreate.contract.Call(opts, &out, "getTaskId") err := _VmCreate.contract.Call(opts, &out, "getTaskId", start, count)
if err != nil { if err != nil {
return *new(string), err return *new([]string), err
} }
out0 := *abi.ConvertType(out[0], new(string)).(*string) out0 := *abi.ConvertType(out[0], new([]string)).(*[]string)
return out0, err return out0, err
} }
// GetTaskId is a free data retrieval call binding the contract method 0x13859688. // GetTaskId is a free data retrieval call binding the contract method 0xf8800fcc.
// //
// Solidity: function getTaskId() view returns(string) // Solidity: function getTaskId(uint8 start, uint8 count) view returns(string[] res)
func (_VmCreate *VmCreateSession) GetTaskId() (string, error) { func (_VmCreate *VmCreateSession) GetTaskId(start uint8, count uint8) ([]string, error) {
return _VmCreate.Contract.GetTaskId(&_VmCreate.CallOpts) return _VmCreate.Contract.GetTaskId(&_VmCreate.CallOpts, start, count)
} }
// GetTaskId is a free data retrieval call binding the contract method 0x13859688. // GetTaskId is a free data retrieval call binding the contract method 0xf8800fcc.
// //
// Solidity: function getTaskId() view returns(string) // Solidity: function getTaskId(uint8 start, uint8 count) view returns(string[] res)
func (_VmCreate *VmCreateCallerSession) GetTaskId() (string, error) { func (_VmCreate *VmCreateCallerSession) GetTaskId(start uint8, count uint8) ([]string, error) {
return _VmCreate.Contract.GetTaskId(&_VmCreate.CallOpts) return _VmCreate.Contract.GetTaskId(&_VmCreate.CallOpts, start, count)
} }
// GetVmCreateProgress is a free data retrieval call binding the contract method 0xb1870375. // GetVmCreateProgress is a free data retrieval call binding the contract method 0xb1870375.
...@@ -273,6 +273,37 @@ func (_VmCreate *VmCreateCallerSession) GetVmCreateProgress(taskId string) (*big ...@@ -273,6 +273,37 @@ func (_VmCreate *VmCreateCallerSession) GetVmCreateProgress(taskId string) (*big
return _VmCreate.Contract.GetVmCreateProgress(&_VmCreate.CallOpts, taskId) return _VmCreate.Contract.GetVmCreateProgress(&_VmCreate.CallOpts, taskId)
} }
// GetVmId is a free data retrieval call binding the contract method 0x256fa3b2.
//
// Solidity: function getVmId(string taskId) view returns(uint256)
func (_VmCreate *VmCreateCaller) GetVmId(opts *bind.CallOpts, taskId string) (*big.Int, error) {
var out []interface{}
err := _VmCreate.contract.Call(opts, &out, "getVmId", taskId)
if err != nil {
return *new(*big.Int), err
}
out0 := *abi.ConvertType(out[0], new(*big.Int)).(**big.Int)
return out0, err
}
// GetVmId is a free data retrieval call binding the contract method 0x256fa3b2.
//
// Solidity: function getVmId(string taskId) view returns(uint256)
func (_VmCreate *VmCreateSession) GetVmId(taskId string) (*big.Int, error) {
return _VmCreate.Contract.GetVmId(&_VmCreate.CallOpts, taskId)
}
// GetVmId is a free data retrieval call binding the contract method 0x256fa3b2.
//
// Solidity: function getVmId(string taskId) view returns(uint256)
func (_VmCreate *VmCreateCallerSession) GetVmId(taskId string) (*big.Int, error) {
return _VmCreate.Contract.GetVmId(&_VmCreate.CallOpts, taskId)
}
// IsAdmin is a free data retrieval call binding the contract method 0x24d7806c. // IsAdmin is a free data retrieval call binding the contract method 0x24d7806c.
// //
// Solidity: function isAdmin(address _addr) view returns(bool) // Solidity: function isAdmin(address _addr) view returns(bool)
...@@ -387,25 +418,25 @@ func (_VmCreate *VmCreateTransactorSession) AddAdmin(_admin common.Address) (*ty ...@@ -387,25 +418,25 @@ func (_VmCreate *VmCreateTransactorSession) AddAdmin(_admin common.Address) (*ty
return _VmCreate.Contract.AddAdmin(&_VmCreate.TransactOpts, _admin) return _VmCreate.Contract.AddAdmin(&_VmCreate.TransactOpts, _admin)
} }
// AddVirtualMachine is a paid mutator transaction binding the contract method 0xb3570a36. // AddVirtualMachine is a paid mutator transaction binding the contract method 0xb51f5bd7.
// //
// Solidity: function addVirtualMachine(string taskId, string callerIp, string cpuModel, uint64 cpuNum, uint64 cpuCores, string gpuModel, uint64 gpuNum, uint64 memNum, string os) returns() // Solidity: function addVirtualMachine(string taskId, string callerIp, string cpuModel, uint64 cpuNum, uint64 cpuCores, string gpuModel, uint64 gpuNum, uint64 memSize, string os, string vmName) returns()
func (_VmCreate *VmCreateTransactor) AddVirtualMachine(opts *bind.TransactOpts, taskId string, callerIp string, cpuModel string, cpuNum uint64, cpuCores uint64, gpuModel string, gpuNum uint64, memNum uint64, os string) (*types.Transaction, error) { func (_VmCreate *VmCreateTransactor) AddVirtualMachine(opts *bind.TransactOpts, taskId string, callerIp string, cpuModel string, cpuNum uint64, cpuCores uint64, gpuModel string, gpuNum uint64, memSize uint64, os string, vmName string) (*types.Transaction, error) {
return _VmCreate.contract.Transact(opts, "addVirtualMachine", taskId, callerIp, cpuModel, cpuNum, cpuCores, gpuModel, gpuNum, memNum, os) return _VmCreate.contract.Transact(opts, "addVirtualMachine", taskId, callerIp, cpuModel, cpuNum, cpuCores, gpuModel, gpuNum, memSize, os, vmName)
} }
// AddVirtualMachine is a paid mutator transaction binding the contract method 0xb3570a36. // AddVirtualMachine is a paid mutator transaction binding the contract method 0xb51f5bd7.
// //
// Solidity: function addVirtualMachine(string taskId, string callerIp, string cpuModel, uint64 cpuNum, uint64 cpuCores, string gpuModel, uint64 gpuNum, uint64 memNum, string os) returns() // Solidity: function addVirtualMachine(string taskId, string callerIp, string cpuModel, uint64 cpuNum, uint64 cpuCores, string gpuModel, uint64 gpuNum, uint64 memSize, string os, string vmName) returns()
func (_VmCreate *VmCreateSession) AddVirtualMachine(taskId string, callerIp string, cpuModel string, cpuNum uint64, cpuCores uint64, gpuModel string, gpuNum uint64, memNum uint64, os string) (*types.Transaction, error) { func (_VmCreate *VmCreateSession) AddVirtualMachine(taskId string, callerIp string, cpuModel string, cpuNum uint64, cpuCores uint64, gpuModel string, gpuNum uint64, memSize uint64, os string, vmName string) (*types.Transaction, error) {
return _VmCreate.Contract.AddVirtualMachine(&_VmCreate.TransactOpts, taskId, callerIp, cpuModel, cpuNum, cpuCores, gpuModel, gpuNum, memNum, os) return _VmCreate.Contract.AddVirtualMachine(&_VmCreate.TransactOpts, taskId, callerIp, cpuModel, cpuNum, cpuCores, gpuModel, gpuNum, memSize, os, vmName)
} }
// AddVirtualMachine is a paid mutator transaction binding the contract method 0xb3570a36. // AddVirtualMachine is a paid mutator transaction binding the contract method 0xb51f5bd7.
// //
// Solidity: function addVirtualMachine(string taskId, string callerIp, string cpuModel, uint64 cpuNum, uint64 cpuCores, string gpuModel, uint64 gpuNum, uint64 memNum, string os) returns() // Solidity: function addVirtualMachine(string taskId, string callerIp, string cpuModel, uint64 cpuNum, uint64 cpuCores, string gpuModel, uint64 gpuNum, uint64 memSize, string os, string vmName) returns()
func (_VmCreate *VmCreateTransactorSession) AddVirtualMachine(taskId string, callerIp string, cpuModel string, cpuNum uint64, cpuCores uint64, gpuModel string, gpuNum uint64, memNum uint64, os string) (*types.Transaction, error) { func (_VmCreate *VmCreateTransactorSession) AddVirtualMachine(taskId string, callerIp string, cpuModel string, cpuNum uint64, cpuCores uint64, gpuModel string, gpuNum uint64, memSize uint64, os string, vmName string) (*types.Transaction, error) {
return _VmCreate.Contract.AddVirtualMachine(&_VmCreate.TransactOpts, taskId, callerIp, cpuModel, cpuNum, cpuCores, gpuModel, gpuNum, memNum, os) return _VmCreate.Contract.AddVirtualMachine(&_VmCreate.TransactOpts, taskId, callerIp, cpuModel, cpuNum, cpuCores, gpuModel, gpuNum, memSize, os, vmName)
} }
// DelAdmin is a paid mutator transaction binding the contract method 0x62d91855. // DelAdmin is a paid mutator transaction binding the contract method 0x62d91855.
...@@ -429,6 +460,27 @@ func (_VmCreate *VmCreateTransactorSession) DelAdmin(_admin common.Address) (*ty ...@@ -429,6 +460,27 @@ func (_VmCreate *VmCreateTransactorSession) DelAdmin(_admin common.Address) (*ty
return _VmCreate.Contract.DelAdmin(&_VmCreate.TransactOpts, _admin) return _VmCreate.Contract.DelAdmin(&_VmCreate.TransactOpts, _admin)
} }
// FinishTask is a paid mutator transaction binding the contract method 0x6cb050ea.
//
// Solidity: function finishTask(address owner, string taskId, uint256 vmId) returns()
func (_VmCreate *VmCreateTransactor) FinishTask(opts *bind.TransactOpts, owner common.Address, taskId string, vmId *big.Int) (*types.Transaction, error) {
return _VmCreate.contract.Transact(opts, "finishTask", owner, taskId, vmId)
}
// FinishTask is a paid mutator transaction binding the contract method 0x6cb050ea.
//
// Solidity: function finishTask(address owner, string taskId, uint256 vmId) returns()
func (_VmCreate *VmCreateSession) FinishTask(owner common.Address, taskId string, vmId *big.Int) (*types.Transaction, error) {
return _VmCreate.Contract.FinishTask(&_VmCreate.TransactOpts, owner, taskId, vmId)
}
// FinishTask is a paid mutator transaction binding the contract method 0x6cb050ea.
//
// Solidity: function finishTask(address owner, string taskId, uint256 vmId) returns()
func (_VmCreate *VmCreateTransactorSession) FinishTask(owner common.Address, taskId string, vmId *big.Int) (*types.Transaction, error) {
return _VmCreate.Contract.FinishTask(&_VmCreate.TransactOpts, owner, taskId, vmId)
}
// RenounceOwnership is a paid mutator transaction binding the contract method 0x715018a6. // RenounceOwnership is a paid mutator transaction binding the contract method 0x715018a6.
// //
// Solidity: function renounceOwnership() returns() // Solidity: function renounceOwnership() returns()
...@@ -613,12 +665,13 @@ type VmCreateAddCreateVMInfoEvent struct { ...@@ -613,12 +665,13 @@ type VmCreateAddCreateVMInfoEvent struct {
GpuNum uint64 GpuNum uint64
MemNum uint64 MemNum uint64
Os string Os string
VmName string
Raw types.Log // Blockchain specific contextual infos Raw types.Log // Blockchain specific contextual infos
} }
// FilterAddCreateVMInfoEvent is a free log retrieval operation binding the contract event 0x7d25d4d054c4e119d70f7f809edd27dfdff08e176a4a4a3f25e7e7ad63d3398e. // FilterAddCreateVMInfoEvent is a free log retrieval operation binding the contract event 0x14cfc769ae51024fff38f2bdd079158750cf8a7676da49060b89e554166c9a2d.
// //
// Solidity: event AddCreateVMInfoEvent(string taskId, address owner, string callerIp, string cpuModel, uint64 cpuNum, uint64 cpuCores, string gpuModel, uint64 gpuNum, uint64 memNum, string os) // Solidity: event AddCreateVMInfoEvent(string taskId, address owner, string callerIp, string cpuModel, uint64 cpuNum, uint64 cpuCores, string gpuModel, uint64 gpuNum, uint64 memNum, string os, string vmName)
func (_VmCreate *VmCreateFilterer) FilterAddCreateVMInfoEvent(opts *bind.FilterOpts) (*VmCreateAddCreateVMInfoEventIterator, error) { func (_VmCreate *VmCreateFilterer) FilterAddCreateVMInfoEvent(opts *bind.FilterOpts) (*VmCreateAddCreateVMInfoEventIterator, error) {
logs, sub, err := _VmCreate.contract.FilterLogs(opts, "AddCreateVMInfoEvent") logs, sub, err := _VmCreate.contract.FilterLogs(opts, "AddCreateVMInfoEvent")
...@@ -628,9 +681,9 @@ func (_VmCreate *VmCreateFilterer) FilterAddCreateVMInfoEvent(opts *bind.FilterO ...@@ -628,9 +681,9 @@ func (_VmCreate *VmCreateFilterer) FilterAddCreateVMInfoEvent(opts *bind.FilterO
return &VmCreateAddCreateVMInfoEventIterator{contract: _VmCreate.contract, event: "AddCreateVMInfoEvent", logs: logs, sub: sub}, nil return &VmCreateAddCreateVMInfoEventIterator{contract: _VmCreate.contract, event: "AddCreateVMInfoEvent", logs: logs, sub: sub}, nil
} }
// WatchAddCreateVMInfoEvent is a free log subscription operation binding the contract event 0x7d25d4d054c4e119d70f7f809edd27dfdff08e176a4a4a3f25e7e7ad63d3398e. // WatchAddCreateVMInfoEvent is a free log subscription operation binding the contract event 0x14cfc769ae51024fff38f2bdd079158750cf8a7676da49060b89e554166c9a2d.
// //
// Solidity: event AddCreateVMInfoEvent(string taskId, address owner, string callerIp, string cpuModel, uint64 cpuNum, uint64 cpuCores, string gpuModel, uint64 gpuNum, uint64 memNum, string os) // Solidity: event AddCreateVMInfoEvent(string taskId, address owner, string callerIp, string cpuModel, uint64 cpuNum, uint64 cpuCores, string gpuModel, uint64 gpuNum, uint64 memNum, string os, string vmName)
func (_VmCreate *VmCreateFilterer) WatchAddCreateVMInfoEvent(opts *bind.WatchOpts, sink chan<- *VmCreateAddCreateVMInfoEvent) (event.Subscription, error) { func (_VmCreate *VmCreateFilterer) WatchAddCreateVMInfoEvent(opts *bind.WatchOpts, sink chan<- *VmCreateAddCreateVMInfoEvent) (event.Subscription, error) {
logs, sub, err := _VmCreate.contract.WatchLogs(opts, "AddCreateVMInfoEvent") logs, sub, err := _VmCreate.contract.WatchLogs(opts, "AddCreateVMInfoEvent")
...@@ -665,9 +718,9 @@ func (_VmCreate *VmCreateFilterer) WatchAddCreateVMInfoEvent(opts *bind.WatchOpt ...@@ -665,9 +718,9 @@ func (_VmCreate *VmCreateFilterer) WatchAddCreateVMInfoEvent(opts *bind.WatchOpt
}), nil }), nil
} }
// ParseAddCreateVMInfoEvent is a log parse operation binding the contract event 0x7d25d4d054c4e119d70f7f809edd27dfdff08e176a4a4a3f25e7e7ad63d3398e. // ParseAddCreateVMInfoEvent is a log parse operation binding the contract event 0x14cfc769ae51024fff38f2bdd079158750cf8a7676da49060b89e554166c9a2d.
// //
// Solidity: event AddCreateVMInfoEvent(string taskId, address owner, string callerIp, string cpuModel, uint64 cpuNum, uint64 cpuCores, string gpuModel, uint64 gpuNum, uint64 memNum, string os) // Solidity: event AddCreateVMInfoEvent(string taskId, address owner, string callerIp, string cpuModel, uint64 cpuNum, uint64 cpuCores, string gpuModel, uint64 gpuNum, uint64 memNum, string os, string vmName)
func (_VmCreate *VmCreateFilterer) ParseAddCreateVMInfoEvent(log types.Log) (*VmCreateAddCreateVMInfoEvent, error) { func (_VmCreate *VmCreateFilterer) ParseAddCreateVMInfoEvent(log types.Log) (*VmCreateAddCreateVMInfoEvent, error) {
event := new(VmCreateAddCreateVMInfoEvent) event := new(VmCreateAddCreateVMInfoEvent)
if err := _VmCreate.contract.UnpackLog(event, "AddCreateVMInfoEvent", log); err != nil { if err := _VmCreate.contract.UnpackLog(event, "AddCreateVMInfoEvent", log); err != nil {
......
...@@ -32,6 +32,7 @@ require ( ...@@ -32,6 +32,7 @@ require (
github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712 // indirect github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712 // indirect
github.com/elastic/go-elasticsearch/v6 v6.8.5 // indirect github.com/elastic/go-elasticsearch/v6 v6.8.5 // indirect
github.com/ethereum/go-ethereum v1.12.2 // indirect github.com/ethereum/go-ethereum v1.12.2 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/garyburd/redigo v1.6.4 // indirect github.com/garyburd/redigo v1.6.4 // indirect
github.com/go-ole/go-ole v1.2.1 // indirect github.com/go-ole/go-ole v1.2.1 // indirect
...@@ -55,6 +56,7 @@ require ( ...@@ -55,6 +56,7 @@ require (
github.com/lestrrat-go/strftime v1.0.6 // indirect github.com/lestrrat-go/strftime v1.0.6 // indirect
github.com/lib/pq v1.0.0 // indirect github.com/lib/pq v1.0.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/oschwald/geoip2-golang v1.9.0 // indirect github.com/oschwald/geoip2-golang v1.9.0 // indirect
github.com/oschwald/maxminddb-golang v1.11.0 // indirect github.com/oschwald/maxminddb-golang v1.11.0 // indirect
github.com/pelletier/go-toml v1.2.0 // indirect github.com/pelletier/go-toml v1.2.0 // indirect
......
package models
type ClientListRequest struct {
AuthKey string `json:"auth_key"`
Timestamp int64 `json:"timestamp"`
Start int64 `json:"start"`
Limit int64 `json:"limit"`
Order string `json:"order"`
}
type AddTunnelRequest struct {
Type string `json:"type"`
Remark string `json:"remark"`
Port string `json:"port"`
Target string `json:"target"`
ClientId string `json:"client_id"`
}
package models
type AuthKey struct {
CryptAuthKey string `json:"crypt_auth_key"`
CryptType string `json:"crypt_type"`
Status int64 `json:"status"`
}
type NpsOperateResp struct {
Msg string `json:"Msg"`
Status int64 `json:"Status"`
}
type UnixTime struct {
Timestamp int64 `json:"time"`
}
type NpsClientInfo struct {
Id int64 `json:"Id"`
Status bool `json:"Status"`
IsConnect bool `json:"IsConnect"`
RateLimit int64 `json:"RateLimit"`
VerifyKey string `json:"VerifyKey"`
Addr string `json:"Addr"`
}
type TcpTunnelInfo struct {
Id int64 `json:"Id"`
Port int64 `json:"Port"`
Mode string `json:"Mode"`
Status bool `json:"Status"`
RunStatus bool `json:"RunStatus"`
}
...@@ -16,7 +16,7 @@ type HeaderInfo struct { ...@@ -16,7 +16,7 @@ type HeaderInfo struct {
type VM struct { type VM struct {
NewId string `json:"newId"` // 克隆虚拟机模版新id NewId string `json:"newId"` // 克隆虚拟机模版新id
VmId string `json:"vmId"` // 虚拟机模版id VmId string `json:"vmId"` // 虚拟机模版id
Name string `json:"name"` SupportType int `json:"supportType"`
VmCfg *VmConfig `json:"vmConfig"` VmCfg *VmConfig `json:"vmConfig"`
User string `json:"user"` User string `json:"user"`
Password string `json:"password"` Password string `json:"password"`
...@@ -37,4 +37,15 @@ type VmConfig struct { ...@@ -37,4 +37,15 @@ type VmConfig struct {
GpuNum *big.Int `json:"gpuNum"` // 设置虚拟机的Gpu数量。 GpuNum *big.Int `json:"gpuNum"` // 设置虚拟机的Gpu数量。
StartDate time.Time `json:"startDate"` // 设置虚拟机的初始日期和时间。 StartDate time.Time `json:"startDate"` // 设置虚拟机的初始日期和时间。
Disk *big.Int `json:"disk"` Disk *big.Int `json:"disk"`
Name string `json:"name"`
}
type VmNetWork struct {
InternalIp string `json:"internal_ip"`
InSshPort int64 `json:"in_ssh_port"`
InVncPort int64 `json:"in_vnc_port"`
ExternalIp string `json:"external_ip"`
ExSshPort string `json:"ex_ssh_port"`
ExVncPort string `json:"ex_vnc_port"`
SupportType int64 `json:"support_type"`
} }
...@@ -24,6 +24,8 @@ type QemuList struct { ...@@ -24,6 +24,8 @@ type QemuList struct {
//Pid int64 `json:"pid"` //Pid int64 `json:"pid"`
MaxMem *big.Int `json:"maxMem"` MaxMem *big.Int `json:"maxMem"`
Template int64 `json:"template" default:"0"` Template int64 `json:"template" default:"0"`
Name string `json:"name"`
Uptime int64 `json:"uptime"`
} }
type NetWorkResult struct { type NetWorkResult struct {
......
...@@ -41,3 +41,8 @@ func TestIpAddressCondition(t *testing.T) { ...@@ -41,3 +41,8 @@ func TestIpAddressCondition(t *testing.T) {
condition := asyncLog.IsCreateVmCondition("13.38.146.66") condition := asyncLog.IsCreateVmCondition("13.38.146.66")
fmt.Println("condition:", condition) fmt.Println("condition:", condition)
} }
func TestNpsMappingInternalIp(t *testing.T) {
mapping := asyncLog.NpsMappingNetwork("192.168.1.117", 2)
fmt.Println("mapping:", mapping)
}
...@@ -2,8 +2,13 @@ package utils ...@@ -2,8 +2,13 @@ package utils
import ( import (
"context" "context"
"crypto/aes"
"crypto/cipher"
"crypto/ecdsa" "crypto/ecdsa"
"crypto/md5"
"encoding/hex"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"github.com/astaxie/beego" "github.com/astaxie/beego"
"github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/abi/bind"
...@@ -84,7 +89,12 @@ func GetIpAddr(ipAddress string) *Coordinates { ...@@ -84,7 +89,12 @@ func GetIpAddr(ipAddress string) *Coordinates {
log.Error(" geoip2 open error:", err) log.Error(" geoip2 open error:", err)
return nil return nil
} }
defer db.Close() defer func(db *geoip2.Reader) {
err := db.Close()
if err != nil {
log.Error(" geoip2 close error:", err)
}
}(db)
// 解析 IP 地址 // 解析 IP 地址
ip := net.ParseIP(ipAddress) ip := net.ParseIP(ipAddress)
// 查询 IP 地址的位置信息 // 查询 IP 地址的位置信息
...@@ -118,3 +128,44 @@ func CalculateDistance(coord1, coord2 *Coordinates) float64 { ...@@ -118,3 +128,44 @@ func CalculateDistance(coord1, coord2 *Coordinates) float64 {
distance := EarthRadius * c distance := EarthRadius * c
return distance return distance
} }
func GetAuthKey(encryptedText string, timestamp int64) string {
cryptKeyStr := beego.AppConfig.String("nps::auth_crypt_key")
cryptKey := []byte(cryptKeyStr)
encryptedTextByte, _ := hex.DecodeString(encryptedText)
// 创建解密器
decrypt, err := AesDecrypt(encryptedTextByte, cryptKey)
if err != nil {
return ""
}
log.Info("Decrypt test:", string(decrypt))
input := fmt.Sprintf("%s%d", string(decrypt), timestamp)
hash := md5.New()
hash.Write([]byte(input))
hashBytes := hash.Sum(nil)
md5Str := hex.EncodeToString(hashBytes)
log.Info("md5Str:", md5Str)
return md5Str
}
func PKCS5UnPadding(origData []byte) (error, []byte) {
length := len(origData)
unpadding := int(origData[length-1])
if (length - unpadding) < 0 {
return errors.New("len error"), nil
}
return nil, origData[:(length - unpadding)]
}
func AesDecrypt(crypted, key []byte) ([]byte, error) {
block, err := aes.NewCipher(key)
if err != nil {
return nil, err
}
blockSize := block.BlockSize()
blockMode := cipher.NewCBCDecrypter(block, key[:blockSize])
origData := make([]byte, len(crypted))
blockMode.CryptBlocks(origData, crypted)
err, origData = PKCS5UnPadding(origData)
return origData, err
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment