Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions mantle/cmd/ore/gcloud/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var (
uploadImageFamily string
uploadImageDescription string
uploadCreateImage bool
uploadImageLicense string
uploadImageLicenses []string
)

func init() {
Expand All @@ -59,7 +59,9 @@ func init() {
cmdUpload.Flags().StringVar(&uploadImageFamily, "family", "", "GCP image family to attach image to")
cmdUpload.Flags().StringVar(&uploadImageDescription, "description", "", "The description that should be attached to the image")
cmdUpload.Flags().BoolVar(&uploadCreateImage, "create-image", true, "Create an image in GCP after uploading")
cmdUpload.Flags().StringVar(&uploadImageLicense, "license", "", "The license to attach to the image")
cmdUpload.Flags().StringSliceVar(
&uploadImageLicenses, "license", []string{},
"License to attach to image. Can be specified multiple times.")
GCloud.AddCommand(cmdUpload)
}

Expand Down Expand Up @@ -138,8 +140,8 @@ func runUpload(cmd *cobra.Command, args []string) {
SourceImage: imageStorageURL,
Description: uploadImageDescription,
}
if uploadImageLicense != "" {
spec.Licenses = []string{uploadImageLicense}
if len(uploadImageLicenses) > 0 {
spec.Licenses = uploadImageLicenses
}
_, pending, err := api.CreateImage(spec, uploadForce)
if err == nil {
Expand Down
17 changes: 12 additions & 5 deletions mantle/platform/api/gcloud/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ type ImageSpec struct {
Licenses []string // short names
}

const endpointPrefix = "https://www.googleapis.com/compute/v1/"

// Given a string representing an image return the full API
// endpoint for the image. For example:
// https://www.googleapis.com/compute/v1/projects/fedora-coreos-cloud/global/images/fedora-coreos-31-20200420-3-0-gcp-x86-64
func getImageAPIEndpoint(image, project string) (string, error) {
const endpointPrefix = "https://www.googleapis.com/compute/v1/"
// If the input is already a full API endpoint then just return it
if strings.HasPrefix(image, endpointPrefix) {
return image, nil
Expand All @@ -70,11 +71,17 @@ func getImageAPIEndpoint(image, project string) (string, error) {
func (a *API) CreateImage(spec *ImageSpec, overwrite bool) (*compute.Operation, *Pending, error) {
licenses := make([]string, len(spec.Licenses))
for i, l := range spec.Licenses {
license, err := a.compute.Licenses.Get(a.options.Project, l).Do()
if err != nil {
return nil, nil, fmt.Errorf("Invalid GCE license %s: %v", l, err)
// If the license is already in URI format then use that
if strings.HasPrefix(l, "https://") {
licenses[i] = l
} else {
// If not in URI format then query GCP for that info
license, err := a.compute.Licenses.Get(a.options.Project, l).Do()
if err != nil {
return nil, nil, fmt.Errorf("Invalid GCE license %s: %v", l, err)
}
licenses[i] = license.SelfLink
}
licenses[i] = license.SelfLink
}

if overwrite {
Expand Down
10 changes: 6 additions & 4 deletions src/cosalib/gcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def gcp_run_ore(build, args):
'--json-key', args.json_key,

]
if args.log_level == "DEBUG":
ore_common_args.extend(['--log-level', "DEBUG"])
if args.log_level:
ore_common_args.extend(['--log-level', args.log_level])

ore_upload_cmd = ore_common_args + [
'upload',
Expand All @@ -68,7 +68,8 @@ def gcp_run_ore(build, args):
if not args.create_image:
ore_upload_cmd.extend(['--create-image=false'])
if args.license:
ore_upload_cmd.extend(['--license', args.license])
for license in args.license:
ore_upload_cmd.extend(['--license', license])
run_verbose(ore_upload_cmd)

# Run deprecate image to deprecate if requested
Expand Down Expand Up @@ -145,7 +146,8 @@ def gcp_cli(parser):
help="Whether or not to create an image in GCP after upload.",
default=True)
parser.add_argument("--license",
help="The license that should be attached to the image",
action='append',
help="The licenses that should be attached to the image",
default=None)
parser.add_argument("--deprecated",
action="store_true",
Expand Down