[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]



[tomcat at sam-devel tmp]$ ./configShell.pl 192.168.2.137
ENS Version: Version: 3.1.4 Development, Build: 110905-170135
localhost # set net 1 fqdn cart.opsup.com
Configuration updated.
localhost # show net 1
###################################################
#                     Network                     #
###################################################
# Network Interface: 1
set net 1 active enabled
set net 1 dhcp disabled
set net 1 fqdn cart.opsup.com
set net 1 address 192.168.2.137
set net 1 netmask 255.255.255.0
set net 1 broadcast 192.168.2.255
set net 1 gateway 192.168.2.254
set net 1 nameserver1 192.168.2.254
set net 1 nameserver2 0.0.0.0
set net 1 nameserver3 0.0.0.0
localhost # save
Saved to flash
localhost # restart
Restarting ENS at 192.168.2.137



It looks just like the config on the device

On Thu, 2005-11-10 at 09:55 -0500, Christopher Fowler wrote:
> That work good.
> 
> I'm trying to identify a better way to parse the XML via XML::Parser;
> Normally I use the xml subs method but I intend to have everything
> readable in one perl program.  I'm also using OOP.  So I want a package
> for each noun but I do not want a package for each noun and one for xml
> parsing of data for each noun.  Here is what my code looks like
> 
> ----------------------------------------
>   # Retrieve ENS Hostname
>   my $ens_network = ENSNetwork->new($ua);
>   $ens_network->load();
> 
> 
> {
>   package ENSNetwork;
> 
>   sub new {
>     my ($proto, $ua) = @_;
>     my $class = ref($proto) || $proto;
> 
>     my $self = {
>       'server' => $ua,
>       'errstr'     => undef,
>     };
>     bless ($self,$class);
>     return $self;
> 
>   }
> 
>   sub load {
>     my ($self) = shift;
>     my $server = Frontier::Client->new( debug => 0,
&gt;       url =&gt; &quot;<a  rel="nofollow" href="http://$ens_ip/cgi-bin/xml-rpc&quot;,ua";>http://$ens_ip/cgi-bin/xml-rpc&quot;,ua</a> =&gt; $self-&gt;{'server'} );
&gt;     my $result = $server-&gt;call('get_network_config', (&quot;0&quot;));
&gt;     $result = MIME::Base64::decode_base64($result);
&gt;     print &quot;$result\n&quot;;
&gt; 
&gt;     # Need to parse the data!
&gt; 
&gt;   }
&gt; }
&gt; 
&gt; ----------------------------------------
&gt; 
&gt; Here is what XML data looks like when retrieved:
&gt; ----------------------------------------
&gt; &lt;?xml version=&quot;1.0&quot;?&gt;
&gt; &lt;config&gt;
&gt;   &lt;network id=&quot;1&quot;&gt;
&gt;     &lt;active&gt;enabled&lt;/active&gt;
&gt;     &lt;fqdn&gt;localhost.localdomain.com&lt;/fqdn&gt;
&gt;     &lt;dhcp&gt;disabled&lt;/dhcp&gt;
&gt;     &lt;address&gt;192.168.2.137&lt;/address&gt;
&gt;     &lt;broadcast&gt;192.168.2.255&lt;/broadcast&gt;
&gt;     &lt;netmask&gt;255.255.255.0&lt;/netmask&gt;
&gt;     &lt;gateway&gt;192.168.2.254&lt;/gateway&gt;
&gt;     &lt;nameserver1&gt;192.168.2.254&lt;/nameserver1&gt;
&gt;     &lt;nameserver2&gt;0.0.0.0&lt;/nameserver2&gt;
&gt;     &lt;nameserver3&gt;0.0.0.0&lt;/nameserver3&gt;
&gt;     &lt;forwarding&gt;disabled&lt;/forwarding&gt;
&gt;   &lt;/network&gt;
&gt;   &lt;network id=&quot;2&quot;&gt;
&gt;     &lt;active&gt;disabled&lt;/active&gt;
&gt;     &lt;fqdn&gt;localhost.localdomain.com&lt;/fqdn&gt;
&gt;     &lt;dhcp&gt;enabled&lt;/dhcp&gt;
&gt;     &lt;address&gt;0.0.0.0&lt;/address&gt;
&gt;     &lt;broadcast&gt;0.0.0.0&lt;/broadcast&gt;
&gt;     &lt;netmask&gt;0.0.0.0&lt;/netmask&gt;
&gt;     &lt;gateway&gt;0.0.0.0&lt;/gateway&gt;
&gt;     &lt;nameserver1&gt;0.0.0.0&lt;/nameserver1&gt;
&gt;     &lt;nameserver2&gt;0.0.0.0&lt;/nameserver2&gt;
&gt;     &lt;nameserver3&gt;0.0.0.0&lt;/nameserver3&gt;
&gt;     &lt;forwarding&gt;disabled&lt;/forwarding&gt;
&gt;   &lt;/network&gt;
&gt; &lt;/config&gt;
&gt; --------------------------------------
&gt; 
&gt; 
&gt; Can I have a package within a package:
&gt; 
&gt; {
&gt;   package ENSNetwork;
&gt; 
&gt;   { 
&gt;     package ens_network_xml_subs;
&gt;   }
&gt; }
&gt; 
&gt; That makes reading a pain.  If that is doable how would the XML::Parser
&gt; gain access to the current object's data?  Normally I declare a hash as
&gt; readable by the whole program like this:
&gt; 
&gt; 
&gt; my %device = ()
&gt; 
&gt; { 
&gt;   package xml_subs;
&gt; 
&gt;   sub device {
&gt;     my(undef, undef, %attrs) = @_;
&gt;     $device{'id'} = $attrs{'id'};
&gt;   }
&gt; 
&gt; }
&gt; 
&gt; 
&gt; 
&gt; On Thu, 2005-11-10 at 09:41 -0500, Philip Polstra wrote:
&gt; &gt; I would use split instead of what you are doing with the pattern
&gt; &gt; match.  Something like this
&gt; &gt; ($verb, $noun, $cmdline) = split /\s+/, $_, 3;
&gt; &gt; 
&gt; &gt; You can then check to see if $noun and $cmdline are defined to know
&gt; &gt; how many parameters were passed.
&gt; &gt; 
&gt; &gt; On 11/10/05, Christopher Fowler &lt;cfowler at outpostsentinel.com&gt; wrote:
&gt; &gt;         Perl Guru's:
&gt; &gt;         
&gt; &gt;         I'm trying to create a config shell that runs in Linux that
&gt; &gt;         will use 
&gt; &gt;         XML-RPC to configure our embedded device.  The XML-RPC thing
&gt; &gt;         is
&gt; &gt;         complete.  What I'm working on now is parsing the command
&gt; &gt;         line.
&gt; &gt;         
&gt; &gt;         here is my code:
&gt; &gt;         
&gt; &gt;         --------------------------------
&gt; &gt;         sub prompt {
&gt; &gt;           print &quot;# &quot;; 
&gt; &gt;           my $cmd = &lt;STDIN&gt;;
&gt; &gt;           chomp $cmd;
&gt; &gt;           $cmd =~ m/^(.+?)\s(.+?)\s(.+?)$/;
&gt; &gt;           my $verb = $1;
&gt; &gt;           my $noun = $2;
&gt; &gt;           my $cmdline = $3;
&gt; &gt;           print &quot;[[$verb]]\n&quot;;
&gt; &gt;           return ($verb, $noun, $cmdline); 
&gt; &gt;         }
&gt; &gt;         -------------------------------
&gt; &gt;         
&gt; &gt;         $1, $2, and $3 substitutions fail when there is only one verb
&gt; &gt;         like
&gt; &gt;         'exit'.  Verbs can be 'show, set, add, delete, or
&gt; &gt;         exit'.  Nouns can be
&gt; &gt;         'port, user, vtun, snmp, etc.'   So to show port 1's config I
&gt; &gt;         use 'show 
&gt; &gt;         port 1'  To show all ports I use 'show port'.  I guess I could
&gt; &gt;         simply
&gt; &gt;         use split and split on \s boundaries.  for $cmdline I need to
&gt; &gt;         be
&gt; &gt;         smarter.  Some items have descriptions that can include a
&gt; &gt;         space and I
&gt; &gt;         will want to cut $cmdline into arguments. 
&gt; &gt;         
&gt; &gt;         'set system location &quot;Buford Development&quot;'
&gt; &gt;         verb = set
&gt; &gt;         noun = system
&gt; &gt;         arg[0] = location
&gt; &gt;         arg[1] = 'Buford Development'
&gt; &gt;         
&gt; &gt;         So I'm trying to do shell like parsing.  I bet there is a
&gt; &gt;         module that 
&gt; &gt;         does all this for me.  If not can someone point me in the best
&gt; &gt;         direction.
&gt; &gt;         
&gt; &gt;         Thanks,
&gt; &gt;         Chris
&gt; &gt;         
&gt; &gt;         
&gt; &gt;         _______________________________________________
&gt; &gt;         Ale mailing list
&gt; &gt;         Ale at ale.org
&gt; &gt;         <a  rel="nofollow" href="http://www.ale.org/mailman/listinfo/ale";>http://www.ale.org/mailman/listinfo/ale</a>
&gt; &gt; 
&gt; &gt; _______________________________________________
&gt; &gt; Ale mailing list
&gt; &gt; Ale at ale.org
&gt; &gt; <a  rel="nofollow" href="http://www.ale.org/mailman/listinfo/ale";>http://www.ale.org/mailman/listinfo/ale</a>
&gt; 
&gt; _______________________________________________
&gt; Ale mailing list
&gt; Ale at ale.org
&gt; <a  rel="nofollow" href="http://www.ale.org/mailman/listinfo/ale";>http://www.ale.org/mailman/listinfo/ale</a>



</pre>
<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<hr>
<!--X-Follow-Ups-End-->
<!--X-References-->
<ul><li><strong>References</strong>:
<ul>
<li><strong><a name="00159" href="msg00159.html">[ale] Perl parsing problem</a></strong>
<ul><li><em>From:</em> cfowler at outpostsentinel.com (Christopher Fowler)</li></ul></li>
<li><strong><a name="00160" href="msg00160.html">[ale] Perl parsing problem</a></strong>
<ul><li><em>From:</em> ppolstra at gmail.com (Philip Polstra)</li></ul></li>
<li><strong><a name="00161" href="msg00161.html">[ale] Perl parsing problem</a></strong>
<ul><li><em>From:</em> cfowler at outpostsentinel.com (Christopher Fowler)</li></ul></li>
</ul></li></ul>
<!--X-References-End-->
<!--X-BotPNI-->
<ul>
<li>Prev by Date:
<strong><a href="msg00163.html">[ale] Parking for ALE Central Meeting, 11/10/05</a></strong>
</li>
<li>Next by Date:
<strong><a href="msg00165.html">[ale] tux magazine</a></strong>
</li>
<li>Previous by thread:
<strong><a href="msg00161.html">[ale] Perl parsing problem</a></strong>
</li>
<li>Next by thread:
<strong><a href="msg00163.html">[ale] Parking for ALE Central Meeting, 11/10/05</a></strong>
</li>
<li>Index(es):
<ul>
<li><a href="maillist.html#00164"><strong>Date</strong></a></li>
<li><a href="threads.html#00164"><strong>Thread</strong></a></li>
</ul>
</li>
</ul>

<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
</body>
</html>