mysqlsamples

package
v0.0.0-...-57c00fc Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2022 License: MIT Imports: 7 Imported by: 0

README


services: mysql platforms: go author: gechris

Azure mysql Samples

This package demonstrates how to manage Azure VMs, their disks and container instances with the Go SDK.

The child package "hybrid" demonstrates how to manage Azure VMs using Azure's Hybrid profile.

Contents

  • How to run all samples
  • Management
    • CreateServer - Create a PostgreSQL.
    • UpdateServer - Updates a PostgreSQL server.
    • DeleteServer - Deletes an existing PostgreSQL server.
    • CreateOrUpdateFirewallRules - Creates or updates a firewall rule on the server.
    • GetConfiguration - Get the configuration value that is set on the server.
    • UpdateConfiguration - Updates a configuration on the server.

How to run all samples

  1. Get this package and all dependencies.
export PROJECT=github.com/Azure-Samples/azure-sdk-for-go-samples/mysql
go get -u $PROJECT
cd ${GOPATH}/src/${PROJECT}
dep ensure
  1. Create an Azure service principal with the [Azure CLI][] command az ad sp create-for-rbac --output json and set the following environment variables per that command's output. You can also copy .env.tpl to .env and fill it in; the configuration system will utilize this.
AZURE_CLIENT_ID=
AZURE_CLIENT_SECRET=
AZURE_TENANT_ID=
AZURE_SUBSCRIPTION_ID=
AZURE_BASE_GROUP_NAME=
AZURE_LOCATION_DEFAULT=westus2
  1. TODO(joshgav): grant this principal all-powerful rights to your AAD tenant to faciliate identity-related operations.
  2. Run the tests: go test -v -timeout 12h

The timeout is optional, but some tests take longer than then default 10m to complete.

More information

Please refer to Azure SDK for Go for more information.


This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Documentation

Overview

Example (PerformServerOperations)

Example_createDatabase creates a MySQL server and database, then creates a table and inserts a record.

config.SetGroupName(groupName)

serverName = strings.ToLower(serverName)

ctx := context.Background()
defer resources.Cleanup(ctx)

_, err := resources.CreateGroup(ctx, config.GroupName())
if err != nil {
	util.LogAndPanic(err)
}

_, err = CreateServer(ctx, serverName, dbLogin, dbPassword)
if err != nil {
	util.LogAndPanic(fmt.Errorf("cannot create mysql server: %+v", err))
}
util.PrintAndLog("mysql server created")

_, err = UpdateServerStorageCapacity(ctx, serverName, 1048576)
if err != nil {
	util.LogAndPanic(fmt.Errorf("cannot update mysql server: %+v", err))
}
util.PrintAndLog("updated mysql server's storage capacity")

err = CreateOrUpdateFirewallRule(ctx, serverName, "FirewallRuleName", "0.0.0.0", "0.0.0.0")
if err != nil {
	util.LogAndPanic(err)
}
util.PrintAndLog("Firewall rule set")

err = CreateOrUpdateFirewallRule(ctx, serverName, "FirewallRuleName", "0.0.0.0", "1.1.1.1")
if err != nil {
	util.LogAndPanic(err)
}
util.PrintAndLog("Firewall rule updated")

var configuration mysql.Configuration

configuration, err = GetConfiguration(ctx, serverName, "event_scheduler")
if err != nil {
	util.LogAndPanic(err)
}
util.PrintAndLog("Got the event_scheduler configuration")

// Update the configuration Value.
configuration.ConfigurationProperties.Value = to.StringPtr("on")
configuration.ConfigurationProperties.Source = to.StringPtr("user-override")

_, err = UpdateConfiguration(ctx, serverName, "event_scheduler", configuration)
if err != nil {
	util.LogAndPanic(err)
}
util.PrintAndLog("Updated the event_scheduler configuration")

// Finally delete the server.
_, err = DeleteServer(ctx, serverName)
if err != nil {
	util.LogAndPanic(err)
}
util.PrintAndLog("Successfully deleted the server")
Output:

mysql server created
updated mysql server's storage capacity
Firewall rule set
Firewall rule updated
Got the event_scheduler configuration
Updated the event_scheduler configuration
Successfully deleted the server

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateOrUpdateFirewallRule

func CreateOrUpdateFirewallRule(ctx context.Context, serverName, firewallRuleName, startIPAddr, endIPAddr string) error

CreateOrUpdateFirewallRule given the firewallname and new properties it updates the firewall rule.

func CreateServer

func CreateServer(ctx context.Context, serverName, dbLogin, dbPassword string) (server mysql.Server, err error)

CreateServer creates a new MySQL Server

func DeleteServer

func DeleteServer(ctx context.Context, serverName string) (resp autorest.Response, err error)

DeleteServer deletes the MySQL server.

func GetConfiguration

func GetConfiguration(ctx context.Context, serverName, configurationName string) (mysql.Configuration, error)

GetConfiguration given the server name and configuration name it returns the configuration.

func UpdateConfiguration

func UpdateConfiguration(ctx context.Context, serverName string, configurationName string, configuration mysql.Configuration) (updatedConfig mysql.Configuration, err error)

UpdateConfiguration given the name of the configuation and the configuration object it updates the configuration for the given server.

func UpdateServerStorageCapacity

func UpdateServerStorageCapacity(ctx context.Context, serverName string, storageCapacity int32) (server mysql.Server, err error)

UpdateServerStorageCapacity given the server name and the new storage capacity it updates the server's storage capacity.

Types

This section is empty.

Jump to

Keyboard shortcuts

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