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

     1  // Copyright 2016 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 azure
    16  
    17  import (
    18  	"github.com/coreos/pkg/capnslog"
    19  	"github.com/spf13/cobra"
    20  
    21  	"github.com/coreos/mantle/auth"
    22  	"github.com/coreos/mantle/cli"
    23  	"github.com/coreos/mantle/platform/api/azure"
    24  )
    25  
    26  var (
    27  	plog = capnslog.NewPackageLogger("github.com/coreos/mantle", "ore/azure")
    28  
    29  	Azure = &cobra.Command{
    30  		Use:   "azure [command]",
    31  		Short: "azure image and vm utilities",
    32  	}
    33  
    34  	azureProfile      string
    35  	azureAuth         string
    36  	azureSubscription string
    37  	azureLocation     string
    38  
    39  	api *azure.API
    40  )
    41  
    42  func init() {
    43  	cli.WrapPreRun(Azure, preauth)
    44  
    45  	sv := Azure.PersistentFlags().StringVar
    46  	sv(&azureProfile, "azure-profile", "", "Azure Profile json file")
    47  	sv(&azureAuth, "azure-auth", "", "Azure auth location (default \"~/"+auth.AzureAuthPath+"\")")
    48  	sv(&azureSubscription, "azure-subscription", "", "Azure subscription name. If unset, the first is used.")
    49  	sv(&azureLocation, "azure-location", "westus", "Azure location (default \"westus\")")
    50  }
    51  
    52  func preauth(cmd *cobra.Command, args []string) error {
    53  	plog.Printf("Creating Azure API...")
    54  
    55  	a, err := azure.New(&azure.Options{
    56  		AzureProfile:      azureProfile,
    57  		AzureAuthLocation: azureAuth,
    58  		AzureSubscription: azureSubscription,
    59  		Location:          azureLocation,
    60  	})
    61  	if err != nil {
    62  		plog.Fatalf("Failed to create Azure API: %v", err)
    63  	}
    64  
    65  	api = a
    66  	return nil
    67  }