Fog::Compute::OpenNebula::Real
F

Very high overall complexity: 668

# t.template_str
# CPU="0.2"
# VCPU="2"
# MEMORY="2048"
# SCHED_REQUIREMENTS="NFS=\"true\""
Found in Fog::Compute::OpenNebula::Real - About 5 days to fix

When classes take on too many responsibilities, they grow. A large number of instance variables or methods can make a class hard to understand. Large classes tend to have lower cohesion and higher churn.

Often large classes have methods that do not operate on all of the class state. Identifying the groups of data that are used together can point to seams to split out additional collaborator classes or value objects.

Another trick is to look for repeated prefixes or suffixes in method and variable names, or repeated parameter names, and use them to guide extractions.

Refactorings

Further Reading

Very complex method in #template_pool

        def template_pool(filter = { })

          templates = ::OpenNebula::TemplatePool.new(client)
          if filter[:id].nil?
            templates.info!(-2,-1,-1)
Found in Fog::Compute::OpenNebula::Real - About 2 days to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Very complex method in #list_vms

# DISK=[
#     DEV_PREFIX="vd",
#     DRIVER="qcow2",
#     IMAGE="base",
#     IMAGE_ID="355",
Found in Fog::Compute::OpenNebula::Real - About 2 days to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Very complex method in #vm_allocate

# SCHED_REQUIREMENTS="NFS=\"true\""
# SCHED_DS_REQUIREMENTS="NAME=\"local\""
# DISK=[
#     DEV_PREFIX="vd",
#     DRIVER="qcow2",
Found in Fog::Compute::OpenNebula::Real - About 2 days to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Very complex method in #list_networks

#     DEV_PREFIX="vd",
#     DRIVER="qcow2",
#     IMAGE="base",
#     IMAGE_ID="355",
#     IMAGE_UNAME="oneadmin",
Found in Fog::Compute::OpenNebula::Real - About 1 day to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Complex method in #network_to_attributes

        def template_pool(filter = { })

          templates = ::OpenNebula::TemplatePool.new(client)
          if filter[:id].nil?
            templates.info!(-2,-1,-1)
Found in Fog::Compute::OpenNebula::Real - About 2 hrs to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Complex method in #list_groups

# SCHED_REQUIREMENTS="NFS=\"true\""
# SCHED_DS_REQUIREMENTS="NAME=\"local\""
# DISK=[
#     DEV_PREFIX="vd",
#     DRIVER="qcow2",
Found in Fog::Compute::OpenNebula::Real - About 2 hrs to fix

Long or complex methods can make code harder to understand. In most circumstances, methods are best as a small chunk of code (the "how") with a clear, understandable name (the "what"). Long methods can also lead to duplication, as it's harder to reuse logic that is tightly coupled to surrounding code.

Refactorings

Read More

Identical code found in 1 other location

# t.template_str
# CPU="0.2"
# VCPU="2"
# MEMORY="2048"
# SCHED_REQUIREMENTS="NFS=\"true\""
Found in Fog::Compute::OpenNebula::Real and 1 other location - About 2 days to fix
lib/fog/opennebula/requests/compute/list_groups.rb on lines 49..61

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Refactorings

Further Reading

Identical code found in 1 other location

# t.template_str
# CPU="0.2"
# VCPU="2"
# MEMORY="2048"
# SCHED_REQUIREMENTS="NFS=\"true\""
Found in Fog::Compute::OpenNebula::Real and 1 other location - About 2 days to fix
lib/fog/opennebula/requests/compute/list_groups.rb on lines 23..35

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Refactorings

Further Reading

Similar code found in 1 other location

# t.template_str
# CPU="0.2"
# VCPU="2"
# MEMORY="2048"
# SCHED_REQUIREMENTS="NFS=\"true\""
Found in Fog::Compute::OpenNebula::Real and 1 other location - About 5 hrs to fix
lib/fog/opennebula/requests/compute/template_pool.rb on lines 36..41

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Refactorings

Further Reading

Similar code found in 1 other location

# t.template_str
# CPU="0.2"
# VCPU="2"
# MEMORY="2048"
# SCHED_REQUIREMENTS="NFS=\"true\""
Found in Fog::Compute::OpenNebula::Real and 1 other location - About 5 hrs to fix
lib/fog/opennebula/requests/compute/list_networks.rb on lines 11..16

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Refactorings

