azureutil

package
v0.15.0-rancher111 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 26 Imported by: 1

Documentation

Index

Constants

View Source
const (

	// ManagedByRancherKey indicates that the resource specified is managed by rancher
	ManagedByRancherKey = "rancher-managed"
)

Variables

This section is empty.

Functions

func AuthenticateClientCredentials

func AuthenticateClientCredentials(ctx context.Context, env azure.Environment, subscriptionID, tenantID, clientID, clientSecret string) (*autorest.BearerAuthorizer, error)

AuthenticateClientCredentials uses given client credentials to return a service principal token. Generated token is not stored in a cache file or refreshed.

func AuthenticateDeviceFlow added in v0.9.0

func AuthenticateDeviceFlow(ctx context.Context, env azure.Environment, subscriptionID, tenantID string) (*autorest.BearerAuthorizer, error)

AuthenticateDeviceFlow fetches a token from the local file cache or initiates a consent flow and waits for token to be obtained. Obtained token is stored in a file cache for future use and refreshing.

func BuildInstanceTags

func BuildInstanceTags(tagGroups string) map[string]*string

func FindTenantID

func FindTenantID(ctx context.Context, env azure.Environment, subscriptionID string) (string, error)

FindTenantID figures out the AAD tenant ID of the subscription by making an unauthenticated request to the Get Subscription Details endpoint and parses the value from WWW-Authenticate header.

func ValidateAuthorizer

func ValidateAuthorizer(ctx context.Context, env azure.Environment, authorizer *autorest.BearerAuthorizer) error

ValidateAuthorizer makes a call to Azure SDK with given authorizer to make sure it is valid

Types

type AzureClient

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

AzureClient contains the information necessary to instantiate Azure service clients

func New

func New(env azure.Environment, subsID string, auth autorest.Authorizer) *AzureClient

New creates a new Azure client

func (AzureClient) CleanupAvailabilitySetIfExists

func (a AzureClient) CleanupAvailabilitySetIfExists(ctx context.Context, resourceGroup, name string) error

CleanupAvailabilitySetIfExists removes an availability set if there are no virtual machines attached to it. Note that this method is not safe for multiple concurrent writers, in case of races, deployment of a machine could fail or resource might not be cleaned up.

func (AzureClient) CleanupSubnetIfExists

func (a AzureClient) CleanupSubnetIfExists(ctx context.Context, resourceGroup, virtualNetwork, name string) error

CleanupSubnetIfExists removes a subnet if there are no IP configurations (through NICs) are attached to it. Note that this method is not safe for multiple concurrent writers, in case of races, deployment of a machine could fail or resource might not be cleaned up.

func (AzureClient) CleanupVirtualNetworkIfExists

func (a AzureClient) CleanupVirtualNetworkIfExists(ctx context.Context, resourceGroup, name string) error

CleanupVirtualNetworkIfExists removes a subnet if there are no subnets attached to it. Note that this method is not safe for multiple concurrent writers, in case of races, deployment of a machine could fail or resource might not be cleaned up.

func (AzureClient) CreateAvailabilitySetIfNotExists

func (a AzureClient) CreateAvailabilitySetIfNotExists(ctx context.Context, deploymentCtx *DeploymentContext, resourceGroup, name, location string, isManaged bool, faultCount int32, updateCount int32) error

CreateAvailabilitySetIfNotExists checks that managed disk option match availability set if it already exists. If the availability set does not already exists than it is created with configured parameters.

func (AzureClient) CreateNetworkInterface

func (a AzureClient) CreateNetworkInterface(ctx context.Context, deploymentCtx *DeploymentContext, resourceGroup, name, location, publicIPAddressID, subnetID, nsgID, privateIPAddress string, enabledAcceleratedNetworking bool) error

CreateNetworkInterface creates a network interface

func (AzureClient) CreateNetworkSecurityGroup

func (a AzureClient) CreateNetworkSecurityGroup(ctx context.Context, deploymentCtx *DeploymentContext, providedResourceGroup string, resource azure.Resource,
	location string, usedInPool bool, rules *[]network.SecurityRule) error

