saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:
https://repo.saltproject.io/
Apache License 2.0
14.16k stars 5.48k forks source link

salt-cloud - Azure - should be possible to specify virtual network & subnet in profile #24559

Closed iacopo-papalini closed 9 years ago

iacopo-papalini commented 9 years ago

In the profile file for an Azure provider, it should be possible to optionally specify which Virtual Network and Subnet the VM will belong to.

A resulting profile could look like:

test-profile:
  provider: test-azure-config
  image: 'b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-14_04_2-LTS-amd64-server-20150506-en-us-30GB'
  size: ExtraSmall
  location: 'West Europe'
  ssh_username: azureuser
  ssh_password: silly-password
  slot: production
  media_link: 'https://test-media-link.blob.core.windows.net/vhds'
  virtual_network_name: my-virtual-network
  subnet_name: SUBNET1

(the last two lines are not currently supported)

Since the 'azure' python library already support this, the change is really trivial:

diff --git a/salt/cloud/clouds/msazure.py b/salt/cloud/clouds/msazure.py
index 5548854..80d1175 100644
--- a/salt/cloud/clouds/msazure.py
+++ b/salt/cloud/clouds/msazure.py
@@ -487,6 +487,12 @@ def create(vm_):
         'role_size': vm_['size'],
         'network_config': network_config,
     }
+
+    if 'virtual_network_name' in vm_:
+        vm_kwargs['virtual_network_name'] = vm_['virtual_network_name']
+        if 'subnet_name' in vm_:
+            network_config.subnet_names.append(vm_['subnet_name'])
+

I tested the code with an Azure account and it seems to work

techhat commented 9 years ago

Thanks @iacopo-papalini! Would you be willing to put in a pull request so that you get credit?

iacopo-papalini commented 9 years ago

@techhat done. I hope I didn't mess up anything, it's been my first pull request ever.

rallytime commented 9 years ago

@iacopo-papalini That was perfect! I just merged your PR in. Would you consider this bug ready to be closed?

iacopo-papalini commented 9 years ago

Yes, as long as it does not break any test and since 'it works on my machine' :-) I haven't written any test for the feature, is it ok?

Il giorno mer 10 giu 2015 alle ore 17:58 Nicole Thomas < notifications@github.com> ha scritto:

@iacopo-papalini https://github.com/iacopo-papalini That was perfect! I just merged your PR in. Would you consider this bug ready to be closed?

— Reply to this email directly or view it on GitHub https://github.com/saltstack/salt/issues/24559#issuecomment-110810499.

rallytime commented 9 years ago

@iacopo-papalini Yes, that is ok. We don't require tests for all changes. I can add a "Need Testcase" label to this issue to remind us to write one. Then, when tests are written we'll link them here and remove the Needs Testcase label. (We change open and closed issues for this label.)

Thanks again for the report and the fix!