Skip to content

Commit 087d837

Browse files
committed
Fixed pre-commit issues
1 parent fab4190 commit 087d837

File tree

2 files changed

+63
-45
lines changed

2 files changed

+63
-45
lines changed

src/saltext/vmware/modules/vm.py

Lines changed: 53 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,7 @@ def __virtual__():
2626
return __virtualname__
2727

2828

29-
def list_(
30-
service_instance=None,
31-
datacenter_name=None,
32-
cluster_name=None,
33-
host_name=None
34-
):
29+
def list_(service_instance=None, datacenter_name=None, cluster_name=None, host_name=None):
3530
"""
3631
Returns virtual machines.
3732
@@ -49,28 +44,32 @@ def list_(
4944
"""
5045
log.debug("Running vmware_vm.list")
5146
if service_instance is None:
52-
service_instance = connect.get_service_instance(opts=__opts__, pillar=__pillar__)
47+
service_instance = connect.get_service_instance(
48+
opts=__opts__, pillar=__pillar__, name=credential_name
49+
)
5350
return utils_vm.list_vms(
5451
service_instance=service_instance,
5552
host_name=host_name,
5653
cluster_name=cluster_name,
57-
datacenter_name=datacenter_name
54+
datacenter_name=datacenter_name,
5855
)
5956

6057

61-
def list_templates(service_instance=None):
58+
def list_templates(service_instance=None, credential_name=None):
6259
"""
6360
Returns virtual machines tempates.
6461
6562
service_instance
6663
(optional) The Service Instance from which to obtain managed object references.
6764
"""
6865
if service_instance is None:
69-
service_instance = connect.get_service_instance(opts=__opts__, pillar=__pillar__)
66+
service_instance = connect.get_service_instance(
67+
opts=__opts__, pillar=__pillar__, name=credential_name
68+
)
7069
return utils_vm.list_vm_templates(service_instance)
7170

7271

