mirror of
https://github.com/XShengTech/MEGREZ.git
synced 2026-05-03 13:02:38 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1f55ecb649 | |||
| 87995f0572 | |||
| bb7b60352e | |||
| ef93c40361 | |||
| 716764a86d |
@@ -38,6 +38,8 @@ func forceDeleteHandler(ctx iris.Context) {
|
|||||||
|
|
||||||
if instance.FromAction == models.InstanceActionStop || instance.FromAction == models.InstanceActionPause || instance.FromAction == models.InstanceActionRestart {
|
if instance.FromAction == models.InstanceActionStop || instance.FromAction == models.InstanceActionPause || instance.FromAction == models.InstanceActionRestart {
|
||||||
redis.RawDB.IncrBy(ctx, "remain_gpu:server:"+strconv.Itoa(int(instance.ServerID)), int64(instance.GpuCount))
|
redis.RawDB.IncrBy(ctx, "remain_gpu:server:"+strconv.Itoa(int(instance.ServerID)), int64(instance.GpuCount))
|
||||||
|
}
|
||||||
|
if instance.FromAction != models.InstanceActionCreate {
|
||||||
redis.RawDB.IncrBy(ctx, "remain_volume:server:"+strconv.Itoa(int(instance.ServerID)), int64(instance.VolumeSize+30))
|
redis.RawDB.IncrBy(ctx, "remain_volume:server:"+strconv.Itoa(int(instance.ServerID)), int64(instance.VolumeSize+30))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package index
|
||||||
|
|
||||||
|
import "github.com/kataras/iris/v12"
|
||||||
|
|
||||||
|
func cors(ctx iris.Context) {
|
||||||
|
ctx.Header("Access-Control-Allow-Origin", "*")
|
||||||
|
ctx.Header("Access-Control-Allow-Methods", "GET")
|
||||||
|
ctx.Header("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
||||||
|
ctx.Header("Access-Control-Max-Age", "86400")
|
||||||
|
ctx.Header("Access-Control-Allow-Credentials", "true")
|
||||||
|
ctx.Next()
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func InitIndex(app *iris.Application) {
|
func InitIndex(app *iris.Application) {
|
||||||
|
app.Use(cors)
|
||||||
app.HandleDir("/", GetWebFS(), iris.DirOptions{
|
app.HandleDir("/", GetWebFS(), iris.DirOptions{
|
||||||
IndexName: "/index.html",
|
IndexName: "/index.html",
|
||||||
Compress: true,
|
Compress: true,
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ func control(serverID uint, data Data) (err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
redis.RawDB.IncrBy(ctx, "remain_gpu:server:"+strconv.Itoa(int(serverID)), int64(instance.GpuCount))
|
redis.RawDB.IncrBy(ctx, "remain_gpu:server:"+strconv.Itoa(int(serverID)), int64(instance.GpuCount))
|
||||||
database.DB.Model(&instance).Update("status", models.InstanceStatusFail).Update("from_action", models.InstanceActionRestart)
|
database.DB.Model(&instance).Update("status", models.InstanceStatusFail).Update("from_action", models.InstanceActionStart)
|
||||||
lc.Error("instance restart error: %v", err)
|
lc.Error("instance restart error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,6 @@ func modify(serverID uint, data Data) (err error) {
|
|||||||
err = instanceController.Patch(&instance, gpuCount, volumeSize, data.CpuOnly)
|
err = instanceController.Patch(&instance, gpuCount, volumeSize, data.CpuOnly)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
redis.RawDB.IncrBy(ctx, "remain_gpu:server:"+strconv.Itoa(int(serverID)), int64(gpuCount))
|
|
||||||
redis.RawDB.IncrBy(ctx, "remain_volume:server:"+strconv.Itoa(int(serverID)), int64(volumeSize-oldVolumeSize))
|
redis.RawDB.IncrBy(ctx, "remain_volume:server:"+strconv.Itoa(int(serverID)), int64(volumeSize-oldVolumeSize))
|
||||||
database.DB.Model(&instance).Update("status", models.InstanceStatusFail).Update("from_action", models.InstanceActionModify)
|
database.DB.Model(&instance).Update("status", models.InstanceStatusFail).Update("from_action", models.InstanceActionModify)
|
||||||
lc.Error("patch instance error: %v", err)
|
lc.Error("patch instance error: %v", err)
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ func createInstance(ip string, port int, apikey string,
|
|||||||
},
|
},
|
||||||
Env: []string{
|
Env: []string{
|
||||||
"NVIDIA_DRIVER_CAPABILITIES=video,compute,utility",
|
"NVIDIA_DRIVER_CAPABILITIES=video,compute,utility",
|
||||||
|
"NVIDIA_VISIBLE_DEVICES=none",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -87,10 +87,6 @@ func Patch(instance *models.Instances, gpuCount, volumeSize int, cpuOnly bool) (
|
|||||||
|
|
||||||
err = SetRootPassword(server.IP, server.Port, server.Apikey, instance.ContainerName, instance.SshPasswd)
|
err = SetRootPassword(server.IP, server.Port, server.Apikey, instance.ContainerName, instance.SshPasswd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
deleteInstance(server.IP, server.Port, server.Apikey, instance.ContainerName)
|
|
||||||
if instance.VolumeName != "" {
|
|
||||||
deleteVolume(server.IP, server.Port, server.Apikey, instance.VolumeName, false)
|
|
||||||
}
|
|
||||||
l.Error("set root password error: %v", err)
|
l.Error("set root password error: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -135,10 +131,6 @@ func Patch(instance *models.Instances, gpuCount, volumeSize int, cpuOnly bool) (
|
|||||||
|
|
||||||
err = SetRootPassword(server.IP, server.Port, server.Apikey, instance.ContainerName, instance.SshPasswd)
|
err = SetRootPassword(server.IP, server.Port, server.Apikey, instance.ContainerName, instance.SshPasswd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
deleteInstance(server.IP, server.Port, server.Apikey, instance.ContainerName)
|
|
||||||
if instance.VolumeName != "" {
|
|
||||||
deleteVolume(server.IP, server.Port, server.Apikey, instance.VolumeName, false)
|
|
||||||
}
|
|
||||||
l.Error("set root password error: %v", err)
|
l.Error("set root password error: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,10 +40,6 @@ func Restart(instance *models.Instances) (err error) {
|
|||||||
|
|
||||||
err = SetRootPassword(server.IP, server.Port, server.Apikey, instance.ContainerName, instance.SshPasswd)
|
err = SetRootPassword(server.IP, server.Port, server.Apikey, instance.ContainerName, instance.SshPasswd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
deleteInstance(server.IP, server.Port, server.Apikey, instance.ContainerName)
|
|
||||||
if instance.VolumeName != "" {
|
|
||||||
deleteVolume(server.IP, server.Port, server.Apikey, instance.VolumeName, false)
|
|
||||||
}
|
|
||||||
l.Error("set root password error: %v", err)
|
l.Error("set root password error: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user