vmware-archive / vcloud-rest

Unofficial ruby bindings for VMware vCloud Director®
Apache License 2.0
29 stars 37 forks source link

undefined method `attribute' for nil:NilClass with nokogiri 1.6.6.2 #44

Closed monkey1016 closed 9 years ago

monkey1016 commented 9 years ago

Hi When attempting the following command: knife vc vdc show <VDC Name> -VV I receive the following stack trace:

Description:
C:/opscode/chefdk/embedded/lib/ruby/gems/2.0.0/gems/nokogiri-1.6.6.2-x86-mingw32/lib/nokogiri/xml/node_set.rb:164:in `attr': undefined method `attribute' for nil:NilClass (NoMethodError)
        from C:/opscode/chefdk/embedded/lib/ruby/gems/2.0.0/gems/vcloud-rest-1.3.0/lib/vcloud-rest/vcloud/vapp.rb:38:in `block in get_vapp'
        from C:/opscode/chefdk/embedded/lib/ruby/gems/2.0.0/gems/vcloud-rest-1.3.0/lib/vcloud-rest/vcloud/vapp.rb:36:in `collect'
        from C:/opscode/chefdk/embedded/lib/ruby/gems/2.0.0/gems/vcloud-rest-1.3.0/lib/vcloud-rest/vcloud/vapp.rb:36:in `get_vapp'
        from C:/Users/<USER>/.chefdk/gem/ruby/2.0.0/gems/knife-vcloud-1.3.0/lib/chef/knife/vdc/vc_vdc_show.rb:48:in `block in run'
        from C:/Users/<USER>/.chefdk/gem/ruby/2.0.0/gems/knife-vcloud-1.3.0/lib/chef/knife/vdc/vc_vdc_show.rb:47:in `each'
        from C:/Users/<USER>/.chefdk/gem/ruby/2.0.0/gems/knife-vcloud-1.3.0/lib/chef/knife/vdc/vc_vdc_show.rb:47:in `run'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/knife.rb:417:in `block in run_with_pretty_exceptions'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/local_mode.rb:38:in `with_server_connectivity'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/knife.rb:416:in `run_with_pretty_exceptions'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/knife.rb:213:in `run'
        from C:/opscode/chefdk/embedded/apps/chef/lib/chef/application/knife.rb:139:in `run'
        from C:/opscode/chefdk/embedded/apps/chef/bin/knife:25:in `<top (required)>'
        from C:/opscode/chefdk/bin/knife:52:in `load'
        from C:/opscode/chefdk/bin/knife:52:in `<main>'

I believe the issue is with the use of .css() instead of .at_css(). This stackoverflow link is what pointed me in the right direction. I'm not familiar enough with nokogiri to determine whether it changed between versions. If this sounds right, let me know and I can make changes and submit a PR. Or feel free to point me in the right direction :)

astratto commented 9 years ago

@monkey1016 kind of... At that line we're retrieving the Network ID from the link 'repair' (that should always be present). .css() returns a set, that in your case is clearly not empty, but nil...

If you can debug it, I'd like to know the content of network.to_xml. (just add a puts network.to_xml in C:/opscode/chefdk/embedded/lib/ruby/gems/2.0.0/gems/vcloud-rest-1.3.0/lib/vcloud-rest/vcloud/vapp.rb line 37).

monkey1016 commented 9 years ago

Here's the output (sanitized some stuff with XXX):

$ knife vc vapp show XXXXXXXXXXXXXXXXXXXXXX
Ignoring chef-12.0.0.rc.0-x86-mingw32 because its extensions are not built.  Try: gem pristine chef-12.0.0.rc.0-x86-mingw32
Ignoring chef-12.0.0.rc.0-x86-mingw32 because its extensions are not built.  Try: gem pristine chef-12.0.0.rc.0-x86-mingw32
Note: --vdc not specified, assuming VAPP is an ID
<NetworkConfig networkName="XXXXXXXXXXXX">
            <Link rel="repair" href="https://XXXXXXXXX/api/admin/network/XXXXXXXXXXXXXXXXX/action/reset"/>
            <Description/>
            <Configuration>
                <IpScope>
                    <IsInherited>true</IsInherited>
                    <Gateway>XXXXXXXXXX</Gateway>
                    <Netmask>XXXXXXXXXXX</Netmask>
                    <Dns1>XXXXXXXXXX</Dns1>
                    <Dns2>XXXXXXXXXX</Dns2>
                    <DnsSuffix>XXXXXXXXXX</DnsSuffix>
                    <IpRanges>
                        <IpRange>
                            <StartAddress>XXXXXXXXXXX</StartAddress>
                            <EndAddress>XXXXXXXXXXX</EndAddress>
                        </IpRange>
                        <IpRange>
                            <StartAddress>XXXXXXXXXX</StartAddress>
                            <EndAddress>XXXXXXXXXXX</EndAddress>
                        </IpRange>
                    </IpRanges>
                </IpScope>
                <ParentNetwork name="XXXXXXXXXXXXXXXXX" id="XXXXXXXXXXXXXXXXXX" href="https://XXXXXXXXXXX/api/admin/network/XXXXXXXXXXXXXXXXX"/>
                <FenceMode>bridged</FenceMode>
                <RetainNetInfoAcrossDeployments>false</RetainNetInfoAcrossDeployments>
            </Configuration>
            <IsDeployed>false</IsDeployed>
        </NetworkConfig>
Name: XXXXXXXXXXXXXXXXXXXXXXXXXX
Description: XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Status: stopped
Networks
XXXXXXXXXXXXXXX
   Gateway        Netmask          Fence Mode  Parent Network     Retain Network
   XXXXXXXXXXXX  255.255.255.128  bridged     XXXXXXXXXXXXXX  false
VMs
Name                                      Status   IPs  ID                                    Scoped ID
XXXXXXXXXXXXXXXXXXXX  stopped       XXXXXXXXXXXXXXXXXXXXX  XXXXXXXXXXXXXXXX
astratto commented 9 years ago

Merged, thank you!