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

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