lxc/utils.go
func ensureImageAliases(client lxd.ContainerServer, aliases []api.ImageAlias, fingerprint string) error {
	if len(aliases) == 0 {
		return nil
	}

	names := make([]string, len(aliases))
	for i, alias := range aliases {
		names[i] = alias.Name
	}
	sort.Strings(names)

	resp, err := client.GetImageAliases()
	if err != nil {
		return err
	}

	// Delete existing aliases that match provided ones
	for _, alias := range GetExistingAliases(names, resp) {
		err := client.DeleteImageAlias(alias.Name)
		if err != nil {
			fmt.Println(fmt.Sprintf(i18n.G("Failed to remove alias %s"), alias.Name))
		}
	}
	// Create new aliases
	for _, alias := range aliases {
		aliasPost := api.ImageAliasesPost{}
		aliasPost.Name = alias.Name
		aliasPost.Target = fingerprint
		err := client.CreateImageAlias(aliasPost)
		if err != nil {
			fmt.Println(fmt.Sprintf(i18n.G("Failed to create alias %s"), alias.Name))
		}
	}
	return nil
}
func ensureImageAliases(client lxd.ContainerServer, aliases []api.ImageAlias, fingerprint string) error {
	if len(aliases) == 0 {
		return nil
	}

	names := make([]string, len(aliases))
	for i, alias := range aliases {
		names[i] = alias.Name
	}
	sort.Strings(names)

	resp, err := client.GetImageAliases()
	if err != nil {
		return err
	}

	// Delete existing aliases that match provided ones
	for _, alias := range GetExistingAliases(names, resp) {
		err := client.DeleteImageAlias(alias.Name)
		if err != nil {
			fmt.Println(fmt.Sprintf(i18n.G("Failed to remove alias %s"), alias.Name))
		}
	}
	// Create new aliases
	for _, alias := range aliases {
		aliasPost := api.ImageAliasesPost{}
		aliasPost.Name = alias.Name
		aliasPost.Target = fingerprint
		err := client.CreateImageAlias(aliasPost)
		if err != nil {
			fmt.Println(fmt.Sprintf(i18n.G("Failed to create alias %s"), alias.Name))
		}
	}
	return nil
}
func ensureImageAliases ( client lxd . ContainerServer , aliases [ ] api . ImageAlias , fingerprint string ) error { if len ( aliases ) == 0 { return nil } names := make ( [ ] string , len ( aliases ) ) for i , alias := range aliases { names [ i ] = alias . Name } sort . Strings ( names ) resp , err := client . GetImageAliases ( ) if err != nil { return err } // Delete existing aliases that match provided ones for _ , alias := range GetExistingAliases ( names , resp ) { err := client . DeleteImageAlias ( alias . Name ) if err != nil { fmt . Println ( fmt . Sprintf ( i18n . G ( " " ) , alias . Name ) ) } } // Create new aliases for _ , alias := range aliases { aliasPost := api . ImageAliasesPost { } aliasPost . Name = alias . Name aliasPost . Target = fingerprint err := client . CreateImageAlias ( aliasPost ) if err != nil { fmt . Println ( fmt . Sprintf ( i18n . G ( " " ) , alias . Name ) ) } } return nil }
// Create the specified image alises, updating those that already exist
Create the specified image alises updating those that already exist