mirror of
https://github.com/rancher/os.git
synced 2025-09-04 08:14:21 +00:00
gofmt
This commit is contained in:
@@ -37,13 +37,13 @@ func Main() {
|
||||
// Action: reload,
|
||||
//},
|
||||
{
|
||||
Name: "os",
|
||||
Usage: "operating system upgrade/downgrade",
|
||||
Name: "os",
|
||||
Usage: "operating system upgrade/downgrade",
|
||||
Subcommands: osSubcommands(),
|
||||
},
|
||||
{
|
||||
Name: "tlsconf",
|
||||
Usage: "setup tls configuration",
|
||||
Name: "tlsconf",
|
||||
Usage: "setup tls configuration",
|
||||
Subcommands: tlsConfCommands(),
|
||||
},
|
||||
}
|
||||
|
@@ -182,7 +182,7 @@ func getOrSetVal(args string, data map[interface{}]interface{}, value interface{
|
||||
for i, part := range parts {
|
||||
val, ok := data[part]
|
||||
last := i+1 == len(parts)
|
||||
|
||||
|
||||
if last && value != nil {
|
||||
if s, ok := value.(string); ok {
|
||||
value = config.DummyMarshall(s)
|
||||
|
@@ -30,27 +30,27 @@ func osSubcommands() []cli.Command {
|
||||
Action: osUpgrade,
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "stage, s",
|
||||
Name: "stage, s",
|
||||
Usage: "Only stage the new upgrade, don't apply it",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "image, i",
|
||||
Name: "image, i",
|
||||
Usage: "upgrade to a certain image",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "channel, c",
|
||||
Name: "channel, c",
|
||||
Usage: "upgrade to the latest in a specific channel",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "list",
|
||||
Usage: "list the current available versions",
|
||||
Name: "list",
|
||||
Usage: "list the current available versions",
|
||||
Action: osMetaDataGet,
|
||||
},
|
||||
{
|
||||
Name: "rollback",
|
||||
Usage: "rollback to the previous version",
|
||||
Name: "rollback",
|
||||
Usage: "rollback to the previous version",
|
||||
Action: osRollback,
|
||||
},
|
||||
}
|
||||
@@ -65,9 +65,9 @@ func osRollback(c *cli.Context) {
|
||||
|
||||
fileReader := bufio.NewScanner(file)
|
||||
line := " "
|
||||
for ; line[len(line)-1:] != "*"; {
|
||||
for line[len(line)-1:] != "*" {
|
||||
if !fileReader.Scan() {
|
||||
log.Error("Current version not indicated in "+ osVersionsFile)
|
||||
log.Error("Current version not indicated in " + osVersionsFile)
|
||||
}
|
||||
line = fileReader.Text()
|
||||
}
|
||||
@@ -79,9 +79,10 @@ func osRollback(c *cli.Context) {
|
||||
|
||||
startUpgradeContainer(line, false)
|
||||
}
|
||||
|
||||
|
||||
func osMetaDataGet(c *cli.Context) {
|
||||
osChannel, ok := getChannelUrl("meta"); if !ok {
|
||||
osChannel, ok := getChannelUrl("meta")
|
||||
if !ok {
|
||||
log.Fatal("unrecognized channel meta")
|
||||
}
|
||||
resp, err := http.Get(osChannel)
|
||||
@@ -113,7 +114,7 @@ func osUpgrade(c *cli.Context) {
|
||||
|
||||
func startUpgradeContainer(image string, stage bool) {
|
||||
container := docker.NewContainer(config.DOCKER_SYSTEM_HOST, &config.ContainerConfig{
|
||||
Cmd: "--name=upgrade " +
|
||||
Cmd: "--name=upgrade " +
|
||||
"--privileged " +
|
||||
"--net=host " +
|
||||
"--ipc=host " +
|
||||
@@ -140,7 +141,7 @@ func getLatestImage(channel string) (string, error) {
|
||||
data, err := getConfigData()
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "", err
|
||||
}
|
||||
|
||||
var pivot string
|
||||
@@ -153,15 +154,16 @@ func getLatestImage(channel string) (string, error) {
|
||||
}
|
||||
|
||||
switch currentChannel := val.(type) {
|
||||
case string:
|
||||
pivot = currentChannel
|
||||
default:
|
||||
return "", errors.New("invalid format of rancherctl config get os_upgrade_channel")
|
||||
case string:
|
||||
pivot = currentChannel
|
||||
default:
|
||||
return "", errors.New("invalid format of rancherctl config get os_upgrade_channel")
|
||||
}
|
||||
} else {
|
||||
pivot = channel
|
||||
}
|
||||
osChannel, ok := getChannelUrl(pivot); if !ok {
|
||||
osChannel, ok := getChannelUrl(pivot)
|
||||
if !ok {
|
||||
return "", errors.New("unrecognized channel " + pivot)
|
||||
}
|
||||
resp, err := http.Get(osChannel)
|
||||
@@ -184,14 +186,13 @@ func parseBody(body []byte, channel string) string {
|
||||
|
||||
func getChannelUrl(channel string) (string, bool) {
|
||||
if osChannels == nil {
|
||||
osChannels = map[string]string {
|
||||
"stable" : "",
|
||||
"alpha" : "",
|
||||
"beta" : "",
|
||||
"meta" : "",
|
||||
osChannels = map[string]string{
|
||||
"stable": "",
|
||||
"alpha": "",
|
||||
"beta": "",
|
||||
"meta": "",
|
||||
}
|
||||
}
|
||||
channel, ok := osChannels[channel];
|
||||
channel, ok := osChannels[channel]
|
||||
return channel, ok
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
package control
|
||||
package control
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -10,32 +10,32 @@ import (
|
||||
)
|
||||
|
||||
func tlsConfCommands() []cli.Command {
|
||||
return []cli.Command {
|
||||
return []cli.Command{
|
||||
{
|
||||
Name: "create",
|
||||
Usage: "use it to create a new set of tls configuration certs and keys or upload existing ones",
|
||||
Name: "create",
|
||||
Usage: "use it to create a new set of tls configuration certs and keys or upload existing ones",
|
||||
Action: tlsConfCreate,
|
||||
Flags: []cli.Flag {
|
||||
cli.StringFlag {
|
||||
Name: "cakey",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "cakey",
|
||||
Usage: "path to existing certificate authority key (only use with --generate)",
|
||||
},
|
||||
cli.StringFlag {
|
||||
Name: "ca",
|
||||
cli.StringFlag{
|
||||
Name: "ca",
|
||||
Usage: "path to existing certificate authority (only use with --genreate)",
|
||||
},
|
||||
cli.BoolFlag {
|
||||
Name: "generate, g",
|
||||
cli.BoolFlag{
|
||||
Name: "generate, g",
|
||||
Usage: "generate the client key and client cert from existing ca and cakey",
|
||||
},
|
||||
cli.StringFlag {
|
||||
Name: "outDir, o",
|
||||
cli.StringFlag{
|
||||
Name: "outDir, o",
|
||||
Usage: "the output directory to save the generated certs or keys",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func tlsConfCreate(c *cli.Context) {
|
||||
name := "rancher"
|
||||
@@ -52,18 +52,18 @@ func tlsConfCreate(c *cli.Context) {
|
||||
if val := c.String("outDir"); val != "" {
|
||||
outDir = val
|
||||
}
|
||||
|
||||
|
||||
if c.Bool("generate") {
|
||||
generateCaCerts = false
|
||||
}
|
||||
|
||||
|
||||
if val := c.String("cakey"); val != "" {
|
||||
inputCaKey = val
|
||||
}
|
||||
|
||||
if val := c.String("ca"); val != "" {
|
||||
inputCaCert = val
|
||||
}
|
||||
}
|
||||
|
||||
caCertPath = filepath.Join(outDir, caCertPath)
|
||||
caKeyPath = filepath.Join(outDir, caKeyPath)
|
||||
@@ -100,7 +100,6 @@ func tlsConfCreate(c *cli.Context) {
|
||||
serverKeyPath = "client-key.pem"
|
||||
}
|
||||
|
||||
|
||||
serverCertPath = filepath.Join(outDir, serverCertPath)
|
||||
serverKeyPath = filepath.Join(outDir, serverKeyPath)
|
||||
|
||||
|
@@ -8,8 +8,8 @@ import (
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/fsouza/go-dockerclient"
|
||||
log "github.com/Sirupsen/logrus"
|
||||
"github.com/fsouza/go-dockerclient"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -20,7 +20,7 @@ const (
|
||||
func PowerOff() {
|
||||
if os.Geteuid() != 0 {
|
||||
log.Info("poweroff: Permission Denied")
|
||||
return
|
||||
return
|
||||
}
|
||||
syscall.Sync()
|
||||
reboot(syscall.LINUX_REBOOT_CMD_POWER_OFF)
|
||||
|
Reference in New Issue
Block a user