emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Some advice on how to use babel to generate cisco configs
@ 2013-01-30 22:24 Bart Bunting
  2013-01-31  9:50 ` Karl Voit
  2013-01-31 11:44 ` Thomas S. Dye
  0 siblings, 2 replies; 5+ messages in thread
From: Bart Bunting @ 2013-01-30 22:24 UTC (permalink / raw)
  To: emacs-orgmode

Good morning,

I have been trying to figure out without much luck how to use babel to
generate some cisco configs.


What I would like to achieve is to have a table containing a few values,
e.g. ip address vlan number etc.

Then have a cisco config in the org file with markers where the
substitutions are to be inserted.
Run through the table and create a node in the org file one for each row
of the table.

The end result should be a set of cisco configs with the substitutions
made.  I was hoping to also use shell to call pwgen to generate a
random password to insert.
  
Hope that ramble made some sort of sence.

Can someone give me some ideas on how to put this together?

I tried to use an org source block and a shell function to parse it.  I
couldn't quite tie together how to get the output to work correctly or
how to be able to parse each line....


Kind regards

Bart
-- 


Kind regards

Bart

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Some advice on how to use babel to generate cisco configs
  2013-01-30 22:24 Some advice on how to use babel to generate cisco configs Bart Bunting
@ 2013-01-31  9:50 ` Karl Voit
  2013-01-31 11:44 ` Thomas S. Dye
  1 sibling, 0 replies; 5+ messages in thread
From: Karl Voit @ 2013-01-31  9:50 UTC (permalink / raw)
  To: emacs-orgmode

* Bart Bunting <bart@bunting.net.au> wrote:
> Good morning,

Hi!

> What I would like to achieve is to have a table containing a few values,
> e.g. ip address vlan number etc.
>
> Then have a cisco config in the org file with markers where the
> substitutions are to be inserted.
> Run through the table and create a node in the org file one for each row
> of the table.

Are you planning to use this as a one-time creation thing or do you
want to re-run (and re-generate) the configs from the same table
multiple times?

> The end result should be a set of cisco configs with the substitutions
> made.  I was hoping to also use shell to call pwgen to generate a
> random password to insert.

If it is one-time only, you might be happy using a yasnippet
template which generates your substitutions.

-- 
Karl Voit

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Some advice on how to use babel to generate cisco configs
  2013-01-30 22:24 Some advice on how to use babel to generate cisco configs Bart Bunting
  2013-01-31  9:50 ` Karl Voit
@ 2013-01-31 11:44 ` Thomas S. Dye
  2013-02-01  8:10   ` Bart Bunting
  1 sibling, 1 reply; 5+ messages in thread
From: Thomas S. Dye @ 2013-01-31 11:44 UTC (permalink / raw)
  To: Bart Bunting; +Cc: emacs-orgmode

Aloha Bart,
"Bart Bunting" <bart@bunting.net.au> writes:

> Good morning,
>
> I have been trying to figure out without much luck how to use babel to
> generate some cisco configs.
>
>
> What I would like to achieve is to have a table containing a few values,
> e.g. ip address vlan number etc.
>
> Then have a cisco config in the org file with markers where the
> substitutions are to be inserted.
> Run through the table and create a node in the org file one for each row
> of the table.
>
> The end result should be a set of cisco configs with the substitutions
> made.  I was hoping to also use shell to call pwgen to generate a
> random password to insert.
>   
> Hope that ramble made some sort of sence.

I don't know a Cisco config from a fig newton, but here is my sense of
what you wrote, in case it is helpful.

#+name: cisco-table
| 1 | one   | two  |
| 2 | three | four |
| 3 | five  | six  |

#+header: :results output raw
#+header: :var x=cisco-table
#+begin_src python
  for y in x:
      s = "* Cisco %s \nTwiddle %s, poke %s \n\n" % tuple(y)
      print s,
#+end_src

#+results:
* Cisco 1 
Twiddle one, poke two 

* Cisco 2 
Twiddle three, poke four 

* Cisco 3 
Twiddle five, poke six 

-- 
Thomas S. Dye
http://www.tsdye.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Some advice on how to use babel to generate cisco configs
  2013-01-31 11:44 ` Thomas S. Dye
@ 2013-02-01  8:10   ` Bart Bunting
  2013-02-01 15:34     ` Thomas S. Dye
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Bunting @ 2013-02-01  8:10 UTC (permalink / raw)
  To: Thomas S. Dye; +Cc: emacs-orgmode

Thomas,

Thanks!  That is pretty much what I was struggling with.

Thanks for putting it together for me.  

The only other question I have is, is there a way to prevent the results
from appending each time?


Cheers

Bart


"Thomas S. Dye" <tsd@tsdye.com> writes:

> Aloha Bart,
> "Bart Bunting" <bart@bunting.net.au> writes:
>
>> Good morning,
>>
>> I have been trying to figure out without much luck how to use babel to
>> generate some cisco configs.
>>
>>
>> What I would like to achieve is to have a table containing a few values,
>> e.g. ip address vlan number etc.
>>
>> Then have a cisco config in the org file with markers where the
>> substitutions are to be inserted.
>> Run through the table and create a node in the org file one for each row
>> of the table.
>>
>> The end result should be a set of cisco configs with the substitutions
>> made.  I was hoping to also use shell to call pwgen to generate a
>> random password to insert.
>>   
>> Hope that ramble made some sort of sence.
>
> I don't know a Cisco config from a fig newton, but here is my sense of
> what you wrote, in case it is helpful.
>
> #+name: cisco-table
> | 1 | one   | two  |
> | 2 | three | four |
> | 3 | five  | six  |
>
> #+header: :results output raw
> #+header: :var x=cisco-table
> #+begin_src python
>   for y in x:
>       s = "* Cisco %s \nTwiddle %s, poke %s \n\n" % tuple(y)
>       print s,
> #+end_src
>
> #+results:
> * Cisco 1 
> Twiddle one, poke two 
>
> * Cisco 2 
> Twiddle three, poke four 
>
> * Cisco 3 
> Twiddle five, poke six 
>
> -- 
> Thomas S. Dye
> http://www.tsdye.com
Bart
-- 


Kind regards

Bart

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Some advice on how to use babel to generate cisco configs
  2013-02-01  8:10   ` Bart Bunting
@ 2013-02-01 15:34     ` Thomas S. Dye
  0 siblings, 0 replies; 5+ messages in thread
From: Thomas S. Dye @ 2013-02-01 15:34 UTC (permalink / raw)
  To: Bart Bunting; +Cc: emacs-orgmode

"Bart Bunting" <bart@bunting.net.au> writes:

> Thomas,
>
> Thanks!  That is pretty much what I was struggling with.

Good news.  I'm happy it's starting to work for you.
>
> Thanks for putting it together for me.  
>
> The only other question I have is, is there a way to prevent the results
> from appending each time?

See the manual, 14.8.2.2 :results.  You probably want :results replace.

All the best,
Tom

-- 
T.S. Dye & Colleagues, Archaeologists
735 Bishop St, Suite 315, Honolulu, HI 96813
Tel: 808-529-0866, Fax: 808-529-0884
http://www.tsdye.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-02-01 15:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-30 22:24 Some advice on how to use babel to generate cisco configs Bart Bunting
2013-01-31  9:50 ` Karl Voit
2013-01-31 11:44 ` Thomas S. Dye
2013-02-01  8:10   ` Bart Bunting
2013-02-01 15:34     ` Thomas S. Dye

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).