| Conditions | 7 | 
| Total Lines | 54 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | # Licensed to the StackStorm, Inc ('StackStorm') under one or more | 
            ||
| 69 | def get_vm_reconfig_spec(self, network_obj,  | 
            ||
| 70 | stay_connected, network_type,  | 
            ||
| 71 | wake_on_lan, nettype):  | 
            ||
| 72 | network_spec = vim.vm.device.VirtualDeviceSpec()  | 
            ||
| 73 | network_spec.operation = vim.vm.device.VirtualDeviceSpec.Operation.add  | 
            ||
| 74 | |||
| 75 | if network_type.lower() == 'e1000':  | 
            ||
| 76 | network_spec.device = vim.vm.device.VirtualE1000()  | 
            ||
| 77 | elif network_type.lower() == 'flexible':  | 
            ||
| 78 | network_spec.device = vim.vm.device.VirtualPCNet32()  | 
            ||
| 79 | elif network_type.lower() == 'vmxnet':  | 
            ||
| 80 | network_spec.device = vim.vm.device.VirtualVmxnet()  | 
            ||
| 81 | elif network_type.lower() == 'enhancedvmxnet':  | 
            ||
| 82 | network_spec.device = vim.vm.device.VirtualVmxnet2()  | 
            ||
| 83 | elif network_type.lower() == 'vmxnet3':  | 
            ||
| 84 | network_spec.device = vim.vm.device.VirtualVmxnet3()  | 
            ||
| 85 | else:  | 
            ||
| 86 | network_spec.device = vim.vm.device.VirtualEthernetCard()  | 
            ||
| 87 | |||
| 88 | network_spec.device.wakeOnLanEnabled = wake_on_lan  | 
            ||
| 89 | network_spec.device.deviceInfo = vim.Description()  | 
            ||
| 90 | |||
| 91 | # Default functionality is to use the  | 
            ||
| 92 | # Distributed Port Group over a standard group  | 
            ||
| 93 | if nettype == "dist":  | 
            ||
| 94 | network_spec.device.backing = \  | 
            ||
| 95 | vim.vm.device.VirtualEthernetCard\  | 
            ||
| 96 | .DistributedVirtualPortBackingInfo()  | 
            ||
| 97 | network_spec.device.backing.port = vim.dvs.PortConnection()  | 
            ||
| 98 | |||
| 99 | dvs_port_connection = vim.dvs.PortConnection()  | 
            ||
| 100 | dvs_port_connection.portgroupKey = network_obj.key  | 
            ||
| 101 | dvs_port_connection.switchUuid = \  | 
            ||
| 102 | network_obj.config.distributedVirtualSwitch.uuid  | 
            ||
| 103 | |||
| 104 | network_spec.device.backing = \  | 
            ||
| 105 | vim.vm.device.VirtualEthernetCard\  | 
            ||
| 106 | .DistributedVirtualPortBackingInfo()  | 
            ||
| 107 | network_spec.device.backing.port = dvs_port_connection  | 
            ||
| 108 | else:  | 
            ||
| 109 | network_spec.device.backing = \  | 
            ||
| 110 | vim.vm.device.VirtualEthernetCard.NetworkBackingInfo()  | 
            ||
| 111 | network_spec.device.backing.network = network_obj  | 
            ||
| 112 | network_spec.device.backing.deviceName = network_obj.name  | 
            ||
| 113 | |||
| 114 | network_spec.device.connectable = \  | 
            ||
| 115 | vim.vm.device.VirtualDevice.ConnectInfo()  | 
            ||
| 116 | network_spec.device.connectable.startConnected = stay_connected  | 
            ||
| 117 | network_spec.device.connectable.allowGuestControl = True  | 
            ||
| 118 | |||
| 119 | # creating reconfig spec  | 
            ||
| 120 | vm_reconfig_spec = vim.vm.ConfigSpec()  | 
            ||
| 121 | vm_reconfig_spec.deviceChange = [network_spec]  | 
            ||
| 122 | return vm_reconfig_spec  | 
            ||
| 123 |