本文整理汇总了Golang中github.com/matobet/verdi/env.Backend类的典型用法代码示例。如果您正苦于以下问题:Golang Backend类的具体用法?Golang Backend怎么用?Golang Backend使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Backend类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: addVM
func addVM(backend env.Backend, params *AddVmParams) (result interface{}, err error) {
redis := backend.Redis()
defer redis.Close()
nameLock := vmNameLock(params.Name)
nameLocked, err := redis.Lock(nameLock)
if err != nil || !nameLocked {
return nil, fmt.Errorf("VM with name '%s' is already being created", params.Name)
}
defer redis.Unlock(nameLock)
existing, err := redis.GetString("q:VM:name:" + params.Name)
if existing != "" {
return nil, fmt.Errorf("VM with name '%s' already exists", params.Name)
}
vm := &model.VM{
ID: model.NewGUID(),
Name: params.Name,
MemSizeMB: params.MemSizeMB,
}
tx := redis.Tx().Begin()
tx.Put(vm)
err = tx.Commit()
return "Created", err
}
开发者ID:matobet,项目名称:verdi,代码行数:28,代码来源:global.go
示例2: removeHostFromCluster
func removeHostFromCluster(backend env.Backend, params ClusterHostParams) (result interface{}, err error) {
conn := backend.Redis()
defer conn.Close()
hostID := config.Conf.HostID.String()
conn.Send("MULTI")
conn.Send("SREM", "Cluster:"+params.ClusterID, hostID)
conn.Send("SREM", "Host:"+hostID+":clusters", params.ClusterID)
_, err = conn.Do("EXEC")
scheduler.StopListen(backend, params.ClusterID)
return "Removed", err
}
开发者ID:matobet,项目名称:verdi,代码行数:14,代码来源:host.go
示例3: addHostToCluster
func addHostToCluster(backend env.Backend, params ClusterHostParams) (result interface{}, err error) {
conn := backend.Redis()
defer conn.Close()
hostID := config.Conf.HostID.String()
conn.Send("MULTI")
conn.Send("SADD", "Cluster:"+params.ClusterID, hostID)
conn.Send("SADD", "Host:"+hostID+":clusters", params.ClusterID)
_, err = conn.Do("EXEC")
go scheduler.Listen(backend, params.ClusterID)
return "Added", err
}
开发者ID:matobet,项目名称:verdi,代码行数:15,代码来源:host.go
示例4: Listen
func Listen(backend env.Backend, queue string) {
conn := backend.Redis()
defer conn.Close()
log.Println("Started listening on queue:", queue)
for {
values, err := redis.Values(conn.Do("BRPOP", queue, 0))
if err != nil {
log.Fatal(err)
}
body := values[1].([]byte)
var request Request
err = json.Unmarshal(body, &request)
if err != nil {
fmt.Println("command.Listen: received malformed response. Skipping.")
continue
}
id := request.ID
if id == "" {
fmt.Println("command.Listen: Received a command without 'id'. Skipping")
continue
}
name := request.Name
if name == "" {
respondError(conn, id, "Received a command without 'name'")
continue
}
cmd := commands[name]
if cmd == nil {
respondError(conn, id, "Unknown command")
continue
}
result, err := invokeCommandHandler(backend, cmd.handler, request.Params)
if err != nil {
respondError(conn, id, err.Error())
} else {
respondSuccess(conn, id, result)
}
}
}
开发者ID:matobet,项目名称:verdi,代码行数:47,代码来源:cmd.go
示例5: removeVM
func removeVM(backend env.Backend, params *IDParams) (result interface{}, err error) {
conn := backend.Redis()
defer conn.Close()
exists, err := conn.Exists("VM:" + params.ID.String())
if err != nil {
return
}
if !exists {
return nil, fmt.Errorf("VM with ID '%s' does not exist", params.ID)
}
tx := conn.Tx().Begin()
tx.Delete(&model.VM{ID: params.ID})
err = tx.Commit()
return "Removed", err
}
开发者ID:matobet,项目名称:verdi,代码行数:18,代码来源:global.go
示例6: runVM
func runVM(backend env.Backend, params *IDParams) (result interface{}, err error) {
conn := backend.Redis()
defer conn.Close()
ok, err := conn.Exists("VM:" + params.ID.String())
if err != nil {
return
}
if !ok {
return nil, fmt.Errorf("VM with ID '%s' does not exist", params.ID)
}
vm := &model.VM{ID: params.ID}
err = conn.Get(vm)
if err != nil {
return
}
err = backend.Virt().StartVM(vm)
return "Started", err
}
开发者ID:matobet,项目名称:verdi,代码行数:20,代码来源:global.go
示例7: Run
func Run(backend env.Backend, name string, params map[string]interface{}) (result map[string]interface{}, err error) {
cmd := commands[name]
if cmd == nil {
return nil, fmt.Errorf(`command.Run: Unknown command: "%s"`, name)
}
request := Request{
Name: name,
ID: uuid.NewV4().String(),
Params: params,
}
queue, err := queueByClass(cmd.Class, params)
if err != nil {
return nil, err
}
conn := backend.Redis()
defer conn.Close()
requestBody, err := json.Marshal(request)
if err != nil {
return nil, err
}
_, err = conn.Do("LPUSH", queue, requestBody)
if err != nil {
return nil, err
}
reply := replyQueue(request.ID)
values, err := redis.Values(conn.Do("BRPOP", reply, config.Conf.CommandTimeout))
if err != nil || values[0] == nil {
return nil, TimedOut
}
response := values[1].([]byte)
err = json.Unmarshal(response, &result)
return
}
开发者ID:matobet,项目名称:verdi,代码行数:40,代码来源:cmd.go
示例8: updateVM
func updateVM(backend env.Backend, params *UpdateVmParams) (result interface{}, err error) {
conn := backend.Redis()
defer conn.Close()
ok, err := conn.Exists("VM:" + params.ID.String())
if err != nil {
return
}
if !ok {
return nil, fmt.Errorf("VM with ID '%s' does not exist", params.ID)
}
vm := &model.VM{
ID: params.ID,
Name: params.Name,
}
tx := conn.Tx().Begin()
tx.Put(vm)
err = tx.Commit()
return "Updated", err
}
开发者ID:matobet,项目名称:verdi,代码行数:22,代码来源:global.go
注:本文中的github.com/matobet/verdi/env.Backend类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论