File cloud.rb
has 797 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'json'
require 'membrane'
require 'ruby_vim_sdk'
require 'cloud'
require 'cloud/vsphere/retry_block'
Class Cloud
has 40 methods (exceeds 20 allowed). Consider refactoring. Open
class Cloud < Bosh::Cloud
include VimSdk
include RetryBlock
class TimeoutException < StandardError;
Method attach_disk
has 72 lines of code (exceeds 25 allowed). Consider refactoring. Open
def attach_disk(vm_cid, disk_cid)
with_thread_name("attach_disk(#{vm_cid}, #{disk_cid})") do
@logger.info("Attaching disk: #{disk_cid} on vm: #{vm_cid}")
disk = Models::Disk.first(uuid: disk_cid)
raise "Disk not found: #{disk_cid}" if disk.nil?
Method configure_networks
has 55 lines of code (exceeds 25 allowed). Consider refactoring. Open
def configure_networks(vm_cid, networks)
with_thread_name("configure_networks(#{vm_cid}, ...)") do
vm = get_vm_by_cid(vm_cid)
@logger.debug('Waiting for the VM to shutdown')
Method delete_vm
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
def delete_vm(vm_cid)
with_thread_name("delete_vm(#{vm_cid})") do
@logger.info("Deleting vm: #{vm_cid}")
vm = get_vm_by_cid(vm_cid)
Method attach_disk
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def attach_disk(vm_cid, disk_cid)
with_thread_name("attach_disk(#{vm_cid}, #{disk_cid})") do
@logger.info("Attaching disk: #{disk_cid} on vm: #{vm_cid}")
disk = Models::Disk.first(uuid: disk_cid)
raise "Disk not found: #{disk_cid}" if disk.nil?
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method replicate_stemcell
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
def replicate_stemcell(cluster, datastore, stemcell)
stemcell_vm = client.find_by_inventory_path([cluster.datacenter.name, 'vm',
cluster.datacenter.template_folder.name, stemcell])
raise "Could not find stemcell: #{stemcell}" if stemcell_vm.nil?
stemcell_datastore = client.get_property(stemcell_vm, Vim::VirtualMachine, 'datastore', ensure_all: true)
Method delete_vm
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def delete_vm(vm_cid)
with_thread_name("delete_vm(#{vm_cid})") do
@logger.info("Deleting vm: #{vm_cid}")
vm = get_vm_by_cid(vm_cid)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method replicate_stemcell
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def replicate_stemcell(cluster, datastore, stemcell)
stemcell_vm = client.find_by_inventory_path([cluster.datacenter.name, 'vm',
cluster.datacenter.template_folder.name, stemcell])
raise "Could not find stemcell: #{stemcell}" if stemcell_vm.nil?
stemcell_datastore = client.get_property(stemcell_vm, Vim::VirtualMachine, 'datastore', ensure_all: true)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method set_vm_metadata
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def set_vm_metadata(vm_cid, metadata)
with_thread_name("set_vm_metadata(#{vm_cid}, ...)") do
begin
fields_manager = client.service_content.custom_fields_manager
custom_fields = fields_manager.field
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method create_stemcell
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
def create_stemcell(image, _)
with_thread_name("create_stemcell(#{image}, _)") do
result = nil
Dir.mktmpdir do |temp_dir|
@logger.info("Extracting stemcell to: #{temp_dir}")
Method detach_disk
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
def detach_disk(vm_cid, disk_cid)
with_thread_name("detach_disk(#{vm_cid}, #{disk_cid})") do
@logger.info("Detaching disk: #{disk_cid} from vm: #{vm_cid}")
disk = Models::Disk.first(uuid: disk_cid)
raise "Disk not found: #{disk_cid}" if disk.nil?
Method detach_disk
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def detach_disk(vm_cid, disk_cid)
with_thread_name("detach_disk(#{vm_cid}, #{disk_cid})") do
@logger.info("Detaching disk: #{disk_cid} from vm: #{vm_cid}")
disk = Models::Disk.first(uuid: disk_cid)
raise "Disk not found: #{disk_cid}" if disk.nil?
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method upload_ovf
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
def upload_ovf(ovf, lease, file_items)
info = client.get_property(lease, Vim::HttpNfcLease, 'info', ensure_all: true)
lease_updater = LeaseUpdater.new(client, lease)
info.device_url.each do |device_url|
Method delete_disk
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def delete_disk(disk_cid)
with_thread_name("delete_disk(#{disk_cid})") do
@logger.info("Deleting disk: #{disk_cid}")
disk = Models::Disk.first(uuid: disk_cid)
if disk
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method configure_networks
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def configure_networks(vm_cid, networks)
with_thread_name("configure_networks(#{vm_cid}, ...)") do
vm = get_vm_by_cid(vm_cid)
@logger.debug('Waiting for the VM to shutdown')
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method create_nic_config_spec
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def create_nic_config_spec(v_network_name, network, controller_key, dvs_index)
raise "Can't find network: #{v_network_name}" if network.nil?
if network.class == Vim::Dvs::DistributedVirtualPortgroup
portgroup_properties = client.get_properties(network,
Vim::Dvs::DistributedVirtualPortgroup,
Method set_vm_metadata
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def set_vm_metadata(vm_cid, metadata)
with_thread_name("set_vm_metadata(#{vm_cid}, ...)") do
begin
fields_manager = client.service_content.custom_fields_manager
custom_fields = fields_manager.field
Method get_primary_datastore
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def get_primary_datastore(devices)
ephemeral_disks = devices.select { |device| device.kind_of?(Vim::Vm::Device::VirtualDisk) &&
device.backing.disk_mode != Vim::Vm::Device::VirtualDiskOption::DiskMode::INDEPENDENT_PERSISTENT }
datastore = nil
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method create_vm
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def create_vm(agent_id, stemcell, cloud_properties, networks, disk_locality = nil, environment = nil)
Method fix_device_unit_numbers
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def fix_device_unit_numbers(devices, device_changes)
controllers_available_unit_numbers = Hash.new { |h,k| h[k] = (0..15).to_a }
devices.each do |device|
if device.controller_key
available_unit_numbers = controllers_available_unit_numbers[device.controller_key]
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method create_disk_config_spec
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def create_disk_config_spec(datastore, file_name, controller_key, space, options = {})
Method generate_agent_env
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def generate_agent_env(name, vm, agent_id, networking_env, disk_env)
Method clone_vm
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def clone_vm(vm, name, folder, resource_pool, options={})
Method get_vm_location
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def get_vm_location(vm, options = {})
datacenter_name = options[:datacenter]
datastore_name = options[:datastore]
vm_name = options[:vm]
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method generate_network_env
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def generate_network_env(devices, networks, dvs_index)
nics = {}
devices.each do |device|
if device.kind_of?(Vim::Vm::Device::VirtualEthernetCard)
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method reboot_vm
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def reboot_vm(vm_cid)
with_thread_name("reboot_vm(#{vm_cid})") do
vm = get_vm_by_cid(vm_cid)
datacenter = client.find_parent(vm, Vim::Datacenter)
power_state = client.get_property(vm, Vim::VirtualMachine, 'runtime.powerState')
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method create_stemcell
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def create_stemcell(image, _)
with_thread_name("create_stemcell(#{image}, _)") do
result = nil
Dir.mktmpdir do |temp_dir|
@logger.info("Extracting stemcell to: #{temp_dir}")
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method clone_vm
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def clone_vm(vm, name, folder, resource_pool, options={})
relocation_spec = Vim::Vm::RelocateSpec.new
relocation_spec.datastore = options[:datastore] if options[:datastore]
if options[:linked]
relocation_spec.disk_move_type = Vim::Vm::RelocateSpec::DiskMoveOptions::CREATE_NEW_CHILD_DISK_BACKING
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"