Further Reading

Similar code found in 5 other locations

# t.template_str
# CPU="0.2"
# VCPU="2"
# MEMORY="2048"
# SCHED_REQUIREMENTS="NFS=\"true\""
Found in Fog::Compute::OpenNebula::Real and 5 other locations - About 4 hrs to fix
lib/fog/opennebula/requests/compute/list_networks.rb on lines 19..21
lib/fog/opennebula/requests/compute/list_networks.rb on lines 25..27
lib/fog/opennebula/requests/compute/template_pool.rb on lines 46..48
lib/fog/opennebula/requests/compute/template_pool.rb on lines 49..51
lib/fog/opennebula/requests/compute/template_pool.rb on lines 52..54

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Refactorings

Further Reading

Similar code found in 5 other locations

# t.template_str
# CPU="0.2"
# VCPU="2"
# MEMORY="2048"
# SCHED_REQUIREMENTS="NFS=\"true\""
Found in Fog::Compute::OpenNebula::Real and 5 other locations - About 4 hrs to fix
lib/fog/opennebula/requests/compute/list_networks.rb on lines 22..24
lib/fog/opennebula/requests/compute/list_networks.rb on lines 25..27
lib/fog/opennebula/requests/compute/template_pool.rb on lines 46..48
lib/fog/opennebula/requests/compute/template_pool.rb on lines 49..51
lib/fog/opennebula/requests/compute/template_pool.rb on lines 52..54

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Refactorings

Further Reading

Similar code found in 5 other locations

# t.template_str
# CPU="0.2"
# VCPU="2"
# MEMORY="2048"
# SCHED_REQUIREMENTS="NFS=\"true\""
Found in Fog::Compute::OpenNebula::Real and 5 other locations - About 4 hrs to fix
lib/fog/opennebula/requests/compute/list_networks.rb on lines 19..21
lib/fog/opennebula/requests/compute/list_networks.rb on lines 22..24
lib/fog/opennebula/requests/compute/list_networks.rb on lines 25..27
lib/fog/opennebula/requests/compute/template_pool.rb on lines 49..51
lib/fog/opennebula/requests/compute/template_pool.rb on lines 52..54

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Refactorings

Further Reading

Similar code found in 5 other locations

# t.template_str
# CPU="0.2"
# VCPU="2"
# MEMORY="2048"
# SCHED_REQUIREMENTS="NFS=\"true\""
Found in Fog::Compute::OpenNebula::Real and 5 other locations - About 4 hrs to fix
lib/fog/opennebula/requests/compute/list_networks.rb on lines 19..21
lib/fog/opennebula/requests/compute/list_networks.rb on lines 22..24
lib/fog/opennebula/requests/compute/template_pool.rb on lines 46..48
lib/fog/opennebula/requests/compute/template_pool.rb on lines 49..51
lib/fog/opennebula/requests/compute/template_pool.rb on lines 52..54

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Refactorings

Further Reading

Similar code found in 5 other locations

# t.template_str
# CPU="0.2"
# VCPU="2"
# MEMORY="2048"
# SCHED_REQUIREMENTS="NFS=\"true\""
Found in Fog::Compute::OpenNebula::Real and 5 other locations - About 4 hrs to fix
lib/fog/opennebula/requests/compute/list_networks.rb on lines 19..21
lib/fog/opennebula/requests/compute/list_networks.rb on lines 22..24
lib/fog/opennebula/requests/compute/list_networks.rb on lines 25..27
lib/fog/opennebula/requests/compute/template_pool.rb on lines 46..48
lib/fog/opennebula/requests/compute/template_pool.rb on lines 49..51

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Refactorings

Further Reading

Similar code found in 5 other locations

# t.template_str
# CPU="0.2"
# VCPU="2"
# MEMORY="2048"
# SCHED_REQUIREMENTS="NFS=\"true\""
Found in Fog::Compute::OpenNebula::Real and 5 other locations - About 4 hrs to fix
lib/fog/opennebula/requests/compute/list_networks.rb on lines 19..21
lib/fog/opennebula/requests/compute/list_networks.rb on lines 22..24
lib/fog/opennebula/requests/compute/list_networks.rb on lines 25..27
lib/fog/opennebula/requests/compute/template_pool.rb on lines 46..48
lib/fog/opennebula/requests/compute/template_pool.rb on lines 52..54

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Refactorings

