Module: Fog::Ovirt::Compute::V4::Shared

Included in:
Mock, Mock, Real, Real
Defined in:
lib/fog/ovirt/compute/v4.rb,
lib/fog/ovirt/requests/compute/v4/update_volume.rb,
lib/fog/ovirt/requests/compute/v4/update_interface.rb

Instance Method Summary collapse

Instance Method Details

#check_arguments(id, options) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
9
# File 'lib/fog/ovirt/requests/compute/v4/update_volume.rb', line 6

def check_arguments(id, options)
  raise ArgumentError, "instance id is a required parameter" unless id
  raise ArgumentError, "disk id is a required parameter for update-volume" unless options.key? :id
end

#convert_string_to_bool(value) ⇒ Object

rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/fog/ovirt/compute/v4.rb', line 121

def convert_string_to_bool(value)
  case value
  when "true"
    true
  when "false"
    false
  when Array
    value.map { |elem| convert_string_to_bool(elem) }
  when Hash
    value.each do |key, elem|
      value[key] = convert_string_to_bool(elem)
    end
    value
  else
    value
  end
end

#get_attr_value(value, opts) ⇒ Object

rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/fog/ovirt/compute/v4.rb', line 82

def get_attr_value(value, opts)
  case value
  when OvirtSDK4::List
    value.to_a
  when Array, Hash, DateTime
    value
  when OvirtSDK4::HighAvailability
    opts[:ha] = value.enabled
    value
  when OvirtSDK4::TemplateVersion
    OpenStruct.new(:version_name => value.version_name, :version_number => value.version_number)
  when OvirtSDK4::Mac
    value.address
  when OvirtSDK4::Cpu
    opts[:cores] = value.topology.nil? ? nil : value.topology.cores
    opts[:sockets] = value.topology.nil? ? nil : value.topology.sockets
  when OvirtSDK4::Display
    subject = value.certificate.subject if value.certificate
    {
      :type => value.type,
      :address => value.address,
      :port => value.port,
      :secure_port => value.secure_port,
      :keyboard_layout => value.keyboard_layout,
      :subject => subject,
      :monitors => value.monitors
    }
  when OvirtSDK4::Console
    { :enabled => value.enabled }
  else
    if value.class.respond_to?(:module_parent) && value.class.module_parent == OvirtSDK4
      value.id if value.respond_to?(:id)
    else
      value.to_s.strip
    end
  end
end

#shared_ovirt_attrs(obj) ⇒ Object

rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity converts an OVIRT object into an hash for fog to consume.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/fog/ovirt/compute/v4.rb', line 52

def shared_ovirt_attrs(obj)
  opts = {}
  # TODO: stop using instance_variables, they will change
  obj.instance_variables.each do |v|
    key = v.to_s.delete("@").to_sym
    value = obj.instance_variable_get(v)

    if key == :network
      opts[key] = obj.vnic_profile.present? ? yield(obj) : value
      next
    end

    if key == :provisioned_size
      opts[:size] = value.to_s
      next
    end

    # ignore nil values
    next if value.nil?

    opts[key] = value.id if key != :data_center && value.respond_to?(:href) && value.href && value.respond_to?(:id)

    opts[key] ||= get_attr_value(value, opts)
  end
  opts
end