Azure Disk Attachment to VM using C# and StorageManagementClient/ComputeManagementClient
up vote
0
down vote
favorite
I already had a working C# ResourceManager application that could successfully attach disks to virtual machines. However I solved this with the nuget package Microsoft.Azure.Management.Compute
. But, since this package causes problems in other developments, it was decided not to use it anymore. For that we are using Microsoft.Azure.Management.Compute.Fluent
.
Until now I had the following code (short version):
var computeClient = new ComputeManagementClient(credentials) {
SubscriptionId = credentials.DefaultSubscriptionId };
var ObjVirtualMachines = computeClient.VirtualMachines.Get(resourcegroup, vmname);
ObjVirtualMachines.StorageProfile.DataDisks.Add(
new DataDisk(ObjVirtualMachines.StorageProfile.DataDisks.Count + 1,
"Attach", name, null, null, null, null, null,
new ManagedDiskParameters(resourceid, acctype)));
var newUpdatesVM = computeClient.VirtualMachines.CreateOrUpdate(
resourcegroup, ObjVirtualMachines.Name, ObjVirtualMachines);
That works pretty much, but as I said I have to translate to the other package.
First I thought I can solve these problems with the StorageManagementClient
.
But I did not get any options to update the virtual machine, because of type mismatch of the parameters.
Any ideas?
c# azure
add a comment |
up vote
0
down vote
favorite
I already had a working C# ResourceManager application that could successfully attach disks to virtual machines. However I solved this with the nuget package Microsoft.Azure.Management.Compute
. But, since this package causes problems in other developments, it was decided not to use it anymore. For that we are using Microsoft.Azure.Management.Compute.Fluent
.
Until now I had the following code (short version):
var computeClient = new ComputeManagementClient(credentials) {
SubscriptionId = credentials.DefaultSubscriptionId };
var ObjVirtualMachines = computeClient.VirtualMachines.Get(resourcegroup, vmname);
ObjVirtualMachines.StorageProfile.DataDisks.Add(
new DataDisk(ObjVirtualMachines.StorageProfile.DataDisks.Count + 1,
"Attach", name, null, null, null, null, null,
new ManagedDiskParameters(resourceid, acctype)));
var newUpdatesVM = computeClient.VirtualMachines.CreateOrUpdate(
resourcegroup, ObjVirtualMachines.Name, ObjVirtualMachines);
That works pretty much, but as I said I have to translate to the other package.
First I thought I can solve these problems with the StorageManagementClient
.
But I did not get any options to update the virtual machine, because of type mismatch of the parameters.
Any ideas?
c# azure
What doesi have to translate to the other package
mean? Could you please add more information about that?
– Tom Sun
Nov 22 at 0:47
Sure, i used the Microsoft.Azure.Management.Compute package, wich has is own namespace. Since this led to incompatibilities, I now have to work with the above package and therefore have a completely new namespace. But since I don't know this namespace, I thought someone would know about it, and have an idea how to implement it.
– Glowhollow
Nov 22 at 9:58
ok, cool, got it done
– Glowhollow
Nov 22 at 13:03
If it is resolved, please add it as an answer to close this thread.
– Tom Sun
Nov 23 at 1:17
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I already had a working C# ResourceManager application that could successfully attach disks to virtual machines. However I solved this with the nuget package Microsoft.Azure.Management.Compute
. But, since this package causes problems in other developments, it was decided not to use it anymore. For that we are using Microsoft.Azure.Management.Compute.Fluent
.
Until now I had the following code (short version):
var computeClient = new ComputeManagementClient(credentials) {
SubscriptionId = credentials.DefaultSubscriptionId };
var ObjVirtualMachines = computeClient.VirtualMachines.Get(resourcegroup, vmname);
ObjVirtualMachines.StorageProfile.DataDisks.Add(
new DataDisk(ObjVirtualMachines.StorageProfile.DataDisks.Count + 1,
"Attach", name, null, null, null, null, null,
new ManagedDiskParameters(resourceid, acctype)));
var newUpdatesVM = computeClient.VirtualMachines.CreateOrUpdate(
resourcegroup, ObjVirtualMachines.Name, ObjVirtualMachines);
That works pretty much, but as I said I have to translate to the other package.
First I thought I can solve these problems with the StorageManagementClient
.
But I did not get any options to update the virtual machine, because of type mismatch of the parameters.
Any ideas?
c# azure
I already had a working C# ResourceManager application that could successfully attach disks to virtual machines. However I solved this with the nuget package Microsoft.Azure.Management.Compute
. But, since this package causes problems in other developments, it was decided not to use it anymore. For that we are using Microsoft.Azure.Management.Compute.Fluent
.
Until now I had the following code (short version):
var computeClient = new ComputeManagementClient(credentials) {
SubscriptionId = credentials.DefaultSubscriptionId };
var ObjVirtualMachines = computeClient.VirtualMachines.Get(resourcegroup, vmname);
ObjVirtualMachines.StorageProfile.DataDisks.Add(
new DataDisk(ObjVirtualMachines.StorageProfile.DataDisks.Count + 1,
"Attach", name, null, null, null, null, null,
new ManagedDiskParameters(resourceid, acctype)));
var newUpdatesVM = computeClient.VirtualMachines.CreateOrUpdate(
resourcegroup, ObjVirtualMachines.Name, ObjVirtualMachines);
That works pretty much, but as I said I have to translate to the other package.
First I thought I can solve these problems with the StorageManagementClient
.
But I did not get any options to update the virtual machine, because of type mismatch of the parameters.
Any ideas?
c# azure
c# azure
edited Nov 23 at 13:11
Pedro Gaspar
425318
425318
asked Nov 21 at 17:11
Glowhollow
599
599
What doesi have to translate to the other package
mean? Could you please add more information about that?
– Tom Sun
Nov 22 at 0:47
Sure, i used the Microsoft.Azure.Management.Compute package, wich has is own namespace. Since this led to incompatibilities, I now have to work with the above package and therefore have a completely new namespace. But since I don't know this namespace, I thought someone would know about it, and have an idea how to implement it.
– Glowhollow
Nov 22 at 9:58
ok, cool, got it done
– Glowhollow
Nov 22 at 13:03
If it is resolved, please add it as an answer to close this thread.
– Tom Sun
Nov 23 at 1:17
add a comment |
What doesi have to translate to the other package
mean? Could you please add more information about that?
– Tom Sun
Nov 22 at 0:47
Sure, i used the Microsoft.Azure.Management.Compute package, wich has is own namespace. Since this led to incompatibilities, I now have to work with the above package and therefore have a completely new namespace. But since I don't know this namespace, I thought someone would know about it, and have an idea how to implement it.
– Glowhollow
Nov 22 at 9:58
ok, cool, got it done
– Glowhollow
Nov 22 at 13:03
If it is resolved, please add it as an answer to close this thread.
– Tom Sun
Nov 23 at 1:17
What does
i have to translate to the other package
mean? Could you please add more information about that?– Tom Sun
Nov 22 at 0:47
What does
i have to translate to the other package
mean? Could you please add more information about that?– Tom Sun
Nov 22 at 0:47
Sure, i used the Microsoft.Azure.Management.Compute package, wich has is own namespace. Since this led to incompatibilities, I now have to work with the above package and therefore have a completely new namespace. But since I don't know this namespace, I thought someone would know about it, and have an idea how to implement it.
– Glowhollow
Nov 22 at 9:58
Sure, i used the Microsoft.Azure.Management.Compute package, wich has is own namespace. Since this led to incompatibilities, I now have to work with the above package and therefore have a completely new namespace. But since I don't know this namespace, I thought someone would know about it, and have an idea how to implement it.
– Glowhollow
Nov 22 at 9:58
ok, cool, got it done
– Glowhollow
Nov 22 at 13:03
ok, cool, got it done
– Glowhollow
Nov 22 at 13:03
If it is resolved, please add it as an answer to close this thread.
– Tom Sun
Nov 23 at 1:17
If it is resolved, please add it as an answer to close this thread.
– Tom Sun
Nov 23 at 1:17
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
ok, here is the answer...
var ObjVirtualMachines = computeClient.VirtualMachines.GetAsync(ressgroup, virtualmname, null, new System.Threading.CancellationToken()).Result;
var storagemanagementclient = new StorageManagementClient(credentials) { SubscriptionId = credentials.DefaultSubscriptionId };
ObjVirtualMachines.StorageProfile.DataDisks.Add(new DataDisk(
ObjVirtualMachines.StorageProfile.DataDisks.Count + 1,
DiskCreateOptionTypes.Attach,
name,
null,
null,
null,
null,
new ManagedDiskParametersInner(resourceid, acctype)));
var newUpdateVM = computeClient.VirtualMachines.CreateOrUpdateAsync(ressgroup, virtualmname, ObjVirtualMachines);
and for the acctype use this.
var computeClient = new ComputeManagementClient(credentials) { SubscriptionId = credentials.DefaultSubscriptionId };
var disk = computeClient.Disks.ListAsync().Result.FirstOrDefault(p => p.Name == name);
var content = azure.Disks.GetById(disk.Id);
var resourceid = disk.Id;
var ressgroup = Resourcegroup.Get(context);
var virtualmname = VirtualMachineName.Get(context);
var acctype = getAccType(content.Sku.AccountType.ToString());
getAccType Function is this...
public StorageAccountTypes getAccType(string input)
{
switch (input)
{
case "StandardLRS": return StorageAccountTypes.StandardLRS;
case "PremiumLRS": return StorageAccountTypes.PremiumLRS;
// case "StandardSSDLRS":return "StandardSSD_LRS";
// case "UltraSSDLRS":return "UltraSSD_LRS";
default: return StorageAccountTypes.StandardLRS;
}
}
The Problem is that the AccType version in this namespace is limited to 2 (StandardLRS and PremiumLRS) . In the old version you had 4 different versions of it.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
ok, here is the answer...
var ObjVirtualMachines = computeClient.VirtualMachines.GetAsync(ressgroup, virtualmname, null, new System.Threading.CancellationToken()).Result;
var storagemanagementclient = new StorageManagementClient(credentials) { SubscriptionId = credentials.DefaultSubscriptionId };
ObjVirtualMachines.StorageProfile.DataDisks.Add(new DataDisk(
ObjVirtualMachines.StorageProfile.DataDisks.Count + 1,
DiskCreateOptionTypes.Attach,
name,
null,
null,
null,
null,
new ManagedDiskParametersInner(resourceid, acctype)));
var newUpdateVM = computeClient.VirtualMachines.CreateOrUpdateAsync(ressgroup, virtualmname, ObjVirtualMachines);
and for the acctype use this.
var computeClient = new ComputeManagementClient(credentials) { SubscriptionId = credentials.DefaultSubscriptionId };
var disk = computeClient.Disks.ListAsync().Result.FirstOrDefault(p => p.Name == name);
var content = azure.Disks.GetById(disk.Id);
var resourceid = disk.Id;
var ressgroup = Resourcegroup.Get(context);
var virtualmname = VirtualMachineName.Get(context);
var acctype = getAccType(content.Sku.AccountType.ToString());
getAccType Function is this...
public StorageAccountTypes getAccType(string input)
{
switch (input)
{
case "StandardLRS": return StorageAccountTypes.StandardLRS;
case "PremiumLRS": return StorageAccountTypes.PremiumLRS;
// case "StandardSSDLRS":return "StandardSSD_LRS";
// case "UltraSSDLRS":return "UltraSSD_LRS";
default: return StorageAccountTypes.StandardLRS;
}
}
The Problem is that the AccType version in this namespace is limited to 2 (StandardLRS and PremiumLRS) . In the old version you had 4 different versions of it.
add a comment |
up vote
0
down vote
ok, here is the answer...
var ObjVirtualMachines = computeClient.VirtualMachines.GetAsync(ressgroup, virtualmname, null, new System.Threading.CancellationToken()).Result;
var storagemanagementclient = new StorageManagementClient(credentials) { SubscriptionId = credentials.DefaultSubscriptionId };
ObjVirtualMachines.StorageProfile.DataDisks.Add(new DataDisk(
ObjVirtualMachines.StorageProfile.DataDisks.Count + 1,
DiskCreateOptionTypes.Attach,
name,
null,
null,
null,
null,
new ManagedDiskParametersInner(resourceid, acctype)));
var newUpdateVM = computeClient.VirtualMachines.CreateOrUpdateAsync(ressgroup, virtualmname, ObjVirtualMachines);
and for the acctype use this.
var computeClient = new ComputeManagementClient(credentials) { SubscriptionId = credentials.DefaultSubscriptionId };
var disk = computeClient.Disks.ListAsync().Result.FirstOrDefault(p => p.Name == name);
var content = azure.Disks.GetById(disk.Id);
var resourceid = disk.Id;
var ressgroup = Resourcegroup.Get(context);
var virtualmname = VirtualMachineName.Get(context);
var acctype = getAccType(content.Sku.AccountType.ToString());
getAccType Function is this...
public StorageAccountTypes getAccType(string input)
{
switch (input)
{
case "StandardLRS": return StorageAccountTypes.StandardLRS;
case "PremiumLRS": return StorageAccountTypes.PremiumLRS;
// case "StandardSSDLRS":return "StandardSSD_LRS";
// case "UltraSSDLRS":return "UltraSSD_LRS";
default: return StorageAccountTypes.StandardLRS;
}
}
The Problem is that the AccType version in this namespace is limited to 2 (StandardLRS and PremiumLRS) . In the old version you had 4 different versions of it.
add a comment |
up vote
0
down vote
up vote
0
down vote
ok, here is the answer...
var ObjVirtualMachines = computeClient.VirtualMachines.GetAsync(ressgroup, virtualmname, null, new System.Threading.CancellationToken()).Result;
var storagemanagementclient = new StorageManagementClient(credentials) { SubscriptionId = credentials.DefaultSubscriptionId };
ObjVirtualMachines.StorageProfile.DataDisks.Add(new DataDisk(
ObjVirtualMachines.StorageProfile.DataDisks.Count + 1,
DiskCreateOptionTypes.Attach,
name,
null,
null,
null,
null,
new ManagedDiskParametersInner(resourceid, acctype)));
var newUpdateVM = computeClient.VirtualMachines.CreateOrUpdateAsync(ressgroup, virtualmname, ObjVirtualMachines);
and for the acctype use this.
var computeClient = new ComputeManagementClient(credentials) { SubscriptionId = credentials.DefaultSubscriptionId };
var disk = computeClient.Disks.ListAsync().Result.FirstOrDefault(p => p.Name == name);
var content = azure.Disks.GetById(disk.Id);
var resourceid = disk.Id;
var ressgroup = Resourcegroup.Get(context);
var virtualmname = VirtualMachineName.Get(context);
var acctype = getAccType(content.Sku.AccountType.ToString());
getAccType Function is this...
public StorageAccountTypes getAccType(string input)
{
switch (input)
{
case "StandardLRS": return StorageAccountTypes.StandardLRS;
case "PremiumLRS": return StorageAccountTypes.PremiumLRS;
// case "StandardSSDLRS":return "StandardSSD_LRS";
// case "UltraSSDLRS":return "UltraSSD_LRS";
default: return StorageAccountTypes.StandardLRS;
}
}
The Problem is that the AccType version in this namespace is limited to 2 (StandardLRS and PremiumLRS) . In the old version you had 4 different versions of it.
ok, here is the answer...
var ObjVirtualMachines = computeClient.VirtualMachines.GetAsync(ressgroup, virtualmname, null, new System.Threading.CancellationToken()).Result;
var storagemanagementclient = new StorageManagementClient(credentials) { SubscriptionId = credentials.DefaultSubscriptionId };
ObjVirtualMachines.StorageProfile.DataDisks.Add(new DataDisk(
ObjVirtualMachines.StorageProfile.DataDisks.Count + 1,
DiskCreateOptionTypes.Attach,
name,
null,
null,
null,
null,
new ManagedDiskParametersInner(resourceid, acctype)));
var newUpdateVM = computeClient.VirtualMachines.CreateOrUpdateAsync(ressgroup, virtualmname, ObjVirtualMachines);
and for the acctype use this.
var computeClient = new ComputeManagementClient(credentials) { SubscriptionId = credentials.DefaultSubscriptionId };
var disk = computeClient.Disks.ListAsync().Result.FirstOrDefault(p => p.Name == name);
var content = azure.Disks.GetById(disk.Id);
var resourceid = disk.Id;
var ressgroup = Resourcegroup.Get(context);
var virtualmname = VirtualMachineName.Get(context);
var acctype = getAccType(content.Sku.AccountType.ToString());
getAccType Function is this...
public StorageAccountTypes getAccType(string input)
{
switch (input)
{
case "StandardLRS": return StorageAccountTypes.StandardLRS;
case "PremiumLRS": return StorageAccountTypes.PremiumLRS;
// case "StandardSSDLRS":return "StandardSSD_LRS";
// case "UltraSSDLRS":return "UltraSSD_LRS";
default: return StorageAccountTypes.StandardLRS;
}
}
The Problem is that the AccType version in this namespace is limited to 2 (StandardLRS and PremiumLRS) . In the old version you had 4 different versions of it.
answered Nov 23 at 10:03
Glowhollow
599
599
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53417327%2fazure-disk-attachment-to-vm-using-c-sharp-and-storagemanagementclient-computeman%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What does
i have to translate to the other package
mean? Could you please add more information about that?– Tom Sun
Nov 22 at 0:47
Sure, i used the Microsoft.Azure.Management.Compute package, wich has is own namespace. Since this led to incompatibilities, I now have to work with the above package and therefore have a completely new namespace. But since I don't know this namespace, I thought someone would know about it, and have an idea how to implement it.
– Glowhollow
Nov 22 at 9:58
ok, cool, got it done
– Glowhollow
Nov 22 at 13:03
If it is resolved, please add it as an answer to close this thread.
– Tom Sun
Nov 23 at 1:17