Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client.templates fails if filtered_api = true #110

Closed
aalba6675 opened this issue May 10, 2016 · 4 comments
Closed

client.templates fails if filtered_api = true #110

aalba6675 opened this issue May 10, 2016 · 4 comments

Comments

@aalba6675
Copy link
Contributor

aalba6675 commented May 10, 2016

ovirt 3.6.5, rbovirt 0.1.1

  • User with admin privileges
client = OVIRT::Client.new(
  "adminuser@domain",
  "password",
  "https://ovirt.example.com/api",
  { :datacenter_id =>'5ac1ff95-d7ac-4b42-89d5-241eef81b9a6',
    :ca_no_verify => true
  },)
client.templates ## returns lots of information about templates
  • Same user
client = OVIRT::Client.new(
  "adminuser@domain",
  "password",
  "https://ovirt.example.com/api",
  { :datacenter_id =>'5ac1ff95-d7ac-4b42-89d5-241eef81b9a6',
    :ca_no_verify => true, :filtered_api = true
  },)
irb(main):058:0> client.templates
NoMethodError: undefined method `[]' for nil:NilClass
        from /home/vagrant/.gem/ruby/gems/rbovirt-0.1.1/lib/ovirt/template.rb:40:in `parse_xml_attributes!'
        from /home/vagrant/.gem/ruby/gems/rbovirt-0.1.1/lib/ovirt/template.rb:8:in `initialize'
        from /home/vagrant/.gem/ruby/gems/rbovirt-0.1.1/lib/client/template_api.rb:7:in `new'
        from /home/vagrnat/.gem/ruby/gems/rbovirt-0.1.1/lib/client/template_api.rb:7:in `block in templates'
        from /usr/share/gems/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/node_set.rb:187:in `block in each'
        from /usr/share/gems/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/node_set.rb:186:in `upto'
        from /usr/share/gems/gems/nokogiri-1.6.7.2/lib/nokogiri/xml/node_set.rb:186:in `each'
        from /home/vagrant/.gem/ruby/gems/rbovirt-0.1.1/lib/client/template_api.rb:6:in `collect'
        from /home/vagrant/.gem/ruby/gems/rbovirt-0.1.1/lib/client/template_api.rb:6:in `templates'
        from (irb):58
        from /usr/bin/irb:11:in `<main>'
@aalba6675
Copy link
Contributor Author

aalba6675 commented May 10, 2016

The difference is due to path += search_url(opts) unless unfltered_api which triggers the error

  class Client
    def templates(opts={})
      path = "/templates"
      path += search_url(opts) unless unfiltered_api
      result = http_get(path).xpath('/templates/template')
      puts "DEBUG:  #{result.class.name}"
      http_get(path).xpath('/templates/template').collect do |t|
        OVIRT::Template::new(self, t)
      end.compact
    end

@aalba6675
Copy link
Contributor Author

aalba6675 commented May 10, 2016

Perhaps we should skip the template if xml id is "00000000-0000-0000-0000-000000000000".
because :filtered_api = true search results include this "Blank" template with no <cluster> element. template.rb fails when trying to extract <cluster> from the xml snippet:

  def parse_xml_attributes!(xml)
      ## etc etc
      @cluster = Link::new(@client, (xml/'cluster').first[:id], (xml/'cluster').first[:href])
       ## Template "00000000-0000-0000-0000-000000000000"  xml/'cluster'.first is nil

I propose either remove the Blank template from the collection or

    def parse_xml_attributes!(xml)
      @description = ((xml/'description').first.text rescue '')
      @comment = ((xml/'comment').first.text rescue '')
      @version = TemplateVersion.new((xml/'version').first)
      @status = ((xml/'status').first.text rescue 'unknown')
      @memory = (xml/'memory').first.text
      @profile = (xml/'type').first.text
      if (xml/'cluster').first
        @cluster = Link::new(@client, (xml/'cluster').first[:id], (xml/'cluster').first[:href])
      end

Tested and works with vagrant-ovirt3 1.9.1.

@lzap
Copy link
Collaborator

lzap commented May 11, 2016

Tested and works with vagrant-ovirt3 1.9.1.

Go ahead and create a PR for this.

Later,
Lukas #lzap Zapletal

@iNecas
Copy link
Contributor

iNecas commented Aug 11, 2017

Resolved by #111

@iNecas iNecas closed this as completed Aug 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants