From b081d4203d6104f64514e636349b0692c869b275 Mon Sep 17 00:00:00 2001 From: Dusty Mabe Date: Fri, 22 May 2020 18:09:16 -0400 Subject: [PATCH 1/2] cosalib/gcp: pass the log level to ore We'll use it to pass --log-level=INFO in the pipeline because the default logging level appears to be NOTICE. --- src/cosalib/gcp.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cosalib/gcp.py b/src/cosalib/gcp.py index a601e40ee0..18977a3d9b 100644 --- a/src/cosalib/gcp.py +++ b/src/cosalib/gcp.py @@ -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', From fa8d107d52a2e286bcb0f1ee7d4063c272ddcbf9 Mon Sep 17 00:00:00 2001 From: Dusty Mabe Date: Fri, 22 May 2020 18:10:24 -0400 Subject: [PATCH 2/2] mantle/ore: gcloud: support specifying multiple image licenses This will allow us to specify our normal fedora-coreos-$stream license as well as the nested virtualization license: https://compute.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx --- mantle/cmd/ore/gcloud/upload.go | 10 ++++++---- mantle/platform/api/gcloud/image.go | 17 ++++++++++++----- src/cosalib/gcp.py | 6 ++++-- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/mantle/cmd/ore/gcloud/upload.go b/mantle/cmd/ore/gcloud/upload.go index 5bb8af7382..d7b49f2a86 100644 --- a/mantle/cmd/ore/gcloud/upload.go +++ b/mantle/cmd/ore/gcloud/upload.go @@ -44,7 +44,7 @@ var ( uploadImageFamily string uploadImageDescription string uploadCreateImage bool - uploadImageLicense string + uploadImageLicenses []string ) func init() { @@ -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) } @@ -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 { diff --git a/mantle/platform/api/gcloud/image.go b/mantle/platform/api/gcloud/image.go index 19f2b149c0..7842f06d77 100644 --- a/mantle/platform/api/gcloud/image.go +++ b/mantle/platform/api/gcloud/image.go @@ -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 @@ -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 { diff --git a/src/cosalib/gcp.py b/src/cosalib/gcp.py index 18977a3d9b..ab7a96eedf 100644 --- a/src/cosalib/gcp.py +++ b/src/cosalib/gcp.py @@ -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 @@ -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",