azure

package
v0.0.22 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RetryTimeout   = 2 * time.Second
	DefaultSSHPort = 22
)

Variables

View Source
var AzureCmd = &cobra.Command{
	Use:   "azure",
	Short: "Azure-related commands",
	Long:  `Commands for interacting with Azure resources.`,
}
View Source
var AzureListResourcesCmd = &cobra.Command{
	Use:   "list-resources",
	Short: "List Azure resources",
	Long:  `List all resources in a subscription or specific resource group.`,
	Run: func(cmd *cobra.Command, args []string) {
		verbose, _ := cmd.Flags().GetBool("verbose")
		log := logger.Get()
		log.SetVerbose(verbose)

		projectPrefix := viper.GetString("general.project_prefix")
		uniqueID := viper.GetString("general.unique_id")
		tags := azure_provider.GenerateTags(projectPrefix, uniqueID)

		log.Info("Listing Azure resources...")

		azureProvider, err := azure_provider.NewAzureProviderFunc(
			cmd.Context(),
			viper.GetString("azure.subscription_id"),
		)
		if err != nil {
			log.Fatal("failed to assert provider to common.AzureProviderer")
		}

		allFlag, _ := cmd.Flags().GetBool("all")
		resourceGroup, _ := cmd.Flags().GetString("resource-group")

		if !allFlag && resourceGroup == "" {
			log.Fatal("Either --all or --resource-group must be specified")
		}

		if allFlag && resourceGroup != "" {
			log.Fatal("Cannot use both --all and --resource-group flags simultaneously")
		}

		log.Info("Contacting Azure API...")
		startTime := time.Now()

		var resources []interface{}
		if err != nil {
			log.Fatalf("Failed to get subscription ID: %v", err)
		}
		if allFlag {
			resources, err = azureProvider.
				ListAllResourcesInSubscription(cmd.Context(),
					tags)
		} else {
			resources, err = azureProvider.GetResources(cmd.Context(),
				resourceGroup,
				tags)
		}

		_ = resources

		if err != nil {
			switch {
			case isNetworkError(err):
				log.Fatal("Network is down. Please check your internet connection and try again.")
			case isAzureServiceError(err):
				log.Fatalf("Azure service error: %v", err)
			default:
				log.Fatalf("Failed to query resources: %v", err)
			}
		}

		log.Infof("Azure API contacted (took %s)", time.Since(startTime).Round(time.Millisecond))

	},
}
View Source
var AzureListSubscriptionsCmd = &cobra.Command{
	Use:   "list-subscriptions",
	Short: "List Azure subscriptions",
	Long:  `List all subscriptions and optionally select one to use.`,
	Run:   runListSubscriptions,
}

AzureListSubscriptionsCmd represents the command to list Azure subscriptions

Functions

func ExecuteCreateDeployment

func ExecuteCreateDeployment(cmd *cobra.Command, args []string) error

func GetAzureCmd

func GetAzureCmd() *cobra.Command

func GetAzureCreateDeploymentCmd

func GetAzureCreateDeploymentCmd() *cobra.Command

func GetAzureCreateVMCmd

func GetAzureCreateVMCmd() *cobra.Command

func GetAzureDestroyCmd

func GetAzureDestroyCmd() *cobra.Command

func GetAzureListResourcesCmd

func GetAzureListResourcesCmd() *cobra.Command

func GetAzureListSKUsCmd

func GetAzureListSKUsCmd() *cobra.Command

func GetAzureListSubscriptionsCmd

func GetAzureListSubscriptionsCmd() *cobra.Command

func InitializeCommands

func InitializeCommands()

func ListSubscriptions

func ListSubscriptions(configFilePath string, setSubscription bool) error

Types

type ConfigDeployment

type ConfigDeployment struct {
	Name         string
	Type         models.DeploymentType
	ID           string
	UniqueID     string
	FullViperKey string
}

type Subscription

type Subscription struct {
	DisplayName    string
	ID             string
	State          string
	SubscriptionID string
	TenantID       string
}

Subscription represents an Azure subscription

type SubscriptionTable

type SubscriptionTable struct {
	Title    string
	Columns  []display.DisplayColumn
	LogFile  string
	DataType interface{}
}

SubscriptionTable defines the structure for displaying subscription data

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL