func TestSetConfigFromFlagsWithConfigFile(t *testing.T) { driver := NewDriver("default", "path") checkFlags := &drivers.CheckDriverOptions{ FlagsValues: map[string]interface{}{ "sakuracloud-access-token": "token", "sakuracloud-access-token-secret": "secret", }, CreateFlags: driver.GetCreateFlags(), } client := cli.NewClient() client.SetConfigValue("region", "tk1a") defer os.RemoveAll(client.GetDriversDir()) driver.SetConfigFromFlags(checkFlags) //assert.NoError(t, err) assert.Empty(t, checkFlags.InvalidFlags) //drv := driver.(*Driver) //assert.Equal(t, drv.Client.Region, "tk1a") }
# eval $(docker-machine-driver-sakuracloud clear %s) ` ) var clearCommand = cli.Command{ Name: "clear", Usage: fmt.Sprintf(clearUsageFormat, clearUsageParamName), Flags: []cli.Flag{ cli.BoolFlag{ Name: "all, a", Usage: "clear all config", }, }, Action: func(c *cli.Context) { cnt := len(c.Args()) client := sakura_cli.NewClient() targetNames := []string{} if c.Bool("all") { opts := client.ListOptions() for _, opt := range opts { targetNames = append(targetNames, opt.KeyName()) } } else { if cnt == 0 { fmt.Println(c.Command.Usage) return } optionName := c.Args()[0] option := client.GetOption(optionName)
// SetConfigFromFlags create config values from flags func (d *Driver) SetConfigFromFlags(srcFlags drivers.DriverOptions) error { cliClient := cli.NewClient() flags := cliClient.GetDriverOptions(srcFlags) d.Client = api.NewAPIClient( flags.String("sakuracloud-access-token"), flags.String("sakuracloud-access-token-secret"), flags.String("sakuracloud-region"), ) d.SwarmMaster = flags.Bool("swarm-master") d.SwarmHost = flags.String("swarm-host") d.SwarmDiscovery = flags.String("swarm-discovery") d.SSHUser = "******" d.SSHPort = 22 d.SSHKey = flags.String("sakuracloud-ssh-key") if err := d.getClient().ValidateClientConfig(); err != nil { return err } d.serverConfig = &spec.SakuraServerConfig{ HostName: "", Core: flags.Int("sakuracloud-core"), MemorySize: flags.Int("sakuracloud-memory-size"), ConnectedSwitch: flags.String("sakuracloud-connected-switch"), PrivateIP: flags.String("sakuracloud-private-ip"), PrivateIPSubnetMask: flags.String("sakuracloud-private-ip-subnet-mask"), PrivateIPOnly: flags.Bool("sakuracloud-private-ip-only"), Gateway: flags.String("sakuracloud-gateway"), DiskPlan: flags.String("sakuracloud-disk-plan"), DiskSize: flags.Int("sakuracloud-disk-size"), DiskName: flags.String("sakuracloud-disk-name"), DiskConnection: flags.String("sakuracloud-disk-connection"), Group: flags.String("sakuracloud-group"), AutoReboot: flags.Bool("sakuracloud-auto-reboot"), IgnoreVirtioNet: flags.Bool("sakuracloud-ignore-virtio-net"), PacketFilter: flags.String("sakuracloud-packet-filter"), PrivatePacketFilter: flags.String("sakuracloud-private-packet-filter"), EnablePWAuth: flags.Bool("sakuracloud-enable-password-auth"), } if d.serverConfig.HostName == "" { d.serverConfig.HostName = d.GetMachineName() } if d.serverConfig.IsDiskNameDefault() { d.serverConfig.DiskName = d.GetMachineName() } if d.serverConfig.PrivateIPOnly { d.IPAddress = d.serverConfig.PrivateIP } if d.serverConfig.DiskSourceArchiveID == "" { archiveID, err := d.getClient().GetUbuntuArchiveID() if err != nil { return err } d.serverConfig.DiskSourceArchiveID = archiveID } d.EnginePort = flags.Int("sakuracloud-engine-port") d.DNSZone = flags.String("sakuracloud-dns-zone") d.GSLB = flags.String("sakuracloud-gslb") return validateSakuraServerConfig(d.Client, d.serverConfig) }