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: 38 Imported by: 0

Documentation

Overview

pkg/providers/azure/client.go

pkg/providers/azure/provider.go

Index

Constants

View Source
const (
	UpdateQueueSize         = 100
	ResourcePollingInterval = 2 * time.Second
	DebugFilePath           = "/tmp/andaime-debug.log"
	DebugFilePermissions    = 0644
	WaitingForMachinesTime  = 1 * time.Minute
	DefaultSSHUser          = "andaimeuser"
	DefaultSSHPort          = 22
)

Constants related to Azure Provider configurations.

Variables

View Source
var NewAzureClientFunc = NewAzureClient
View Source
var NewAzureProviderFunc = NewAzureProvider

Functions

func AssertResourceGroupCreated

func AssertResourceGroupCreated(
	t *testing.T,
	mockClient *MockClient,
	expectedName, expectedLocation string,
)

AssertResourceGroupCreated is a helper function to assert that a resource group was created

func ConvertFromStringToResourceState

func ConvertFromStringToResourceState(state string) (string, error)

func GenerateTags

func GenerateTags(projectID, uniqueID string) map[string]*string

generateTags creates a map of tags for Azure resources

func NewAzureClient

func NewAzureClient(subscriptionID string) (azure_interface.AzureClienter, error)

NewAzureClient creates a new AzureClient.

func NewTestContext

func NewTestContext() context.Context

NewTestContext creates a new context for testing

Types

type AzureError

type AzureError struct {
	Code    string
	Message string
}

AzureError represents a custom error type for Azure operations.

func (AzureError) Error

func (e AzureError) Error() string

Error returns the error message.

func (AzureError) IsNotFound

func (e AzureError) IsNotFound() bool

IsNotFound checks if the error indicates that a resource was not found.

type AzureProvider

type AzureProvider struct {
	SubscriptionID    string
	ResourceGroupName string
	Tags              map[string]*string
	Client            azure_interface.AzureClienter
	ClusterDeployer   common_interface.ClusterDeployerer
	SSHClient         sshutils.SSHClienter
	SSHUser           string
	SSHPort           int

	UpdateQueue chan display.UpdateAction
	UpdateMutex sync.Mutex
	// contains filtered or unexported fields
}

AzureProvider implements the Providerer interface.

func NewAzureProvider

func NewAzureProvider(
	ctx context.Context,
	subscriptionID string,
) (*AzureProvider, error)

NewAzureProvider creates and initializes a new AzureProvider instance with subscriptionID.

func NewAzureProviderFactory

func NewAzureProviderFactory(ctx context.Context) (*AzureProvider, error)

func (*AzureProvider) AllMachinesComplete

func (p *AzureProvider) AllMachinesComplete() bool

AllMachinesComplete checks if all machines in the deployment are marked as complete.

func (*AzureProvider) CancelAllDeployments

func (p *AzureProvider) CancelAllDeployments(ctx context.Context)

CancelAllDeployments cancels all ongoing deployments.

func (*AzureProvider) CheckAuthentication

func (p *AzureProvider) CheckAuthentication(ctx context.Context) error

func (*AzureProvider) CreateResources

func (p *AzureProvider) CreateResources(ctx context.Context) error

func (*AzureProvider) DeployBacalhauWorkers

func (p *AzureProvider) DeployBacalhauWorkers(ctx context.Context) error

func (*AzureProvider) DeployBacalhauWorkersWithCallback added in v0.0.20

func (p *AzureProvider) DeployBacalhauWorkersWithCallback(ctx context.Context, callback UpdateCallback) error

func (*AzureProvider) DestroyDeployment

func (p *AzureProvider) DestroyDeployment(
	ctx context.Context,
	resourceGroupName string,
) error

DestroyDeployment initiates the deletion of the specified Azure resource group

func (*AzureProvider) DestroyResourceGroup

func (p *AzureProvider) DestroyResourceGroup(ctx context.Context, resourceGroupName string) error

DestroyResourceGroup deletes the specified resource group.

func (*AzureProvider) DestroyResources

func (p *AzureProvider) DestroyResources(ctx context.Context, resourceGroupName string) error

DestroyResources destroys the specified resource group if it exists.

func (*AzureProvider) FinalizeDeployment

func (p *AzureProvider) FinalizeDeployment(ctx context.Context) error

func (*AzureProvider) GetAzureClient

func (p *AzureProvider) GetAzureClient() azure_interface.AzureClienter

func (*AzureProvider) GetClusterDeployer

func (p *AzureProvider) GetClusterDeployer() common_interface.ClusterDeployerer

GetClusterDeployer returns the current ClusterDeployer.

