29fc80d0453cedac9426c1cb303f8bcb7ff25fb7
[sfa.git] / sfa / client / sfiListNodes.py
1 #! /usr/bin/env python
2
3 import sys
4 from sfa.client.sfi_commands import Commands
5 from sfa.rspecs.rspec import RSpec
6 from sfa.util.plxrn import xrn_to_hostname 
7
8 command = Commands(usage="%prog [options]",
9                    description="List all nodes in the RSpec. " + 
10                    "Use this to display the list of nodes on which it is " + 
11                    "possible to create a slice.")
12 command.prep()
13
14 if command.opts.infile:
15     rspec = RSpec(command.opts.infile)
16     nodes = rspec.version.get_nodes()
17     if command.opts.outfile:
18         sys.stdout = open(command.opts.outfile, 'w')
19     
20     for node in nodes:
21         hostname = None
22         if node.get('component_name'):
23             hostname = node['component_name']
24         elif node.get('component_id'):
25             hostname = xrn_to_hostname(node['component_id'])
26         if hostname:
27             print hostname 
28
29
30
31