Skip to content

Commit b734ff5

Browse files
author
Quentin Perez
authored
Merge pull request #424 from QuentinPerez/add-zoneid
Add zoneid
2 parents cf9a0b3 + 5ba784a commit b734ff5

File tree

3 files changed

+29
-23
lines changed

3 files changed

+29
-23
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1203,11 +1203,12 @@ $ scw inspect myserver | jq '.[0].public_ip.address'
12031203

12041204
### master (unreleased)
12051205

1206+
* API: Add ZoneID field in server location
1207+
* `scw image -a -f type=volume` fix unmarshal error on size field
12061208
* `scw ps` do not display empty server with --filter
12071209

12081210
### v1.10.1 (2016-10-24)
12091211

1210-
* `scw image -a -f type=volume` fix unmarshal error on size field
12111212
* `scw login` fix CheckCredentials ([418](https://github.com/scaleway/scaleway-cli/issues/418))
12121213

12131214
View full [commits list](https://github.com/scaleway/scaleway-cli/compare/v1.10...v1.10.1)

pkg/api/api.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ type ScalewayServer struct {
533533
Hypervisor string `json:"hypervisor_id,omitempty"`
534534
Blade string `json:"blade_id,omitempty"`
535535
Node string `json:"node_id,omitempty"`
536+
ZoneID string `json:"zone_id,omitempty"`
536537
} `json:"location,omitempty"`
537538

538539
IPV6 *ScalewayIPV6Definition `json:"ipv6,omitempty"`
@@ -1128,10 +1129,10 @@ func (s *ScalewayAPI) GetServers(all bool, limit int) (*[]ScalewayServer, error)
11281129
return nil, err
11291130
}
11301131
for i, server := range servers.Servers {
1131-
// FIXME region, arch, owner, title
1132+
// FIXME arch, owner, title
11321133
servers.Servers[i].DNSPublic = server.Identifier + URLPublicDNS
11331134
servers.Servers[i].DNSPrivate = server.Identifier + URLPrivateDNS
1134-
s.Cache.InsertServer(server.Identifier, "fr-1", server.Arch, server.Organization, server.Name)
1135+
s.Cache.InsertServer(server.Identifier, server.Location.ZoneID, server.Arch, server.Organization, server.Name)
11351136
}
11361137
// FIXME: when API limit is ready, remove the following code
11371138
if limit > 0 && limit < len(servers.Servers) {
@@ -1177,10 +1178,10 @@ func (s *ScalewayAPI) GetServer(serverID string) (*ScalewayServer, error) {
11771178
if err = json.Unmarshal(body, &oneServer); err != nil {
11781179
return nil, err
11791180
}
1180-
// FIXME region, arch, owner, title
1181+
// FIXME arch, owner, title
11811182
oneServer.Server.DNSPublic = oneServer.Server.Identifier + URLPublicDNS
11821183
oneServer.Server.DNSPrivate = oneServer.Server.Identifier + URLPrivateDNS
1183-
s.Cache.InsertServer(oneServer.Server.Identifier, "fr-1", oneServer.Server.Arch, oneServer.Server.Organization, oneServer.Server.Name)
1184+
s.Cache.InsertServer(oneServer.Server.Identifier, oneServer.Server.Location.ZoneID, oneServer.Server.Arch, oneServer.Server.Organization, oneServer.Server.Name)
11841185
return &oneServer.Server, nil
11851186
}
11861187

@@ -1239,8 +1240,8 @@ func (s *ScalewayAPI) PostServer(definition ScalewayServerDefinition) (string, e
12391240
if err = json.Unmarshal(body, &server); err != nil {
12401241
return "", err
12411242
}
1242-
// FIXME region, arch, owner, title
1243-
s.Cache.InsertServer(server.Server.Identifier, "fr-1", server.Server.Arch, server.Server.Organization, server.Server.Name)
1243+
// FIXME arch, owner, title
1244+
s.Cache.InsertServer(server.Server.Identifier, server.Server.Location.ZoneID, server.Server.Arch, server.Server.Organization, server.Server.Name)
12441245
return server.Server.Identifier, nil
12451246
}
12461247

@@ -1299,8 +1300,8 @@ func (s *ScalewayAPI) PostSnapshot(volumeID string, name string) (string, error)
12991300
if err = json.Unmarshal(body, &snapshot); err != nil {
13001301
return "", err
13011302
}
1302-
// FIXME region, arch, owner, title
1303-
s.Cache.InsertSnapshot(snapshot.Snapshot.Identifier, "fr-1", "", snapshot.Snapshot.Organization, snapshot.Snapshot.Name)
1303+
// FIXME arch, owner, title
1304+
s.Cache.InsertSnapshot(snapshot.Snapshot.Identifier, "", "", snapshot.Snapshot.Organization, snapshot.Snapshot.Name)
13041305
return snapshot.Snapshot.Identifier, nil
13051306
}
13061307

@@ -1334,7 +1335,7 @@ func (s *ScalewayAPI) PostImage(volumeID string, name string, bootscript string,
13341335
return "", err
13351336
}
13361337
// FIXME region, arch, owner, title
1337-
s.Cache.InsertImage(image.Image.Identifier, "fr-1", image.Image.Arch, image.Image.Organization, image.Image.Name, "")
1338+
s.Cache.InsertImage(image.Image.Identifier, "", image.Image.Arch, image.Image.Organization, image.Image.Name, "")
13381339
return image.Image.Identifier, nil
13391340
}
13401341

@@ -1491,7 +1492,7 @@ func (s *ScalewayAPI) GetImages() (*[]MarketImage, error) {
14911492
return nil, err
14921493
}
14931494
for _, orgaImage := range OrgaImages.Images {
1494-
s.Cache.InsertImage(orgaImage.Identifier, "fr-1", orgaImage.Arch, orgaImage.Organization, orgaImage.Name, "")
1495+
s.Cache.InsertImage(orgaImage.Identifier, "", orgaImage.Arch, orgaImage.Organization, orgaImage.Name, "")
14951496
images.Images = append(images.Images, MarketImage{
14961497
Categories: []string{"MyImages"},
14971498
CreationDate: orgaImage.CreationDate,
@@ -1510,7 +1511,7 @@ func (s *ScalewayAPI) GetImages() (*[]MarketImage, error) {
15101511
{
15111512
Arch: orgaImage.Arch,
15121513
ID: orgaImage.Identifier,
1513-
Zone: "fr-1",
1514+
Zone: "",
15141515
},
15151516
},
15161517
},
@@ -1542,7 +1543,7 @@ func (s *ScalewayAPI) GetImage(imageID string) (*ScalewayImage, error) {
15421543
return nil, err
15431544
}
15441545
// FIXME region, arch, owner, title
1545-
s.Cache.InsertImage(oneImage.Image.Identifier, "fr-1", oneImage.Image.Arch, oneImage.Image.Organization, oneImage.Image.Name, "")
1546+
s.Cache.InsertImage(oneImage.Image.Identifier, "", oneImage.Image.Arch, oneImage.Image.Organization, oneImage.Image.Name, "")
15461547
return &oneImage.Image, nil
15471548
}
15481549

@@ -1621,7 +1622,7 @@ func (s *ScalewayAPI) GetSnapshots() (*[]ScalewaySnapshot, error) {
16211622
}
16221623
for _, snapshot := range snapshots.Snapshots {
16231624
// FIXME region, arch, owner, title
1624-
s.Cache.InsertSnapshot(snapshot.Identifier, "fr-1", "", snapshot.Organization, snapshot.Name)
1625+
s.Cache.InsertSnapshot(snapshot.Identifier, "", "", snapshot.Organization, snapshot.Name)
16251626
}
16261627
return &snapshots.Snapshots, nil
16271628
}
@@ -1646,7 +1647,7 @@ func (s *ScalewayAPI) GetSnapshot(snapshotID string) (*ScalewaySnapshot, error)
16461647
return nil, err
16471648
}
16481649
// FIXME region, arch, owner, title
1649-
s.Cache.InsertSnapshot(oneSnapshot.Snapshot.Identifier, "fr-1", "", oneSnapshot.Snapshot.Organization, oneSnapshot.Snapshot.Name)
1650+
s.Cache.InsertSnapshot(oneSnapshot.Snapshot.Identifier, "", "", oneSnapshot.Snapshot.Organization, oneSnapshot.Snapshot.Name)
16501651
return &oneSnapshot.Snapshot, nil
16511652
}
16521653