func (*AzureProvider) GetOrCreateResourceGroup

func (p *AzureProvider) GetOrCreateResourceGroup(
	ctx context.Context,
	resourceGroupName string,
	locationData string,
	tags map[string]string,
) (*armresources.ResourceGroup, error)

GetOrCreateResourceGroup retrieves an existing resource group or creates a new one if it doesn't exist.

func (*AzureProvider) GetResources

func (p *AzureProvider) GetResources(
	ctx context.Context,
	resourceGroupName string,
	tags map[string]*string,
) ([]interface{}, error)

func (*AzureProvider) GetSKUsByLocation

func (p *AzureProvider) GetSKUsByLocation(
	ctx context.Context,
	location string,
) ([]armcompute.ResourceSKU, error)

func (*AzureProvider) GetVMExternalIP

func (p *AzureProvider) GetVMExternalIP(
	ctx context.Context,
	vmName string,
	locationData map[string]string,
) (string, error)

GetVMExternalIP retrieves the external IP of a VM instance.

func (*AzureProvider) GetVMIPAddresses

func (p *AzureProvider) GetVMIPAddresses(
	ctx context.Context,
	resourceGroupName, vmName string,
) (string, string, error)

func (*AzureProvider) Initialize

func (p *AzureProvider) Initialize(ctx context.Context) error

Initialize sets up the AzureProvider by configuring SSH keys and starting the update processor.

func (*AzureProvider) ListAllResourceGroups

func (p *AzureProvider) ListAllResourceGroups(
	ctx context.Context,
) ([]*armresources.ResourceGroup, error)

func (*AzureProvider) ListAllResourcesInSubscription

func (p *AzureProvider) ListAllResourcesInSubscription(
	ctx context.Context,
	tags map[string]*string,
) ([]interface{}, error)

func (*AzureProvider) PollResources

func (p *AzureProvider) PollResources(ctx context.Context) ([]interface{}, error)

func (*AzureProvider) PrepareDeployment

func (p *AzureProvider) PrepareDeployment(
	ctx context.Context,
) (*models.Deployment, error)

func (*AzureProvider) PrepareResourceGroup

func (p *AzureProvider) PrepareResourceGroup(
	ctx context.Context,
) error

PrepareResourceGroup prepares or creates a resource group for the Azure deployment. It ensures that a valid resource group name and location are set, creating them if necessary.

Parameters:

  • ctx: The context.Context for the operation, used for cancellation and timeout.

Returns:

  • error: An error if the resource group preparation fails, nil otherwise.

The function performs the following steps: 1. Retrieves the global deployment object. 2. Ensures a resource group name is set, appending a timestamp if necessary. 3. Determines the resource group location, using the first machine's location if not explicitly set. 4. Creates or retrieves the resource group using the Azure client. 5. Updates the global deployment object with the finalized resource group information.

func (*AzureProvider) ProcessMachinesConfig

func (p *AzureProvider) ProcessMachinesConfig(
	ctx context.Context,
) (map[string]models.Machiner, map[string]bool, error)

This updates m.Deployment with machines and returns an error if any

func (*AzureProvider) SetAzureClient

func (p *AzureProvider) SetAzureClient(client azure_interface.AzureClienter)

func (*AzureProvider) SetClusterDeployer

func (p *AzureProvider) SetClusterDeployer(deployer common_interface.ClusterDeployerer)

SetClusterDeployer sets a new ClusterDeployer.

func (*AzureProvider) StartResourcePolling

func (p *AzureProvider) StartResourcePolling(ctx context.Context) error

StartResourcePolling starts polling Azure resources for updates.

func (*AzureProvider) ValidateMachineType

func (p *AzureProvider) ValidateMachineType(
	ctx context.Context,
	location, machineType string,
) (bool, error)

type BaseAzureTestSuite

type BaseAzureTestSuite struct {
	suite.Suite
	MockAzureClient *azure_mocks.MockAzureClienter
	Ctx             context.Context
	Deployment      *models.Deployment
}

func (*BaseAzureTestSuite) SetupSuite

func (suite *BaseAzureTestSuite) SetupSuite()

func (*BaseAzureTestSuite) SetupTest

func (suite *BaseAzureTestSuite) SetupTest()

func (*BaseAzureTestSuite) TearDownSuite

func (suite *BaseAzureTestSuite) TearDownSuite()

type LiveAzureClient

type LiveAzureClient struct {
	// contains filtered or unexported fields
}

LiveAzureClient implements the AzureClienter interface using the Azure SDK.

func (*LiveAzureClient) DeployTemplate