Further Reading

Similar code found in 1 other location

# t.template_str
# CPU="0.2"
# VCPU="2"
# MEMORY="2048"
# SCHED_REQUIREMENTS="NFS=\"true\""
Found in Fog::Compute::OpenNebula::Real and 1 other location - About 3 hrs to fix
lib/fog/opennebula/requests/compute/list_vms.rb on lines 38..38

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Refactorings

Further Reading

Similar code found in 1 other location

# t.template_str
# CPU="0.2"
# VCPU="2"
# MEMORY="2048"
# SCHED_REQUIREMENTS="NFS=\"true\""
Found in Fog::Compute::OpenNebula::Real and 1 other location - About 3 hrs to fix
lib/fog/opennebula/requests/compute/list_vms.rb on lines 39..39

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Refactorings

Further Reading

Similar code found in 1 other location

# t.template_str
# CPU="0.2"
# VCPU="2"
# MEMORY="2048"
# SCHED_REQUIREMENTS="NFS=\"true\""
Found in Fog::Compute::OpenNebula::Real and 1 other location - About 3 hrs to fix
lib/fog/opennebula/requests/compute/vm_stop.rb on lines 2..9

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Refactorings

Further Reading

Similar code found in 1 other location

# t.template_str
# CPU="0.2"
# VCPU="2"
# MEMORY="2048"
# SCHED_REQUIREMENTS="NFS=\"true\""
Found in Fog::Compute::OpenNebula::Real and 1 other location - About 3 hrs to fix
lib/fog/opennebula/requests/compute/vm_shutdown.rb on lines 2..11

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Refactorings

Further Reading

Similar code found in 1 other location

# t.template_str
# CPU="0.2"
# VCPU="2"
# MEMORY="2048"
# SCHED_REQUIREMENTS="NFS=\"true\""
Found in Fog::Compute::OpenNebula::Real and 1 other location - About 3 hrs to fix
lib/fog/opennebula/requests/compute/vm_suspend.rb on lines 20..23

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Refactorings

Further Reading

Similar code found in 1 other location

# t.template_str
# CPU="0.2"
# VCPU="2"
# MEMORY="2048"
# SCHED_REQUIREMENTS="NFS=\"true\""
Found in Fog::Compute::OpenNebula::Real and 1 other location - About 2 hrs to fix
lib/fog/opennebula/requests/compute/list_vms.rb on lines 31..31

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Refactorings

Further Reading

Similar code found in 1 other location

# t.template_str
# CPU="0.2"
# VCPU="2"
# MEMORY="2048"
# SCHED_REQUIREMENTS="NFS=\"true\""
Found in Fog::Compute::OpenNebula::Real and 1 other location - About 2 hrs to fix
lib/fog/opennebula/requests/compute/list_vms.rb on lines 32..32

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Refactorings

Further Reading

Similar code found in 1 other location

# t.template_str
# CPU="0.2"
# VCPU="2"
# MEMORY="2048"
# SCHED_REQUIREMENTS="NFS=\"true\""
Found in Fog::Compute::OpenNebula::Real and 1 other location - About 2 hrs to fix
lib/fog/opennebula/requests/compute/vm_allocate.rb on lines 54..54

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Refactorings

Further Reading

Similar code found in 1 other location

# t.template_str
# CPU="0.2"
# VCPU="2"
# MEMORY="2048"
# SCHED_REQUIREMENTS="NFS=\"true\""
Found in Fog::Compute::OpenNebula::Real and 1 other location - About 2 hrs to fix
lib/fog/opennebula/requests/compute/vm_allocate.rb on lines 55..55

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Refactorings

Further Reading

There are no issues that match your filters.

