github.com/coreos/mantle@v0.13.0/platform/machine/gcloud/flight.go (about)

     1  // Copyright 2015 CoreOS, Inc.
     2  // Copyright 2015 The Go Authors.
     3  // Copyright 2018 Red Hat
     4  //
     5  // Licensed under the Apache License, Version 2.0 (the "License");
     6  // you may not use this file except in compliance with the License.
     7  // You may obtain a copy of the License at
     8  //
     9  //     http://www.apache.org/licenses/LICENSE-2.0
    10  //
    11  // Unless required by applicable law or agreed to in writing, software
    12  // distributed under the License is distributed on an "AS IS" BASIS,
    13  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  // See the License for the specific language governing permissions and
    15  // limitations under the License.
    16  
    17  package gcloud
    18  
    19  import (
    20  	"github.com/coreos/pkg/capnslog"
    21  
    22  	ctplatform "github.com/coreos/container-linux-config-transpiler/config/platform"
    23  	"github.com/coreos/mantle/platform"
    24  	"github.com/coreos/mantle/platform/api/gcloud"
    25  )
    26  
    27  type flight struct {
    28  	*platform.BaseFlight
    29  	api *gcloud.API
    30  }
    31  
    32  const (
    33  	Platform platform.Name = "gcloud"
    34  )
    35  
    36  var (
    37  	plog = capnslog.NewPackageLogger("github.com/coreos/mantle", "platform/machine/gcloud")
    38  )
    39  
    40  func NewFlight(opts *gcloud.Options) (platform.Flight, error) {
    41  	api, err := gcloud.New(opts)
    42  	if err != nil {
    43  		return nil, err
    44  	}
    45  
    46  	bf, err := platform.NewBaseFlight(opts.Options, Platform, ctplatform.GCE)
    47  	if err != nil {
    48  		return nil, err
    49  	}
    50  
    51  	gf := &flight{
    52  		BaseFlight: bf,
    53  		api:        api,
    54  	}
    55  
    56  	return gf, nil
    57  }
    58  
    59  func (gf *flight) NewCluster(rconf *platform.RuntimeConfig) (platform.Cluster, error) {
    60  	bc, err := platform.NewBaseCluster(gf.BaseFlight, rconf)
    61  	if err != nil {
    62  		return nil, err
    63  	}
    64  
    65  	gc := &cluster{
    66  		BaseCluster: bc,
    67  		flight:      gf,
    68  	}
    69  
    70  	gf.AddCluster(gc)
    71  
    72  	return gc, nil
    73  }