func (c *LiveAzureClient) DeployTemplate(
	ctx context.Context,
	resourceGroupName string,
	deploymentName string,
	template map[string]interface{},
	params map[string]interface{},
	tags map[string]*string,
) (azure_interface.Pollerer, error)

DeployTemplate deploys an ARM template.

func (*LiveAzureClient) DestroyResourceGroup

func (c *LiveAzureClient) DestroyResourceGroup(
	ctx context.Context,
	resourceGroupName string,
) error

func (*LiveAzureClient) GetNetworkInterface

func (c *LiveAzureClient) GetNetworkInterface(
	ctx context.Context,
	resourceGroupName string,
	networkInterfaceName string,
) (*armnetwork.Interface, error)

GetNetworkInterface retrieves a network interface.

func (*LiveAzureClient) GetOrCreateResourceGroup

func (c *LiveAzureClient) GetOrCreateResourceGroup(ctx context.Context,
	rgName string,
	rgLocation string,
	tags map[string]string) (*armresources.ResourceGroup, error)

CreateResourceGroup creates a new resource group or returns an existing one

func (*LiveAzureClient) GetPublicIPAddress

func (c *LiveAzureClient) GetPublicIPAddress(
	ctx context.Context,
	resourceGroupName string,
	publicIPAddress *armnetwork.PublicIPAddress,
) (string, error)

GetPublicIPAddress retrieves a public IP address.

func (*LiveAzureClient) GetResourceGroup

func (c *LiveAzureClient) GetResourceGroup(ctx context.Context,
	rgLocation string,
	rgName string) (*armresources.ResourceGroup, error)

func (*LiveAzureClient) GetResources

func (c *LiveAzureClient) GetResources(
	ctx context.Context,
	subscriptionID string,
	resourceGroupName string,
	tags map[string]*string) ([]interface{}, error)

GetResources retrieves resources based on subscriptionID, resourceGroupName, and tags.

func (*LiveAzureClient) GetSKUsByLocation

func (c *LiveAzureClient) GetSKUsByLocation(
	ctx context.Context,
	location string,
) ([]armcompute.ResourceSKU, error)

GetSKUsByLocation retrieves SKUs available in a specific location.

func (*LiveAzureClient) GetVMExternalIP

func (c *LiveAzureClient) GetVMExternalIP(
	ctx context.Context,
	vmName string,
	locationData map[string]string,
) (string, error)

GetVMExternalIP retrieves the external IP of a VM instance. Note: Implementation depends on how IPs are managed; this is a placeholder.

func (*LiveAzureClient) GetVirtualMachine

func (c *LiveAzureClient) GetVirtualMachine(
	ctx context.Context,
	resourceGroupName string,
	vmName string,
) (*armcompute.VirtualMachine, error)

GetVirtualMachine retrieves a virtual machine.

func (*LiveAzureClient) InitiateResourceGroupDeletion

func (c *LiveAzureClient) InitiateResourceGroupDeletion(
	ctx context.Context,
	resourceGroupName string,
) error

func (*LiveAzureClient) ListAllResourceGroups

func (c *LiveAzureClient) ListAllResourceGroups(
	ctx context.Context,
) ([]*armresources.ResourceGroup, error)

ListAllResourceGroups lists all resource groups.

func (*LiveAzureClient) ListAllResourcesInSubscription

func (c *LiveAzureClient) ListAllResourcesInSubscription(
	ctx context.Context,
	subscriptionID string,
	tags map[string]*string) ([]interface{}, error)

ListAllResourcesInSubscription lists all resources in a subscription with given tags.

func (*LiveAzureClient) ListResourceGroups

func (c *LiveAzureClient) ListResourceGroups(
	ctx context.Context,
) ([]*armresources.ResourceGroup, error)

func (*LiveAzureClient) NewSubscriptionListPager

NewSubscriptionListPager returns a new subscription list pager.

func (*LiveAzureClient) ResourceGroupExists

func (c *LiveAzureClient) ResourceGroupExists(
	ctx context.Context,
	resourceGroupName string,
) (bool, error)

ResourceGroupExists checks if a resource group exists.

func (*LiveAzureClient) ValidateMachineType

func (c *LiveAzureClient) ValidateMachineType(
	ctx context.Context,
	location string,
	vmSize string,
) (bool, error)

ValidateMachineType checks if the specified machine type is valid in the given location.

type MockClient

type MockClient struct {
	mock.Mock
}

MockClient is a mock implementation of the Client interface

func NewMockClient

func NewMockClient() *MockClient

NewMockClient creates a new MockClient with common expectations set

type UpdateCallback added in v0.0.20

type UpdateCallback func(*models.DisplayStatus)

UpdateCallback is a function type for status updates during deployment

Jump to

Keyboard shortcuts

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