73-
def path(vm_name, service_instance=None):
72+
def path(vm_name, service_instance=None, credential_name=None):
7473
"""
7574
Returns specified virtual machine path.
7675
@@ -81,7 +80,9 @@ def path(vm_name, service_instance=None):
8180
The Service Instance from which to obtain managed object references.
8281
"""
8382
if service_instance is None:
84-
service_instance = connect.get_service_instance(opts=__opts__, pillar=__pillar__)
83+
service_instance = connect.get_service_instance(
84+
opts=__opts__, pillar=__pillar__, name=credential_name
85+
)
8586
vm_ref = utils_common.get_mor_by_property(
8687
service_instance,
8788
vim.VirtualMachine,
@@ -90,7 +91,7 @@ def path(vm_name, service_instance=None):
9091
return utils_common.get_path(vm_ref, service_instance)
9192

9293

93-
def _deploy_ovf(name, host_name, ovf, service_instance=None):
94+
def _deploy_ovf(name, host_name, ovf, service_instance=None, credential_name=None):
9495
"""
9596
Helper fuctions that takes in a OVF file to create a virtual machine.
9697
@@ -109,7 +110,9 @@ def _deploy_ovf(name, host_name, ovf, service_instance=None):
109110
The Service Instance from which to obtain managed object references.
110111
"""
111112
if service_instance is None:
112-
service_instance = connect.get_service_instance(opts=__opts__, pillar=__pillar__)
113+
service_instance = connect.get_service_instance(
114+
opts=__opts__, pillar=__pillar__, name=credential_name
115+
)
113116

114117
vms = list_(service_instance)
115118
if name in vms:
@@ -138,7 +141,7 @@ def _deploy_ovf(name, host_name, ovf, service_instance=None):
138141
return vm_ref
139142

140143

141-
def deploy_ovf(vm_name, host_name, ovf_path, service_instance=None):
144+
def deploy_ovf(vm_name, host_name, ovf_path, service_instance=None, credential_name=None):
142145
"""
143146
Deploy a virtual machine from an OVF
144147
@@ -155,11 +158,11 @@ def deploy_ovf(vm_name, host_name, ovf_path, service_instance=None):
155158
(optional) The Service Instance from which to obtain managed object references.
156159
"""
157160
ovf = utils_vm.read_ovf_file(ovf_path)
158-
_deploy_ovf(vm_name, host_name, ovf, service_instance)
161+
_deploy_ovf(vm_name, host_name, ovf, service_instance, credential_name)
159162
return {"deployed": True}
160163

161164

162-
def deploy_ova(vm_name, host_name, ova_path, service_instance=None):
165+
def deploy_ova(vm_name, host_name, ova_path, service_instance=None, credential_name=None):
163166
"""
164167
Deploy a virtual machine from an OVA
165168
@@ -176,11 +179,11 @@ def deploy_ova(vm_name, host_name, ova_path, service_instance=None):
176179
(optional) The Service Instance from which to obtain managed object references.
177180
"""
178181
ovf = utils_vm.read_ovf_from_ova(ova_path)
179-
_deploy_ovf(vm_name, host_name, ovf, service_instance)
182+
_deploy_ovf(vm_name, host_name, ovf, service_instance, credential_name)
180183
return {"deployed": True}
181184

182185

183-
def deploy_template(vm_name, template_name, host_name, service_instance=None):
186+
def deploy_template(vm_name, template_name, host_name, service_instance=None, credential_name=None):
184187
"""
185188
Deploy a virtual machine from a template virtual machine.
186189
@@ -197,7 +200,9 @@ def deploy_template(vm_name, template_name, host_name, service_instance=None):
197200
(optional) The Service Instance from which to obtain managed object references.
198201
"""
199202
if service_instance is None:
200-
service_instance = connect.get_service_instance(opts=__opts__, pillar=__pillar__)
203+
service_instance = connect.get_service_instance(
204+
opts=__opts__, pillar=__pillar__, name=credential_name
205+
)
201206

202207
vms = list_(service_instance)
203208
if vm_name in vms:
@@ -220,7 +225,7 @@ def deploy_template(vm_name, template_name, host_name, service_instance=None):
220225
return {"deployed": True}
221226

222227

223-
def info(vm_name=None, service_instance=None):
228+
def info(vm_name=None, service_instance=None, credential_name=None):
224229
"""
225230
Return basic info about a vSphere VM guest
226231
@@ -233,7 +238,9 @@ def info(vm_name=None, service_instance=None):
233238
vms = []
234239
info = {}
235240
if service_instance is None:
236-
service_instance = connect.get_service_instance(opts=__opts__, pillar=__pillar__)
241+
service_instance = connect.get_service_instance(
242+
opts=__opts__, pillar=__pillar__, name=credential_name
243+
)
237244

238245
if vm_name:
239246
vms.append(
@@ -276,7 +283,7 @@ def info(vm_name=None, service_instance=None):
276283
return info
277284

278285

279-
def power_state(vm_name, state, datacenter_name=None, service_instance=None):
286+
def power_state(vm_name, state, datacenter_name=None, service_instance=None, credential_name=None):
280287
"""
281288
Manages the power state of a virtual machine.
282289
@@ -294,7 +301,9 @@ def power_state(vm_name, state, datacenter_name=None, service_instance=None):
294301
"""
295302
log.trace(f"Managing power state of virtual machine {vm_name} to {state}")
296303
if service_instance is None:
297-
service_instance = connect.get_service_instance(opts=__opts__, pillar=__pillar__)
304+
service_instance = connect.get_service_instance(
305+
opts=__opts__, pillar=__pillar__, name=credential_name
306+
)
298307

299308
if datacenter_name:
300309
dc_ref = utils_common.get_mor_by_property(service_instance, vim.Datacenter, datacenter_name)
@@ -337,6 +346,7 @@ def boot_manager(
337346
retry_delay=0,
338347
efi_secure_boot_enabled=False,
339348
service_instance=None,
349+
credential_name=None,
340350
):
341351
"""
342352
Manage boot option for a virtual machine
@@ -363,7 +373,9 @@ def boot_manager(
363373
(optional) The Service Instance from which to obtain managed object references.
364374
"""
365375
if service_instance is None:
366-
service_instance = connect.get_service_instance(opts=__opts__, pillar=__pillar__)
376+
service_instance = connect.get_service_instance(
377+
opts=__opts__, pillar=__pillar__, name=credential_name
378+
)
367379

368380
vm = utils_common.get_mor_by_property(service_instance, vim.VirtualMachine, vm_name)
369381

@@ -394,6 +406,7 @@ def create_snapshot(
394406
quiesce=False,
395407
datacenter_name=None,
396408
service_instance=None,
409+
credential_name=None,
397410
):
398411
"""
399412
Create snapshot of given vm.
@@ -421,7 +434,9 @@ def create_snapshot(
421434
"""
422435

423436
if service_instance is None:
424-
service_instance = connect.get_service_instance(opts=__opts__, pillar=__pillar__)
437+
service_instance = connect.get_service_instance(
438+
opts=__opts__, pillar=__pillar__, name=credential_name
439+
)
425440

426441
if datacenter_name:
427442
dc_ref = utils_common.get_mor_by_property(service_instance, vim.Datacenter, datacenter_name)
@@ -446,6 +461,7 @@ def destroy_snapshot(
446461
remove_children=False,
447462
datacenter_name=None,
448463
service_instance=None,
464+
credential_name=None,
449465
):
450466
"""
451467
Destroy snapshot of given vm.
@@ -469,7 +485,9 @@ def destroy_snapshot(
469485
(optional) The Service Instance from which to obtain managed object references.
470486
"""
471487
if service_instance is None:
472-
service_instance = connect.get_service_instance(opts=__opts__, pillar=__pillar__)
488+
service_instance = connect.get_service_instance(
489+
opts=__opts__, pillar=__pillar__, name=credential_name
490+
)
473491

474492
if datacenter_name:
475493
dc_ref = utils_common.get_mor_by_property(service_instance, vim.Datacenter, datacenter_name)
@@ -484,7 +502,7 @@ def destroy_snapshot(
484502
return {"snapshot": "destroyed"}
485503

486504

487-
def snapshot(vm_name, datacenter_name=None, service_instance=None):
505+
def snapshot(vm_name, datacenter_name=None, service_instance=None, credential_name=None):
488506
"""
489507
Return info about a virtual machine snapshots
490508
@@ -495,7 +513,9 @@ def snapshot(vm_name, datacenter_name=None, service_instance=None):
495513
(optional) The Service Instance from which to obtain managed object references.
496514
"""
497515
if service_instance is None:
498-
service_instance = connect.get_service_instance(opts=__opts__, pillar=__pillar__)
516+
service_instance = connect.get_service_instance(
517+
opts=__opts__, pillar=__pillar__, name=credential_name
518+
)
499519

500520
if datacenter_name:
501521
dc_ref = utils_common.get_mor_by_property(service_instance, vim.Datacenter, datacenter_name)
@@ -510,7 +530,7 @@ def snapshot(vm_name, datacenter_name=None, service_instance=None):
510530
return {"snapshots": snapshots}
511531

512532

513-
def relocate(vm_name, new_host_name, datastore_name, service_instance=None):
533+
def relocate(vm_name, new_host_name, datastore_name, service_instance=None, credential_name=None):
514534
"""
515535
Relocates a virtual machine to the location specified.
516536
@@ -527,7 +547,9 @@ def relocate(vm_name, new_host_name, datastore_name, service_instance=None):
527547
(optional) The Service Instance from which to obtain managed object references.
528548
"""
529549
if service_instance is None:
530-
service_instance = connect.get_service_instance(opts=__opts__, pillar=__pillar__)
550+
service_instance = connect.get_service_instance(
551+
opts=__opts__, pillar=__pillar__, name=credential_name
552+
)
531553
vm_ref = utils_common.get_mor_by_property(service_instance, vim.VirtualMachine, vm_name)
532554
resources = utils_common.deployment_resources(new_host_name, service_instance)
533555
assert isinstance(datastore_name, str)

src/saltext/vmware/utils/vm.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,10 @@ def unregister_vm(vm_ref):
317317

318318

319319
def list_vms(
320-
service_instance,
321-
datacenter_name=None,
322-
cluster_name=None,
323-
host_name=None,
320+
service_instance,
321+
datacenter_name=None,
322+
cluster_name=None,
323+
host_name=None,
324324
):
325325
"""
326326
Returns a list of VMs associated with a given service instance.
@@ -356,23 +356,19 @@ def list_vms(
356356
properties.append("parent")
357357

358358
if host_name:
359-
host = utils_common.get_mor_by_property(
360-
service_instance,
361-
vim.HostSystem,
362-
host_name
363-
)
359+
host = utils_common.get_mor_by_property(service_instance, vim.HostSystem, host_name)
364360
properties.append("runtime.host")
365361
log.trace("Retrieved host: %s", host)
366362
else:
367363
host = None
368364

369365
# Search for the objects
370366
vms = utils_common.get_mors_with_properties(
371-
service_instance,
372-
vim.VirtualMachine,
373-
container_ref=start_point,
374-
property_list=properties,
375-
)
367+
service_instance,
368+
vim.VirtualMachine,
369+
container_ref=start_point,
370+
property_list=properties,
371+
)
376372

377373
items = []
378374
for vm in vms:

0 commit comments

Comments
 (0)