@@ -1675,7 +1676,7 @@ func (s *ScalewayAPI) GetVolumes() (*[]ScalewayVolume, error) {
16751676
}
16761677
for _, volume := range volumes.Volumes {
16771678
// FIXME region, arch, owner, title
1678-
s.Cache.InsertVolume(volume.Identifier, "fr-1", "", volume.Organization, volume.Name)
1679+
s.Cache.InsertVolume(volume.Identifier, "", "", volume.Organization, volume.Name)
16791680
}
16801681
return &volumes.Volumes, nil
16811682
}
@@ -1700,7 +1701,7 @@ func (s *ScalewayAPI) GetVolume(volumeID string) (*ScalewayVolume, error) {
17001701
return nil, err
17011702
}
17021703
// FIXME region, arch, owner, title
1703-
s.Cache.InsertVolume(oneVolume.Volume.Identifier, "fr-1", "", oneVolume.Volume.Organization, oneVolume.Volume.Name)
1704+
s.Cache.InsertVolume(oneVolume.Volume.Identifier, "", "", oneVolume.Volume.Organization, oneVolume.Volume.Name)
17041705
return &oneVolume.Volume, nil
17051706
}
17061707

@@ -1728,7 +1729,7 @@ func (s *ScalewayAPI) GetBootscripts() (*[]ScalewayBootscript, error) {
17281729
}
17291730
for _, bootscript := range bootscripts.Bootscripts {
17301731
// FIXME region, arch, owner, title
1731-
s.Cache.InsertBootscript(bootscript.Identifier, "fr-1", bootscript.Arch, bootscript.Organization, bootscript.Title)
1732+
s.Cache.InsertBootscript(bootscript.Identifier, "", bootscript.Arch, bootscript.Organization, bootscript.Title)
17321733
}
17331734
return &bootscripts.Bootscripts, nil
17341735
}
@@ -1753,7 +1754,7 @@ func (s *ScalewayAPI) GetBootscript(bootscriptID string) (*ScalewayBootscript, e
17531754
return nil, err
17541755
}
17551756
// FIXME region, arch, owner, title
1756-
s.Cache.InsertBootscript(oneBootscript.Bootscript.Identifier, "fr-1", oneBootscript.Bootscript.Arch, oneBootscript.Bootscript.Organization, oneBootscript.Bootscript.Title)
1757+
s.Cache.InsertBootscript(oneBootscript.Bootscript.Identifier, "", oneBootscript.Bootscript.Arch, oneBootscript.Bootscript.Organization, oneBootscript.Bootscript.Title)
17571758
return &oneBootscript.Bootscript, nil
17581759
}
17591760

