mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix auto-merge conflict
This commit is contained in:
+44
-8
@@ -1,11 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/c-bata/go-prompt"
|
||||
prompt "github.com/c-bata/go-prompt"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/util/version"
|
||||
"yunion.io/x/structarg"
|
||||
@@ -117,18 +120,51 @@ func newClientSession(options *BaseOptions) (*mcclient.ClientSession, error) {
|
||||
options.Timeout,
|
||||
options.Debug,
|
||||
options.Insecure)
|
||||
token, err := client.Authenticate(options.OsUsername,
|
||||
options.OsPassword,
|
||||
options.OsDomainName,
|
||||
options.OsProjectName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
var cacheToken mcclient.TokenCredential
|
||||
cacheFile, err := os.Open("/tmp/OS_AUTH_CACHE_TOKEN")
|
||||
if err == nil && cacheFile != nil {
|
||||
fileInfo, _ := cacheFile.Stat()
|
||||
dur, err := time.ParseDuration("-24h")
|
||||
if fileInfo != nil && err == nil && fileInfo.ModTime().After(time.Now().Add(dur)) {
|
||||
bytesToken, err := ioutil.ReadAll(cacheFile)
|
||||
if err == nil {
|
||||
token := client.NewAuthTokenCredential()
|
||||
err := json.Unmarshal(bytesToken, token)
|
||||
if err != nil {
|
||||
fmt.Printf("Unmarshal token error:%s", err)
|
||||
} else {
|
||||
cacheToken = token
|
||||
}
|
||||
}
|
||||
cacheFile.Close()
|
||||
}
|
||||
}
|
||||
if cacheToken == nil {
|
||||
token, err := client.Authenticate(options.OsUsername,
|
||||
options.OsPassword,
|
||||
options.OsDomainName,
|
||||
options.OsProjectName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cacheToken = token
|
||||
bytesCacheToken, err := json.Marshal(cacheToken)
|
||||
if err != nil {
|
||||
fmt.Printf("Marshal token error:%s", err)
|
||||
} else {
|
||||
fo, _ := os.Create("/tmp/OS_AUTH_CACHE_TOKEN")
|
||||
fo.Write(bytesCacheToken)
|
||||
fo.Close()
|
||||
}
|
||||
} else {
|
||||
fmt.Println("******** Use Token Cache At /tmp/OS_AUTH_CACHE_TOKEN ********")
|
||||
}
|
||||
|
||||
session := client.NewSession(options.OsRegionName,
|
||||
options.OsZoneName,
|
||||
options.OsEndpointType,
|
||||
token,
|
||||
cacheToken,
|
||||
options.ApiVersion)
|
||||
return session, nil
|
||||
}
|
||||
|
||||
@@ -56,6 +56,11 @@ func Executor(s string) {
|
||||
e := parser.ParseArgs(utils.ArgsStringToArray(s), false)
|
||||
subcmd := parser.GetSubcommand()
|
||||
subparser := subcmd.GetSubParser()
|
||||
if args[0] == "--debug" {
|
||||
session.GetClient().SetDebug(true)
|
||||
} else {
|
||||
session.GetClient().SetDebug(false)
|
||||
}
|
||||
if e != nil {
|
||||
if subparser != nil {
|
||||
fmt.Print(subparser.Usage())
|
||||
|
||||
@@ -10,11 +10,12 @@ import (
|
||||
func init() {
|
||||
type DiskListOptions struct {
|
||||
BaseListOptions
|
||||
Unused bool `help:"Show unused disks"`
|
||||
Share bool `help:"Show Share storage disks"`
|
||||
Local bool `help:"Show Local storage disks"`
|
||||
Guest string `help:"Guest ID or name"`
|
||||
Storage string `help:"Storage ID or name"`
|
||||
Unused bool `help:"Show unused disks"`
|
||||
Share bool `help:"Show Share storage disks"`
|
||||
Local bool `help:"Show Local storage disks"`
|
||||
Guest string `help:"Guest ID or name"`
|
||||
Storage string `help:"Storage ID or name"`
|
||||
Provider string `help:"Provider for disk" choices:"Aliyun|VMware"`
|
||||
}
|
||||
R(&DiskListOptions{}, "disk-list", "List virtual disks", func(s *mcclient.ClientSession, suboptions *DiskListOptions) error {
|
||||
params := FetchPagingParams(suboptions.BaseListOptions)
|
||||
@@ -33,6 +34,9 @@ func init() {
|
||||
if len(suboptions.Storage) > 0 {
|
||||
params.Add(jsonutils.NewString(suboptions.Storage), "storage")
|
||||
}
|
||||
if len(suboptions.Provider) > 0 {
|
||||
params.Add(jsonutils.NewString(suboptions.Provider), "provider")
|
||||
}
|
||||
result, err := modules.Disks.List(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -59,7 +59,6 @@ func init() {
|
||||
})
|
||||
|
||||
type SecGroupRulesCreateOptions struct {
|
||||
NAME string `help:"Name of security group rule to create"`
|
||||
SECGROUP string `help:"Secgroup ID or Name" metavar:"Secgroup"`
|
||||
Direction string `help:"Direction of rule" choices:"in|out"`
|
||||
Action string `help:"Action of rule" choices:"allow|deny"`
|
||||
@@ -72,7 +71,6 @@ func init() {
|
||||
|
||||
R(&SecGroupRulesCreateOptions{}, "secgroup-rule-create", "Create all security group rule", func(s *mcclient.ClientSession, args *SecGroupRulesCreateOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.NAME), "name")
|
||||
if len(args.Desc) > 0 {
|
||||
params.Add(jsonutils.NewString(args.Desc), "description")
|
||||
}
|
||||
|
||||
@@ -315,7 +315,7 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&ServerOpsOptions{}, "server-sync", "Sync servers status", func(s *mcclient.ClientSession, args *ServerOpsOptions) error {
|
||||
R(&ServerOpsOptions{}, "server-sync", "Sync servers configures", func(s *mcclient.ClientSession, args *ServerOpsOptions) error {
|
||||
ret := modules.Servers.BatchPerformAction(s, args.ID, "sync", nil)
|
||||
printBatchResults(ret, modules.Servers.GetColumns(s))
|
||||
return nil
|
||||
@@ -343,8 +343,16 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&ServerOpsOptions{}, "server-reset", "Reset servers", func(s *mcclient.ClientSession, args *ServerOpsOptions) error {
|
||||
ret := modules.Servers.BatchPerformAction(s, args.ID, "reset", nil)
|
||||
type ServerResetOptions struct {
|
||||
ServerOpsOptions
|
||||
Hard bool `help:"Hard reset or not; default soft"`
|
||||
}
|
||||
R(&ServerResetOptions{}, "server-reset", "Reset servers", func(s *mcclient.ClientSession, args *ServerResetOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
if args.Hard {
|
||||
params.Add(jsonutils.JSONTrue, "is_hard")
|
||||
}
|
||||
ret := modules.Servers.BatchPerformAction(s, args.ID, "reset", params)
|
||||
printBatchResults(ret, modules.Servers.GetColumns(s))
|
||||
return nil
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user