github.com/coreos/mantle@v0.13.0/cmd/ore/esx/esx.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 esx
    16  
    17  import (
    18  	"fmt"
    19  	"os"
    20  
    21  	"github.com/coreos/mantle/cli"
    22  	"github.com/coreos/mantle/platform/api/esx"
    23  	"github.com/coreos/pkg/capnslog"
    24  	"github.com/spf13/cobra"
    25  )
    26  
    27  var (
    28  	plog = capnslog.NewPackageLogger("github.com/coreos/mantle", "ore/esx")
    29  
    30  	ESX = &cobra.Command{
    31  		Use:   "esx [command]",
    32  		Short: "esx image and vm utilities",
    33  	}
    34  
    35  	API     *esx.API
    36  	options esx.Options
    37  )
    38  
    39  func init() {
    40  	ESX.PersistentFlags().StringVar(&options.Server, "server", "", "ESX server")
    41  	ESX.PersistentFlags().StringVar(&options.Profile, "profile", "", "Profile")
    42  	cli.WrapPreRun(ESX, preflightCheck)
    43  }
    44  
    45  func preflightCheck(cmd *cobra.Command, args []string) error {
    46  	plog.Debugf("Running ESX Preflight check.")
    47  	api, err := esx.New(&options)
    48  	if err != nil {
    49  		fmt.Fprintf(os.Stderr, "could not create ESX client: %v\n", err)
    50  		os.Exit(1)
    51  	}
    52  	if err = api.PreflightCheck(); err != nil {
    53  		fmt.Fprintf(os.Stderr, "could not complete ESX preflight check: %v\n", err)
    54  		os.Exit(1)
    55  	}
    56  
    57  	plog.Debugf("Preflight check success; we have liftoff")
    58  	API = api
    59  	return nil
    60  }