本文整理汇总了Golang中github.com/Azure/azure-sdk-for-go/management/virtualmachine.NewClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewClient函数的具体用法?Golang NewClient怎么用?Golang NewClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewClient函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Run
func (s *StepCreateVm) Run(state multistep.StateBag) multistep.StepAction {
client := state.Get(constants.RequestManager).(management.Client)
ui := state.Get("ui").(packer.Ui)
errorMsg := "Error creating temporary Azure VM: %s"
ui.Say("Creating temporary Azure VM...")
osImageName := state.Get(constants.OSImageName).(string)
if len(osImageName) == 0 {
err := fmt.Errorf(errorMsg, fmt.Errorf("osImageName is empty"))
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
isOSImage := state.Get(constants.IsOSImage).(bool)
mediaLoc := fmt.Sprintf("https://%s.blob.core.windows.net/%s/%s.vhd", s.StorageAccount, s.StorageContainer, s.TmpVmName)
role := createRole(isOSImage, s.TmpVmName, s.InstanceSize, s.Username, s.Password, osImageName, mediaLoc)
if err := retry.ExecuteAsyncOperation(client, func() (management.OperationID, error) {
return vm.NewClient(client).CreateDeployment(role, s.TmpServiceName, vm.CreateDeploymentOptions{})
}); err != nil {
err := fmt.Errorf(errorMsg, err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
state.Put(constants.VmExists, 1)
state.Put(constants.DiskExists, 1)
return multistep.ActionContinue
}
开发者ID:leeelavinoth,项目名称:packer-azure,代码行数:34,代码来源:step_create_vm.go
示例2: TestRoleStateOperations
func TestRoleStateOperations(t *testing.T) {
client := testutils.GetTestClient(t)
vmname := GenerateName()
sa := GetTestStorageAccount(t, client)
location := sa.StorageServiceProperties.Location
role := NewVMConfiguration(vmname, "Standard_D3")
ConfigureDeploymentFromPlatformImage(&role,
GetLinuxTestImage(t, client).Name,
fmt.Sprintf("http://%s.blob.core.windows.net/sdktest/%s.vhd", sa.ServiceName, vmname),
GenerateName())
ConfigureForLinux(&role, "myvm", "azureuser", GeneratePassword())
createRoleConfiguration(t, client, role, location)
vmc := vm.NewClient(client)
if err := Await(client, func() (management.OperationID, error) {
return vmc.ShutdownRole(vmname, vmname, vmname, vm.PostShutdownActionStopped)
}); err != nil {
t.Error(err)
}
if err := Await(client, func() (management.OperationID, error) {
return vmc.StartRole(vmname, vmname, vmname)
}); err != nil {
t.Error(err)
}
if err := Await(client, func() (management.OperationID, error) {
return vmc.RestartRole(vmname, vmname, vmname)
}); err != nil {
t.Error(err)
}
deleteHostedService(t, client, vmname)
}
开发者ID:garimakhulbe,项目名称:azure-sdk-for-go,代码行数:34,代码来源:integration_test.go
示例3: GetState
func (d *Driver) GetState() (state.State, error) {
if err := d.setUserSubscription(); err != nil {
return state.Error, err
}
client, err := d.getClient()
if err != nil {
return state.Error, err
}
dockerVM, err := virtualmachine.NewClient(client).GetDeployment(d.MachineName, d.MachineName)
if err != nil {
if strings.Contains(err.Error(), "Code: ResourceNotFound") {
return state.Error, errors.New("Azure host was not found. Please check your Azure subscription.")
}
return state.Error, err
}
vmState := dockerVM.RoleInstanceList[0].PowerState
switch vmState {
case "Started":
return state.Running, nil
case "Starting":
return state.Starting, nil
case "Stopped":
return state.Stopped, nil
}
return state.None, nil
}
开发者ID:containerx,项目名称:machine,代码行数:31,代码来源:azure.go
示例4: updateRoleResourceExtension
func (c *comm) updateRoleResourceExtension(
nameOfReference, nameOfPublisher, nameOfExtension, versionOfExtension, state string,
params []vm.ResourceExtensionParameter) error {
client := c.config.ManagementClient
serviceName := c.config.ServiceName
vmName := c.config.VmName
log.Println("Updating Role Resource Extension...")
role := vm.Role{}
vmutils.AddAzureVMExtensionConfiguration(&role,
nameOfExtension, nameOfPublisher, versionOfExtension, nameOfReference, state, []byte{}, []byte{})
// HACK-paulmey: clean up later
(*role.ResourceExtensionReferences)[0].ParameterValues = params
if err := retry.ExecuteAsyncOperation(client, func() (management.OperationID, error) {
return vm.NewClient(client).UpdateRole(serviceName, vmName, vmName, role)
}); err != nil {
return err
}
return nil
}
开发者ID:kolargol,项目名称:packer-azure,代码行数:25,代码来源:communicator.go
示例5: pollCustomScriptIsUninstalled
func (c *comm) pollCustomScriptIsUninstalled() error {
client := c.config.ManagementClient
log.Println("Polling CustomScript is uninstalled. It may take some time...")
serviceName := c.config.ServiceName
vmName := c.config.VmName
const attemptLimit uint = 30
repeatCount := attemptLimit
for ; repeatCount > 0; repeatCount-- {
deployment, err := vm.NewClient(client).GetDeployment(serviceName, vmName)
if err != nil {
return err
}
if deployment.RoleInstanceList[0].InstanceStatus == vm.InstanceStatusReadyRole {
if len(deployment.RoleInstanceList[0].ResourceExtensionStatusList) == 0 {
break
}
}
c.sleepSec(45)
}
if repeatCount == 0 {
err := fmt.Errorf("InstanceStatus is not 'ReadyRole' or ResourceExtensionStatusList is not empty after %d attempts", attemptLimit)
return err
}
return nil
}
开发者ID:kolargol,项目名称:packer-azure,代码行数:31,代码来源:communicator.go
示例6: Run
func (*StepCreateVm) Run(state multistep.StateBag) multistep.StepAction {
client := state.Get(constants.RequestManager).(management.Client)
ui := state.Get("ui").(packer.Ui)
config := state.Get(constants.Config).(*Config)
errorMsg := "Error Creating Temporary Azure VM: %s"
ui.Say("Creating Temporary Azure VM...")
role := state.Get("role").(*vm.Role)
options := vm.CreateDeploymentOptions{}
if config.VNet != "" && config.Subnet != "" {
options.VirtualNetworkName = config.VNet
}
if err := retry.ExecuteAsyncOperation(client, func() (management.OperationID, error) {
return vm.NewClient(client).CreateDeployment(*role, config.tmpServiceName, options)
}); err != nil {
err := fmt.Errorf(errorMsg, err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
state.Put(constants.VmExists, 1)
state.Put(constants.DiskExists, 1)
return multistep.ActionContinue
}
开发者ID:lmeyemezu,项目名称:packer-azure,代码行数:30,代码来源:step_create_vm.go
示例7: NewClientFromSettingsFile
// NewClientFromSettingsFile returns a new Azure management
// client created using a publish settings file.
func (c *Config) NewClientFromSettingsFile() (*Client, error) {
if _, err := os.Stat(c.SettingsFile); os.IsNotExist(err) {
return nil, fmt.Errorf("Publish Settings file %q does not exist!", c.SettingsFile)
}
mc, err := management.ClientFromPublishSettingsFile(c.SettingsFile, c.SubscriptionID)
if err != nil {
return nil, nil
}
return &Client{
mgmtClient: mc,
affinityGroupClient: affinitygroup.NewClient(mc),
hostedServiceClient: hostedservice.NewClient(mc),
secGroupClient: networksecuritygroup.NewClient(mc),
osImageClient: osimage.NewClient(mc),
sqlClient: sql.NewClient(mc),
storageServiceClient: storageservice.NewClient(mc),
vmClient: virtualmachine.NewClient(mc),
vmDiskClient: virtualmachinedisk.NewClient(mc),
vmImageClient: virtualmachineimage.NewClient(mc),
vnetClient: virtualnetwork.NewClient(mc),
mutex: &sync.Mutex{},
}, nil
}
开发者ID:rgl,项目名称:terraform,代码行数:27,代码来源:config.go
示例8: main
func main() {
psPath := "path/to/publishSettings"
dnsName := "test-vm-from-go"
storageAccount := "mystorageaccount"
location := "central us"
vmSize := "Small"
vmImage := "b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-14_04-LTS-amd64-server-20140724-en-us-30GB"
userName := "testuser"
userPassword := "Test123"
fmt.Println("Create client")
client, err := management.ClientFromPublishSettingsFile(fmt.Sprintf("%s.publishsettings", psPath), "")
if err != nil {
panic(err)
}
fmt.Println("Create hosted service")
if err := hostedservice.NewClient(client).CreateHostedService(hostedservice.CreateHostedServiceParameters{
ServiceName: dnsName,
Location: location,
Label: base64.StdEncoding.EncodeToString([]byte(dnsName))}); err != nil {
panic(err)
}
fmt.Println("Create storage account")
_, err = storageservice.NewClient(client).CreateStorageService(storageservice.StorageAccountCreateParameters{
ServiceName: storageAccount,
Label: base64.URLEncoding.EncodeToString([]byte(storageAccount)),
Location: location,
AccountType: storageservice.AccountTypeStandardLRS})
if err != nil {
panic(err)
}
fmt.Println("Create virtual machine")
role := vmutils.NewVMConfiguration(dnsName, vmSize)
vmutils.ConfigureDeploymentFromPlatformImage(
&role,
vmImage,
fmt.Sprintf("http://%s.blob.core.windows.net/%s/%s.vhd", storageAccount, dnsName, dnsName),
"")
vmutils.ConfigureForLinux(&role, dnsName, userName, userPassword)
vmutils.ConfigureWithPublicSSH(&role)
fmt.Println("Deploy")
operationID, err := virtualmachine.NewClient(client).
CreateDeployment(role, dnsName, virtualmachine.CreateDeploymentOptions{})
if err != nil {
panic(err)
}
fmt.Println("Waiting...")
if err = client.WaitForOperation(operationID, nil); err != nil {
panic(err)
}
}
开发者ID:garimakhulbe,项目名称:azure-sdk-for-go,代码行数:56,代码来源:example.go
示例9: WaitForDeploymentInstanceStatus
// WaitForDeploymentInstanceStatus blocks until all role instances in deployment
// reach desired InstanceStatus.
func WaitForDeploymentInstanceStatus(client management.Client, cloudServiceName, deploymentName string, desiredInstanceStatus vm.InstanceStatus) error {
for {
deployment, err := vm.NewClient(client).GetDeployment(cloudServiceName, deploymentName)
if err != nil {
return err
}
if allInstancesInInstanceStatus(deployment.RoleInstanceList, desiredInstanceStatus) {
return nil
}
time.Sleep(2 * time.Second)
}
}
开发者ID:RezaDKhan,项目名称:terraform,代码行数:14,代码来源:rolestate.go
示例10: newMachine
func newMachine(bm *provider.BaseMachine) (provider.Machine, error) {
m := &Machine{BaseMachine: bm}
cred := m.Cred()
c, err := management.ClientFromPublishSettingsDataWithConfig([]byte(cred.PublishSettings), cred.SubscriptionID, management.DefaultConfig())
if err != nil {
return nil, err
}
vmclient := vm.NewClient(c)
m.AzureClient = c
m.AzureVMClient = &vmclient
return m, nil
}
开发者ID:koding,项目名称:koding,代码行数:16,代码来源:azure.go
示例11: createRoleConfiguration
func createRoleConfiguration(t *testing.T, client management.Client, role vm.Role, location string) {
vmc := vm.NewClient(client)
hsc := hostedservice.NewClient(client)
vmname := role.RoleName
if err := hsc.CreateHostedService(hostedservice.CreateHostedServiceParameters{
ServiceName: vmname, Location: location,
Label: base64.StdEncoding.EncodeToString([]byte(vmname))}); err != nil {
t.Error(err)
}
if err := Await(client, func() (management.OperationID, error) {
return vmc.CreateDeployment(role, vmname, vm.CreateDeploymentOptions{})
}); err != nil {
t.Error(err)
}
}
开发者ID:garimakhulbe,项目名称:azure-sdk-for-go,代码行数:17,代码来源:integration_test.go
示例12: Stop
func (d *Driver) Stop() error {
if err := d.setUserSubscription(); err != nil {
return err
}
client, err := d.getClient()
if err != nil {
return err
}
if _, err := virtualmachine.NewClient(client).ShutdownRole(d.MachineName, d.MachineName, d.MachineName); err != nil {
return err
}
d.IPAddress = ""
return nil
}
开发者ID:containerx,项目名称:machine,代码行数:17,代码来源:azure.go
示例13: Restart
func (d *Driver) Restart() error {
if err := d.setUserSubscription(); err != nil {
return err
}
client, err := d.getClient()
if err != nil {
return err
}
if _, err := virtualmachine.NewClient(client).RestartRole(d.MachineName, d.MachineName, d.MachineName); err != nil {
return err
}
d.IPAddress, err = d.GetIP()
return err
}
开发者ID:containerx,项目名称:machine,代码行数:17,代码来源:azure.go
示例14: main
func main() {
dnsName := "test-vm-from-go"
storageAccount := "gosdktest"
location := "West US"
vmSize := "Small"
vmImage := "b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-14_04-LTS-amd64-server-20140724-en-us-30GB"
userName := "testuser"
userPassword := "Test123"
client, err := management.ClientFromPublishSettingsFile("/Users/niklasg/Downloads/Internal-credentials.publishsettings", "")
if err != nil {
panic(err)
}
// create hosted service
if err := hostedservice.NewClient(client).CreateHostedService(hostedservice.CreateHostedServiceParameters{
ServiceName: dnsName,
Location: location,
Label: base64.StdEncoding.EncodeToString([]byte(dnsName))}); err != nil {
if azErr, ok := err.(management.AzureError); !ok || azErr.Code != "ConflictError" {
panic(err)
}
}
// create virtual machine
role := vmutils.NewVMConfiguration(dnsName, vmSize)
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)
operationID, err := virtualmachine.NewClient(client).
CreateDeployment(role, dnsName, virtualmachine.CreateDeploymentOptions{})
if err != nil {
panic(err)
}
if err := client.WaitForOperation(operationID, nil); err != nil {
panic(err)
}
}
开发者ID:NiklasGustafsson,项目名称:azure-go-samples,代码行数:44,代码来源:createvm01.go
示例15: requestCustomScriptExtension
func (c *comm) requestCustomScriptExtension() (*vm.ResourceExtension, error) {
log.Println("Requesting resource extensions...")
list, err := vm.NewClient(c.config.ManagementClient).GetResourceExtensions()
if err != nil {
return nil, err
}
log.Println("Searching for CustomScriptExtension...")
for _, ext := range list {
if ext.Name == "CustomScriptExtension" {
log.Printf("CustomScriptExtension: %v\n\n", ext)
return &ext, nil
}
}
return nil, fmt.Errorf("Couldn't find CustomScriptExtension, am I too old or is Azure broken?")
}
开发者ID:kolargol,项目名称:packer-azure,代码行数:19,代码来源:communicator.go
示例16: getHostname
func (d *Driver) getHostname() (string, error) {
if err := d.setUserSubscription(); err != nil {
return "", err
}
client, err := d.getClient()
if err != nil {
return "", err
}
dr, err := virtualmachine.NewClient(client).GetDeployment(d.MachineName, d.MachineName)
if err != nil {
return "", err
}
// remove "http://" and ending "/" from the URL to get the DNS name
return dr.URL[7 : len(dr.URL)-1], nil
}
开发者ID:containerx,项目名称:machine,代码行数:19,代码来源:azure.go
示例17: Example
func Example() {
dnsName := "test-vm-from-go"
storageAccount := "mystorageaccount"
location := "West US"
vmSize := "Small"
vmImage := "b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-14_04-LTS-amd64-server-20140724-en-us-30GB"
userName := "testuser"
userPassword := "Test123"
client, err := management.ClientFromPublishSettingsFile("path/to/downloaded.publishsettings", "")
if err != nil {
panic(err)
}
// create hosted service
if err := hostedservice.NewClient(client).CreateHostedService(hostedservice.CreateHostedServiceParameters{
ServiceName: dnsName,
Location: location,
Label: base64.StdEncoding.EncodeToString([]byte(dnsName))}); err != nil {
panic(err)
}
// create virtual machine
role := NewVMConfiguration(dnsName, vmSize)
ConfigureDeploymentFromPlatformImage(
&role,
vmImage,
fmt.Sprintf("http://%s.blob.core.windows.net/sdktest/%s.vhd", storageAccount, dnsName),
"")
ConfigureForLinux(&role, dnsName, userName, userPassword)
ConfigureWithPublicSSH(&role)
operationID, err := virtualmachine.NewClient(client).
CreateDeployment(role, dnsName, virtualmachine.CreateDeploymentOptions{})
if err != nil {
panic(err)
}
err = client.WaitForOperation(operationID, nil)
if err != nil {
panic(err)
}
}
开发者ID:containerx,项目名称:machine,代码行数:42,代码来源:examples_test.go
示例18: NewClientFromSettingsData
func (c *Config) NewClientFromSettingsData() (*Client, error) {
mc, err := management.ClientFromPublishSettingsData(c.Settings, c.SubscriptionID)
if err != nil {
return nil, nil
}
return &Client{
mgmtClient: mc,
affinityGroupClient: affinitygroup.NewClient(mc),
hostedServiceClient: hostedservice.NewClient(mc),
secGroupClient: networksecuritygroup.NewClient(mc),
osImageClient: osimage.NewClient(mc),
sqlClient: sql.NewClient(mc),
storageServiceClient: storageservice.NewClient(mc),
vmClient: virtualmachine.NewClient(mc),
vmDiskClient: virtualmachinedisk.NewClient(mc),
vmImageClient: virtualmachineimage.NewClient(mc),
vnetClient: virtualnetwork.NewClient(mc),
mutex: &sync.Mutex{},
}, nil
}
开发者ID:saulshanabrook,项目名称:terraform,代码行数:21,代码来源:config.go
示例19: Run
func (s *StepStopVm) Run(state multistep.StateBag) multistep.StepAction {
client := state.Get(constants.RequestManager).(management.Client)
ui := state.Get(constants.Ui).(packer.Ui)
errorMsg := "Error Stopping Temporary Azure VM: %s"
ui.Say("Stopping Temporary Azure VM...")
if err := retry.ExecuteAsyncOperation(client, func() (management.OperationID, error) {
return vm.NewClient(client).ShutdownRole(s.TmpServiceName, s.TmpVmName, s.TmpVmName)
}); err != nil {
err := fmt.Errorf(errorMsg, err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
state.Put(constants.VmRunning, 0)
return multistep.ActionContinue
}
开发者ID:paulmey,项目名称:packer-azure,代码行数:21,代码来源:step_stop_vm.go
示例20: Run
func (s *StepCreateImage) Run(state multistep.StateBag) multistep.StepAction {
client := state.Get(constants.RequestManager).(management.Client)
ui := state.Get(constants.Ui).(packer.Ui)
errorMsg := "Error Creating Azure Image: %s"
ui.Say("Creating Azure Image. If Successful, This Will Remove the Temporary VM...")
if err := retry.ExecuteAsyncOperation(client, func() (management.OperationID, error) {
return vm.NewClient(client).CaptureRole(s.TmpServiceName, s.TmpVmName, s.TmpVmName,
s.UserImageName, s.UserImageLabel, nil)
}); err != nil {
err := fmt.Errorf(errorMsg, err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
// CatpureVMImage removes the VM
state.Put(constants.ImageCreated, 1)
state.Put(constants.VmExists, 0)
return multistep.ActionContinue
}
开发者ID:Gamesparks-OSS,项目名称:packer-azure,代码行数:24,代码来源:step_create_image.go
注:本文中的github.com/Azure/azure-sdk-for-go/management/virtualmachine.NewClient函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论