@@ -2153,7 +2154,7 @@ func (s *ScalewayAPI) GetImageID(needle, arch string) (*ScalewayImageIdentifier,
21532154
Identifier: images[0].Identifier,
21542155
Arch: images[0].Arch,
21552156
// FIXME region, owner hardcoded
2156-
Region: "fr-1",
2157+
Region: "",
21572158
Owner: "",
21582159
}, nil
21592160
}

pkg/commands/ps.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func RunPs(ctx CommandContext, args PsArgs) error {
4747

4848
for key, value := range args.Filters {
4949
switch key {
50-
case "state", "name", "tags", "image", "ip", "arch", "server-type":
50+
case "state", "name", "tags", "image", "ip", "arch", "server-type", "zone":
5151
continue
5252
default:
5353
logrus.Warnf("Unknown filter: '%s=%s'", key, value)
@@ -97,6 +97,10 @@ func RunPs(ctx CommandContext, args PsArgs) error {
9797
if value != server.CommercialType {
9898
goto skipServer
9999
}
100+
case "zone":
101+
if value != server.Location.ZoneID {
102+
goto skipServer
103+
}
100104
}
101105
}
102106
filtered = append(filtered, server)
@@ -106,7 +110,7 @@ func RunPs(ctx CommandContext, args PsArgs) error {
106110
w := tabwriter.NewWriter(ctx.Stdout, 20, 1, 3, ' ', 0)
107111
defer w.Flush()
108112
if !args.Quiet {
109-
fmt.Fprintf(w, "SERVER ID\tIMAGE\tCOMMAND\tCREATED\tSTATUS\tPORTS\tNAME\tCOMMERCIAL TYPE\n")
113+
fmt.Fprintf(w, "SERVER ID\tIMAGE\tZONE\tCREATED\tSTATUS\tPORTS\tNAME\tCOMMERCIAL TYPE\n")
110114
}
111115
sort.Sort(api.ScalewaySortServers(filtered))
112116
for i, server := range filtered {
@@ -122,7 +126,7 @@ func RunPs(ctx CommandContext, args PsArgs) error {
122126
creationTime, _ := time.Parse("2006-01-02T15:04:05.000000+00:00", server.CreationDate)
123127
shortCreationDate := units.HumanDuration(time.Now().UTC().Sub(creationTime))
124128
port := server.PublicAddress.IP
125-
fmt.Fprintf(w, "%s\t%s\t\t%s\t%s\t%s\t%s\t%s\n", shortID, shortImage, shortCreationDate, server.State, port, shortName, server.CommercialType)
129+
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", shortID, shortImage, server.Location.ZoneID, shortCreationDate, server.State, port, shortName, server.CommercialType)
126130
}
127131
}
128132
return nil

0 commit comments

Comments
 (0)