# t.template_str
# CPU="0.2"
# VCPU="2"
# MEMORY="2048"
# SCHED_REQUIREMENTS="NFS=\"true\""
# SCHED_DS_REQUIREMENTS="NAME=\"local\""
# DISK=[
#     DEV_PREFIX="vd",
#     DRIVER="qcow2",
#     IMAGE="base",
#     IMAGE_ID="355",
#     IMAGE_UNAME="oneadmin",
#     TARGET="vda" ]
# GRAPHICS=[
#     LISTEN="0.0.0.0",
#      TYPE="VNC" ]
# NIC=[
#     MODEL="virtio",
#     NETWORK="vlan2-2",
#     NETWORK_UNAME="oneadmin" ]
# OS=[
#     ARCH="x86_64",
#     BOOT="network,hd" ]
# RAW=[
#   DATA="<cpu match='exact'><model fallback='allow'>core2duo</model></cpu>",
#   TYPE="kvm" ]


module Fog
  module Compute
    class OpenNebula
      class Real
        def template_pool(filter = { })

          templates = ::OpenNebula::TemplatePool.new(client)
          if filter[:id].nil?
            templates.info!(-2,-1,-1)
          elsif filter[:id]
            filter[:id] = filter[:id].to_i if filter[:id].is_a?(String)
            templates.info!(-2, filter[:id], filter[:id])
          end # if filter[:id].nil?

          templates = templates.map do |t|
            # filtering by name
            # done here, because OpenNebula:TemplatePool does not support something like .delete_if
            if filter[:name] && filter[:name].is_a?(String) && !filter[:name].empty?
              next if t.to_hash["VMTEMPLATE"]["NAME"] != filter[:name]
            end
            if filter[:uname] && filter[:uname].is_a?(String) && !filter[:uname].empty?
              next if t.to_hash["VMTEMPLATE"]["UNAME"] != filter[:uname]
            end
            if filter[:uid] && filter[:uid].is_a?(String) && !filter[:uid].empty?
              next if t.to_hash["VMTEMPLATE"]["UID"] != filter[:uid]
            end

            h = Hash[
              :id => t.to_hash["VMTEMPLATE"]["ID"],
              :name => t.to_hash["VMTEMPLATE"]["NAME"],
              :content => t.template_str,
              :USER_VARIABLES => "" # Default if not set in template
            ]
            h.merge! t.to_hash["VMTEMPLATE"]["TEMPLATE"]

            # h["NIC"] has to be an array of nic objects
            nics = h["NIC"] unless h["NIC"].nil?
            h["NIC"] = [] # reset nics to a array
            if nics.is_a? Array
              nics.each do |n|
                if n["NETWORK_ID"]
                  vnet = networks.get(n["NETWORK_ID"].to_s)
                elsif n["NETWORK"]
                  vnet = networks.get_by_name(n["NETWORK"].to_s)
                else
                  next
                end
                h["NIC"] << interfaces.new({ :vnet => vnet, :model => n["MODEL"] || "virtio" })
              end
            elsif nics.is_a? Hash
              nics["model"] = "virtio" if nics["model"].nil?
              #nics["uuid"] = "0" if nics["uuid"].nil? # is it better is to remove this NIC?
              n = networks.get_by_filter({
                :id => nics["NETWORK_ID"],
                :network => nics["NETWORK"],
                :network_uname => nics["NETWORK_UNAME"],
                :network_uid => nics["NETWORK_UID"]
              })
              n.each do |i|
                h["NIC"] << interfaces.new({ :vnet => i })
              end
            else
              # should i break?
            end

            # every key should be lowercase
            ret_hash = {}
            h.each_pair do |k,v|
              ret_hash.merge!({k.downcase => v})
            end
            ret_hash
          end

          templates.delete nil
          raise Fog::Compute::OpenNebula::NotFound, "Flavor/Template not found" if templates.empty?
          templates
        end #def template_pool
      end #class Real

      class Mock
        def template_pool(filter = { })
          nic1 = Mock_nic.new
          nic1.vnet = networks.first

          self.data['template_pool']
          self.data['template_pool'].each do |tmpl|
            tmpl['nic'][0] = nic1
          end
          self.data['template_pool']
        end

        class Mock_nic
          attr_accessor :vnet

          def id
            2
          end
          def name
            "fogtest"
          end
          def model
            "virtio-net"
          end
        end
      end #class Mock
    end #class OpenNebula
  end #module Compute
end #module Fog

Size

Lines of code
92