CreateNetworkSecurityGroup either creates or updates the definition of the requested security group with the specified rules and adds it to our DeploymentContext If the resource provided is not tagged, we never update its security rules since the NSG is not managed by Rancher.

func (AzureClient) CreatePublicIPAddress

func (a AzureClient) CreatePublicIPAddress(ctx context.Context, deploymentCtx *DeploymentContext, resourceGroup, name, location string, isStatic bool, dnsLabel string, enablePublicIPStandardSKU bool) error

CreatePublicIPAddress creates a public IP address and adds it to our DeploymentContext

func (AzureClient) CreateResourceGroup

func (a AzureClient) CreateResourceGroup(ctx context.Context, name, location string) error

CreateResourceGroup creates a Resource Group if not exists

func (AzureClient) CreateStorageAccount

func (a AzureClient) CreateStorageAccount(ctx context.Context, deploymentCtx *DeploymentContext, resourceGroup, location string, storageType storage.SkuName) error

CreateStorageAccount sees if the storage account provided exists or otherwise creates a storage account for you and stores the data into DeploymentContext

func (AzureClient) CreateSubnet

func (a AzureClient) CreateSubnet(ctx context.Context, deploymentCtx *DeploymentContext, resourceGroup, virtualNetwork, name, subnetPrefix string) error

CreateSubnet creates or updates a subnet if it does not already exist.

func (AzureClient) CreateVirtualMachine

func (a AzureClient) CreateVirtualMachine(ctx context.Context, resourceGroup, name, location, size, availabilitySetID, networkInterfaceID,
	username, sshPublicKey, imageName, imagePlan, customData string, storageAccount *storage.AccountProperties, isManaged bool,
	storageType string, diskSize int32, tags map[string]*string, availabilityZone string) error

CreateVirtualMachine creates a VM according to the specifications and adds an SSH key to access the VM

func (AzureClient) CreateVirtualNetworkIfNotExists

func (a AzureClient) CreateVirtualNetworkIfNotExists(ctx context.Context, resourceGroup, name, location string) error

CreateVirtualNetworkIfNotExists checks to see if a virtual network exists with the name provided and either updates or creates it accordingly

func (AzureClient) DeleteNetworkInterfaceIfExists

func (a AzureClient) DeleteNetworkInterfaceIfExists(ctx context.Context, resourceGroup, name string) error

DeleteNetworkInterfaceIfExists deletes a network interface if it exists

func (AzureClient) DeleteNetworkSecurityGroupIfExists

func (a AzureClient) DeleteNetworkSecurityGroupIfExists(ctx context.Context, resource azure.Resource, usedInPool bool) error

DeleteNetworkSecurityGroupIfExists checks to see if the security group exists and accordingly deletes it

func (AzureClient) DeletePublicIPAddressIfExists

func (a AzureClient) DeletePublicIPAddressIfExists(ctx context.Context, resourceGroup, name string) error

DeletePublicIPAddressIfExists checks to see if the IP Address exists and accordingly deletes it

func (AzureClient) DeleteVirtualMachineIfExists

func (a AzureClient) DeleteVirtualMachineIfExists(ctx context.Context, resourceGroup, name string) error

DeleteVirtualMachineIfExists checks to see if a VM exists and deletes it accordingly It then

func (AzureClient) GetPrivateIPAddress

func (a AzureClient) GetPrivateIPAddress(ctx context.Context, resourceGroup, name string) (string, error)

GetPrivateIPAddress attempts to retrieve private IP address of the specified network interface name. If IP address is not allocated yet, returns empty string.

func (AzureClient) GetPublicIPAddress

func (a AzureClient) GetPublicIPAddress(ctx context.Context, resourceGroup, name string, useFqdn bool) (string, error)

GetPublicIPAddress attempts to get public IP address from the Public IP resource. If IP address is not allocated yet, returns empty string. If useFqdn is set to true, the a FQDN hostname will be returned.

func (AzureClient) GetVirtualMachinePowerState

func (a AzureClient) GetVirtualMachinePowerState(ctx context.Context, resourceGroup, name string) (VMPowerState, error)

