azure-sdk-for-go/README.md

81 строка
2.4 KiB
Markdown
Исходник Обычный вид История

2015-04-29 04:46:41 +03:00
# Azure SDK for Go
This project provides various Golang packages that makes it easy to consume and manage
Microsoft Azure Services.
2014-10-07 00:57:06 +04:00
2015-05-15 23:31:57 +03:00
[![GoDoc](https://godoc.org/github.com/Azure/azure-sdk-for-go?status.svg)](https://godoc.org/github.com/Azure/azure-sdk-for-go) [![Build Status](https://travis-ci.org/Azure/azure-sdk-for-go.svg?branch=master)](https://travis-ci.org/Azure/azure-sdk-for-go)
2014-10-07 00:57:06 +04:00
# Installation
- Install Golang: https://golang.org/doc/install
- Get Azure SDK package:
go get -d github.com/Azure/azure-sdk-for-go
2014-10-07 00:57:06 +04:00
# Usage
Read Godoc of the package at: http://godoc.org/github.com/Azure/azure-sdk-for-go/management
2015-04-29 04:46:41 +03:00
2015-03-20 03:41:25 +03:00
Download publish settings file from https://manage.windowsazure.com/publishsettings.
2015-04-29 04:46:41 +03:00
# Example: Create a Linux VM
2014-10-07 00:57:06 +04:00
2015-03-20 03:41:25 +03:00
```go
2014-10-07 00:57:06 +04:00
package main
import (
"fmt"
2015-03-20 03:41:25 +03:00
"github.com/Azure/azure-sdk-for-go/management"
"github.com/Azure/azure-sdk-for-go/management/hostedservice"
"github.com/Azure/azure-sdk-for-go/management/virtualmachine"
"github.com/Azure/azure-sdk-for-go/management/vmutils"
2014-10-07 00:57:06 +04:00
)
func main() {
dnsName := "test-vm-from-go"
2015-03-20 03:41:25 +03:00
storageAccount := "mystorageaccount"
2014-10-07 00:57:06 +04:00
location := "West US"
vmSize := "Small"
vmImage := "b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-14_04-LTS-amd64-server-20140724-en-us-30GB"
userName := "testuser"
userPassword := "Test123"
2015-03-20 03:41:25 +03:00
client, err := management.ClientFromPublishSettingsFile("path/to/downloaded.publishsettings", "")
if err != nil {
panic(err)
2015-03-03 22:07:41 +03:00
}
2015-03-20 03:41:25 +03:00
// create hosted service
requestId, err := hostedservice.NewClient(client).CreateHostedService(dnsName, location, "", dnsName, "")
2014-10-07 00:57:06 +04:00
if err != nil {
2015-03-20 03:41:25 +03:00
panic(err)
}
err = client.WaitAsyncOperation(requestId)
if err != nil {
panic(err)
2014-10-07 00:57:06 +04:00
}
2015-03-20 03:41:25 +03:00
// create virtual machine
role, err := vmutils.NewVmConfiguration(dnsName, vmSize)
2014-10-07 00:57:06 +04:00
if err != nil {
2015-03-20 03:41:25 +03:00
panic(err)
2014-10-07 00:57:06 +04:00
}
2015-03-20 03:41:25 +03:00
vmutils.ConfigureDeploymentFromPlatformImage(&role,
vmImage, fmt.Sprintf("http://%s.blob.core.windows.net/sdktest/%s.vhd", storageAccount, dnsName), "")
vmutils.ConfigureForLinux(&role, dnsName, userName, userPassword)
vmutils.ConfigureWithPublicSSH(&role)
requestId, err = virtualmachine.NewClient(client).CreateDeployment(role, dnsName)
2014-10-07 00:57:06 +04:00
if err != nil {
2015-03-20 03:41:25 +03:00
panic(err)
2014-10-07 00:57:06 +04:00
}
2015-03-20 03:41:25 +03:00
err = client.WaitAsyncOperation(requestId)
2014-10-07 00:57:06 +04:00
if err != nil {
2015-03-20 03:41:25 +03:00
panic(err)
2014-10-07 00:57:06 +04:00
}
}
```
2014-10-07 19:57:57 +04:00
# License
2015-04-29 04:49:55 +03:00
This project is published under [Apache 2.0 License](LICENSE).