Skip to content

Commit

Permalink
'scw run --gateway' now creates a server without public ip address (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Jul 20, 2015
1 parent 2441f03 commit 5d3ed41
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ $ scw inspect myserver | jq '.[0].public_ip.address'

#### Features

* No entry
* `scw run --gateway ...` or `SCW_GATEWAY="..." scw run ...` now creates a server without public ip address ([#74](https://github.com/scaleway/scaleway-cli/issues/74))

#### Fixes

Expand Down
3 changes: 3 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,9 @@ type ScalewayServerDefinition struct {
// Volumes are the attached volumes
Volumes map[string]string `json:"volumes,omitempty"`

// DynamicIPRequired is a flag that defines a server with a dynamic ip address attached
DynamicIPRequired *bool `json:"dynamic_ip_required,omitempty"`

// Bootscript is the bootscript used by the server
Bootscript *string `json:"bootscript"`

Expand Down
6 changes: 4 additions & 2 deletions api/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,16 @@ func InspectIdentifiers(api *ScalewayAPI, ci chan ScalewayResolvedIdentifier, cj
}

// CreateServer creates a server using API based on typical server fields
func CreateServer(api *ScalewayAPI, imageName string, name string, bootscript string, env string, additionalVolumes string) (string, error) {
func CreateServer(api *ScalewayAPI, imageName string, name string, bootscript string, env string, additionalVolumes string, dynamicIPRequired bool) (string, error) {
if name == "" {
name = strings.Replace(namesgenerator.GetRandomName(0), "_", "-", -1)
}

var server ScalewayServerDefinition
server.Volumes = make(map[string]string)

server.DynamicIPRequired = &dynamicIPRequired

server.Tags = []string{}
if env != "" {
server.Tags = strings.Split(env, " ")
Expand Down Expand Up @@ -292,7 +294,7 @@ func CreateServer(api *ScalewayAPI, imageName string, name string, bootscript st

serverID, err := api.PostServer(server)
if err != nil {
return "", nil
return "", err
}

// For inherited volumes, we prefix the name with server hostname
Expand Down
2 changes: 1 addition & 1 deletion commands/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func runCreate(cmd *types.Command, args []string) {
cmd.PrintShortUsage()
}

serverID, err := api.CreateServer(cmd.API, args[0], createName, createBootscript, createEnv, createVolume)
serverID, err := api.CreateServer(cmd.API, args[0], createName, createBootscript, createEnv, createVolume, true)

if err != nil {
log.Fatalf("Failed to create server: %v", err)
Expand Down
10 changes: 6 additions & 4 deletions commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,14 @@ func runRun(cmd *types.Command, args []string) {
log.Fatalf("Conflicting options: -d and COMMAND")
}

if runGateway == "" {
runGateway = os.Getenv("SCW_GATEWAY")
}

// create IMAGE
log.Debugf("Creating a new server")
serverID, err := api.CreateServer(cmd.API, args[0], runCreateName, runCreateBootscript, runCreateEnv, runCreateVolume)
dynamicIPRequired := runGateway == ""
serverID, err := api.CreateServer(cmd.API, args[0], runCreateName, runCreateBootscript, runCreateEnv, runCreateVolume, dynamicIPRequired)
if err != nil {
log.Fatalf("Failed to create server: %v", err)
}
Expand Down Expand Up @@ -101,9 +106,6 @@ func runRun(cmd *types.Command, args []string) {
}
} else {
// Resolve gateway
if runGateway == "" {
runGateway = os.Getenv("SCW_GATEWAY")
}
gateway, err := api.ResolveGateway(cmd.API, runGateway)
if err != nil {
log.Fatalf("Cannot resolve Gateway '%s': %v", runGateway, err)
Expand Down

0 comments on commit 5d3ed41

Please sign in to comment.