Skip to content

Commit

Permalink
Merge pull request #331 from QuentinPerez/fix-330
Browse files Browse the repository at this point in the history
Add a new field in the cache to handle UUID marketplace
  • Loading branch information
moul committed Apr 4, 2016
2 parents a03c216 + 5fbce73 commit df62a64
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,7 @@ $ scw inspect myserver | jq '.[0].public_ip.address'

### master (unreleased)

* No entry
* Add marketplace alias in the cache to resolve image ([#330](https://github.com/scaleway/scaleway-cli/issues/330))

View full [commits list](https://github.com/scaleway/scaleway-cli/compare/v1.9.0...master)

Expand Down
8 changes: 4 additions & 4 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ func (s *ScalewayAPI) PostImage(volumeID string, name string, bootscript string,
return "", err
}
// FIXME region, arch, owner, title
s.Cache.InsertImage(image.Image.Identifier, "fr-1", image.Image.Arch, image.Image.Organization, image.Image.Name)
s.Cache.InsertImage(image.Image.Identifier, "fr-1", image.Image.Arch, image.Image.Organization, image.Image.Name, "")
return image.Image.Identifier, nil
}

Expand Down Expand Up @@ -1365,7 +1365,7 @@ func (s *ScalewayAPI) GetImages() (*[]MarketImage, error) {
if version.ID == image.CurrentPublicVersion {
for _, localImage := range version.LocalImages {
images.Images[i].Public = true
s.Cache.InsertImage(localImage.ID, localImage.Zone, localImage.Arch, image.Organization.ID, image.Name)
s.Cache.InsertImage(localImage.ID, localImage.Zone, localImage.Arch, image.Organization.ID, image.Name, image.CurrentPublicVersion)
}
}
}
Expand All @@ -1385,7 +1385,7 @@ func (s *ScalewayAPI) GetImages() (*[]MarketImage, error) {
return nil, err
}
for _, orgaImage := range OrgaImages.Images {
s.Cache.InsertImage(orgaImage.Identifier, "fr-1", orgaImage.Arch, orgaImage.Organization, orgaImage.Name)
s.Cache.InsertImage(orgaImage.Identifier, "fr-1", orgaImage.Arch, orgaImage.Organization, orgaImage.Name, "")
images.Images = append(images.Images, MarketImage{
Categories: []string{"MyImages"},
CreationDate: orgaImage.CreationDate,
Expand Down Expand Up @@ -1436,7 +1436,7 @@ func (s *ScalewayAPI) GetImage(imageID string) (*ScalewayImage, error) {
return nil, err
}
// FIXME region, arch, owner, title
s.Cache.InsertImage(oneImage.Image.Identifier, "fr-1", oneImage.Image.Arch, oneImage.Image.Organization, oneImage.Image.Name)
s.Cache.InsertImage(oneImage.Image.Identifier, "fr-1", oneImage.Image.Arch, oneImage.Image.Organization, oneImage.Image.Name, "")
return &oneImage.Image, nil
}

Expand Down
11 changes: 9 additions & 2 deletions pkg/api/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const (
CacheOwner
// CacheTitle permits to access at the title field
CacheTitle
// CacheMarketPlaceUUID is used to determine the UUID of local images
CacheMarketPlaceUUID

// CacheMaxfield is used to determine the size of array
CacheMaxfield
)
Expand Down Expand Up @@ -284,6 +287,10 @@ func (c *ScalewayCache) LookUpImages(needle string, acceptUUID bool) ScalewayRes
entry := NewScalewayResolverResult(identifier, fields[CacheTitle], fields[CacheArch], IdentifierImage)
entry.ComputeRankMatch(needle)
res = append(res, entry)
} else if strings.HasPrefix(fields[CacheMarketPlaceUUID], needle) || nameRegex.MatchString(fields[CacheMarketPlaceUUID]) {
entry := NewScalewayResolverResult(identifier, fields[CacheTitle], fields[CacheArch], IdentifierImage)
entry.ComputeRankMatch(needle)
res = append(res, entry)
}
}

Expand Down Expand Up @@ -564,13 +571,13 @@ func (c *ScalewayCache) ClearServers() {
}

// InsertImage registers an image in the cache
func (c *ScalewayCache) InsertImage(identifier, region, arch, owner, name string) {
func (c *ScalewayCache) InsertImage(identifier, region, arch, owner, name, marketPlaceUUID string) {
c.Lock.Lock()
defer c.Lock.Unlock()

fields, exists := c.Images[identifier]
if !exists || fields[CacheTitle] != name {
c.Images[identifier] = [CacheMaxfield]string{region, arch, owner, name}
c.Images[identifier] = [CacheMaxfield]string{region, arch, owner, name, marketPlaceUUID}
c.Modified = true
}
}
Expand Down

0 comments on commit df62a64

Please sign in to comment.