github.com/coreos/mantle@v0.13.0/cmd/ore/gcloud/gcloud.go (about)

     1  // Copyright 2017 CoreOS, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package gcloud
    16  
    17  import (
    18  	"github.com/coreos/pkg/capnslog"
    19  	"github.com/spf13/cobra"
    20  
    21  	"github.com/coreos/mantle/cli"
    22  	"github.com/coreos/mantle/platform"
    23  	"github.com/coreos/mantle/platform/api/gcloud"
    24  )
    25  
    26  var (
    27  	plog = capnslog.NewPackageLogger("github.com/coreos/mantle", "ore/gce")
    28  
    29  	GCloud = &cobra.Command{
    30  		Use:   "gcloud [command]",
    31  		Short: "GCloud image creation and upload tools",
    32  	}
    33  
    34  	opts = gcloud.Options{Options: &platform.Options{}}
    35  
    36  	api *gcloud.API
    37  )
    38  
    39  func init() {
    40  	sv := GCloud.PersistentFlags().StringVar
    41  
    42  	sv(&opts.Image, "image", "", "image name")
    43  	sv(&opts.Project, "project", "coreos-gce-testing", "project")
    44  	sv(&opts.Zone, "zone", "us-central1-a", "zone")
    45  	sv(&opts.MachineType, "machinetype", "n1-standard-1", "machine type")
    46  	sv(&opts.DiskType, "disktype", "pd-ssd", "disk type")
    47  	sv(&opts.BaseName, "basename", "kola", "instance name prefix")
    48  	sv(&opts.Network, "network", "default", "network name")
    49  	sv(&opts.JSONKeyFile, "json-key", "", "use a service account's JSON key for authentication")
    50  	GCloud.PersistentFlags().BoolVar(&opts.ServiceAuth, "service-auth", false, "use non-interactive auth when running within GCE")
    51  
    52  	cli.WrapPreRun(GCloud, preauth)
    53  }
    54  
    55  func preauth(cmd *cobra.Command, args []string) error {
    56  	a, err := gcloud.New(&opts)
    57  	if err != nil {
    58  		return err
    59  	}
    60  
    61  	api = a
    62  
    63  	return nil
    64  }