starcluster.commands.completers

Package starcluster :: Package commands :: Module completers |
[hide private]
[frames] | no frames]

# Source Code for Module starcluster.commands.completers

      1  #!/usr/bin/env python
      2
      3  from starcluster import optcomplete
      4  from starcluster.logger import log
      5
      6  from base import CmdBase
      7
      8
      9 -class Completer(CmdBase):
     10      """
     11      Base class for all completer classes
     12      """
     13
     14      @property
     15 -    def completer(self):
     16          return self._completer()
     17
     18
     19 -class ClusterCompleter(Completer):
     20      """
     21      Returns a list of all cluster names as completion options
     22      """
     23 -    def _completer(self):
     24          try:
     25              cm = self.cm
     26              clusters = cm.get_cluster_security_groups()
     27              completion_list = [cm.get_tag_from_sg(sg.name) \
     28                                 for sg in clusters]
     29              return optcomplete.ListCompleter(completion_list)
     30          except Exception, e:
     31              log.error('something went wrong fix me: %s' % e)
     32
     33
     34 -class NodeCompleter(Completer):
     35      """
     36      Returns a list of all node names as completion options
     37      """
     38 -    def _completer(self):
     39          try:
     40              cm = self.cm
     41              clusters = cm.get_cluster_security_groups()
     42              compl_list = [cm.get_tag_from_sg(sg.name) for sg in clusters]
     43              max_num_nodes = 0
     44              for scluster in clusters:
     45                  num_instances = len(scluster.instances())
     46                  if num_instances > max_num_nodes:
     47                      max_num_nodes = num_instances
     48              compl_list.extend(['master'])
     49              compl_list.extend([str(i) for i in range(0, num_instances)])
     50              compl_list.extend(["node%03d" % i \
     51                                 for i in range(1, num_instances)])
     52              return optcomplete.ListCompleter(compl_list)
     53          except Exception, e:
     54              print e
     55              log.error('something went wrong fix me: %s' % e)
     56
     57
     58 -class ImageCompleter(Completer):
     59      """
     60      Returns a list of all registered image ids as completion options
     61      """
     62 -    def _completer(self):
     63          try:
     64              rimages = self.ec2.registered_images
     65              completion_list = [i.id for i in rimages]
     66              return optcomplete.ListCompleter(completion_list)
     67          except Exception, e:
     68              log.error('something went wrong fix me: %s' % e)
     69
     70
     71 -class EBSImageCompleter(Completer):
     72      """
     73      Returns a list of all registered EBS image ids as completion options
     74      """
     75 -    def _completer(self):
     76          try:
     77              rimages = self.ec2.registered_images
     78              completion_list = [i.id for i in rimages if
     79                                 i.root_device_type == "ebs"]
     80              return optcomplete.ListCompleter(completion_list)
     81          except Exception, e:
     82              log.error('something went wrong fix me: %s' % e)
     83
     84
     85 -class S3ImageCompleter(Completer):
     86      """
     87      Returns a list of all registered S3 image ids as completion options
     88      """
     89 -    def _completer(self):
     90          try:
     91              rimages = self.ec2.registered_images
     92              completion_list = [i.id for i in rimages if
     93                                 i.root_device_type == "instance-store"]
     94              return optcomplete.ListCompleter(completion_list)
     95          except Exception, e:
     96              log.error('something went wrong fix me: %s' % e)
     97
     98
     99 -class InstanceCompleter(Completer):
    100      """
    101      Returns a list of all instance ids as completion options
    102      """
    103      show_dns_names = False
    104
    105 -    def _completer(self):
    106          try:
    107              instances = self.ec2.get_all_instances()
    108              completion_list = [i.id for i in instances]
    109              if self.show_dns_names:
    110                  completion_list.extend([i.dns_name for i in instances])
    111              return optcomplete.ListCompleter(completion_list)
    112          except Exception, e:
    113              log.error('something went wrong fix me: %s' % e)
    114
    115
    116 -class VolumeCompleter(Completer):
    117      """
    118      Returns a list of all volume ids as completion options
    119      """
    120 -    def _completer(self):
    121          try:
    122              completion_list = [v.id for v in self.ec2.get_volumes()]
    123              return optcomplete.ListCompleter(completion_list)
    124          except Exception, e:
    125              log.error('something went wrong fix me: %s' % e)
    126