GetVirtualMachinePowerState returns the VM's power state

func (AzureClient) RegisterResourceProviders

func (a AzureClient) RegisterResourceProviders(ctx context.Context, namespaces ...string) error

RegisterResourceProviders registers current subscription to the specified resource provider namespaces if they are not already registered. Namespaces are case-insensitive.

func (AzureClient) RestartVirtualMachine

func (a AzureClient) RestartVirtualMachine(ctx context.Context, resourceGroup, name string) error

RestartVirtualMachine restarts the virtual machine and waits until it reaches the goal state (stopped) or times out.

func (AzureClient) StartVirtualMachine

func (a AzureClient) StartVirtualMachine(ctx context.Context, resourceGroup, name string) error

StartVirtualMachine starts the virtual machine and waits until it reaches the goal state (running) or times out.

func (AzureClient) StopVirtualMachine

func (a AzureClient) StopVirtualMachine(ctx context.Context, resourceGroup, name string, skipShutdown bool) error

StopVirtualMachine power offs the virtual machine and waits until it reaches the goal state (stopped) or times out.

func (AzureClient) VirtualMachineExists

func (a AzureClient) VirtualMachineExists(ctx context.Context, resourceGroup, name string) (bool, error)

VirtualMachineExists sees if a virtual machine exists

type DeploymentContext

type DeploymentContext struct {
	VirtualNetworkExists   bool
	StorageAccount         *storage.AccountProperties
	PublicIPAddressID      string
	NetworkSecurityGroupID string
	SubnetID               string
	NetworkInterfaceID     string
	SSHPublicKey           string
	AvailabilitySetID      string
	FirewallRules          *[]network.SecurityRule
}

DeploymentContext contains references to various sources created and then used in creating other resources.

type ResourceNaming

type ResourceNaming string

ResourceNaming provides methods to construct Azure resource names for a given machine name.

func (ResourceNaming) IP

func (r ResourceNaming) IP() string

IP returns the Azure resource name for an IP address

func (ResourceNaming) NIC

func (r ResourceNaming) NIC() string

NIC returns the Azure resource name for a network interface

func (ResourceNaming) NSG

func (r ResourceNaming) NSG() string

NSG returns the Azure resource name for a network security group

func (ResourceNaming) OSDisk

func (r ResourceNaming) OSDisk() string

OSDisk returns the Azure resource name for an OS disk

func (ResourceNaming) OSDiskBlob

func (r ResourceNaming) OSDiskBlob() string

OSDiskBlob returns the Azure resource name for an OS disk blob

func (ResourceNaming) OSDiskContainer

func (r ResourceNaming) OSDiskContainer() string

OSDiskContainer returns the Azure resource name for an OS disk container

func (ResourceNaming) VM

func (r ResourceNaming) VM() string

VM returns the Azure resource name for a VM

type VMPowerState

type VMPowerState string

VMPowerState indicates the power state of the VM or is Unknown

const (
	// Unknown is returned when Azure does not provide a PowerState (happens
	// when VM is just deployed or started transitioning to another state) or
	// obtained PowerState is not one of the following.
	Unknown VMPowerState = ""

	// Stopped indicates that VM is allocated and in powered off state or the VM
	// has been just deployed for the first time. In this state, VM can be powered
	// on or
	Stopped VMPowerState = "stopped"

	// Stopping indicates that VM is about to go into powered off state.
	Stopping VMPowerState = "stopping"

	// Starting indicates that VM is being created or powered on.
	Starting VMPowerState = "starting"

	// Running indicates that VM is either powered on or being rebooted. VM
	// stays in this state during the reboot operation. In this state VM can be
	// stopped, restarted or deallocated.
	Running VMPowerState = "running"

	// Deallocating indicates that the VM is being terminated.
	Deallocating VMPowerState = "deallocating"

	// Deallocated indicates that the VM is being terminated. In this state, VM
	// can be powered on or powered off.
	Deallocated VMPowerState = "deallocated"
)

Jump to

Keyboard shortcuts

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