Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

169
Visualizações
syntax to resize an Azure virtual machine programatically

Using C#, how do I resize an Azure virtual machine that is already stopped? The Microsoft documentation is non-existent or impossible to discover. In my .Net Standard 2.0 class library I am referencing the Nuget package Microsoft.Azure.Management.Fluent 1.37.1 and have tried the code below.

using Microsoft.Azure.Management.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent.Authentication;
...

// get Azure client
string clientId = ...;
string clientSecret = ...;
string subscriptionId = ...;
string tenantId = ...;
AzureEnvironment env = ...;
AzureCredentials creds = new AzureCredentialsFactory().FromServicePrincipal(clientId, clientSecret, tenantId, env);
IAzure azure = Microsoft.Azure.Management.Fluent.Azure
                   .Configure()
                   .WithLogLevel(HttpLoggingDelegatingHandler.Level.BodyAndHeaders)
                   .Authenticate(creds)
                   .WithSubscription(subscriptionId);

// get virtual machine
string resourceGroupName = "MyResourceGroup";
string machineName = "MyHostname";
IVirtualMachine vm = await azure.VirtualMachines.GetByResourceGroupAsync(resourceGroupName, machineName)

// resize virtual machine
VirtualMachineSizeTypes size = ...;
vm.Inner.HardwareProfile.VmSize = size;
vm.Inner.Validate();
vm.Update();  // nothing happens, virtual machine does not resize

On the last line, vm.Update() does nothing. In the Azure portal I can see that the virtual machine has not resized even after refreshing the portal multiple times.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

The Azure API discoverability is terrible. I finally got resize working. Replace the last 3 lines

vm.Inner.HardwareProfile.VmSize = size;
vm.Inner.Validate();
vm.Update();

with

VirtualMachineUpdate parameters = new VirtualMachineUpdate()
{
    HardwareProfile = new HardwareProfile(size),
};
VirtualMachineInner response = await azure.VirtualMachines.Inner.UpdateAsync(resourceGroupName, vm.Name, parameters);
over 4 years ago · Santiago Trujillo Relatório

0

You had it almost right. Update() is a fluent operator:

var size = VirtualMachineSizeTypes.StandardB2s;
await vm.Update()
 .WithSize(size)
 .ApplyAsync();
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda