コード例 #1
0
ファイル: omf_cinder.py プロジェクト: thetoolsmith/omf
  def get_available_volumes(self):
    '''
    Get volumes with available status. If there are no available volumes, one will be created, so this method should \
    always return a non empty LIST [] 

    INPUT:
 
      * none

    RETURN:

      * LIST  Openstack Volume objects
    '''
    self._statusfilter = 'Available'

    runningtime, obj = omfbase.trace(self._volumes)
    self.parent.log_and_print_info('Volumes query took: {0}'.format(runningtime))

    if (not obj):
      self.parent.log_and_print_info('Creating new volume as needed...')

      cfg = {}
      cfg['name'] = 'VOL_{0}'.format(str(random.getrandbits(24)))
      cfg['description'] = "added dynamically for scale"
      cfg['size'] = self.vol_size
 
      if(self.create_volume(cfg)):
        runningtime, obj = omfbase.trace(self._volumes)
        self.parent.log_and_print_info('Volumes create took: {0}'.format(runningtime))

    return obj
コード例 #2
0
ファイル: omf_cinder.py プロジェクト: thetoolsmith/omf
  def get_volumes_info(self, namefilter=None):
    '''
    Detailed volume lookup

    INPUT:
 
      * STRING namefilter - optional. filter by specific Volume name

    RETURN:

      * NamedTuple VolumeFull 
    '''
    if (namefilter):
      self._namefilter = namefilter

    runningtime, obj = omfbase.trace(self._volumes)
    self.parent.log_and_print_info('Volumes query took: {0}'.format(runningtime))

    _volumes = []

    for v in obj:
      _vol = VolumeFull(status = v.status, name = v.name, attachments = v.attachments, availability_zone = v.availability_zone, created_at = v.created_at, description = v.description, volume_type = v.volume_type, snapshot_id = v.snapshot_id, source_volid = v.source_volid, metadata = v.metadata, id = v.id, size = v.size)

      _volumes.append(_vol)

    return _volumes
コード例 #3
0
ファイル: omf_ceilometer.py プロジェクト: thetoolsmith/omf
  def get_metrics(self, namefilter=None, metric=None):
    '''
    Look up ceilometer metric

    INPUT:
    
      STRING namefilter - openstack instance server name to filter on

      STRING metric - specify a single metric to get

    RETURN:

      LIST of openstack metric objects
    ''' 
    if (namefilter):
      if (self.debug):
        self.parent.log_and_print_info('Setting namefilter to {0}'.format(namefilter))
      self._name_filter = namefilter

    if (metric):
      if (self.debug):
        self.parent.log_and_print_info('Setting metric filter to {0}'.format(metric))
      self._metric_filter = metric

    runningtime, obj = omfbase.trace(self._metrics)
    self.parent.log_and_print_info('Metrics query took: {0}'.format(runningtime))

    return obj 
コード例 #4
0
ファイル: omf_heat.py プロジェクト: thetoolsmith/omf
  def create_stack(self, name=None, stack=None):
    '''
    Create new stack wih Heat client

    INPUT:

      * STRING name - REQUIRED user specified name of stack to create

      * STRING stack - REQUIRED HOT template formatted string of stack data
    
    RETURN:

      * True - success (already verified so no need to do that in the caller)

      * False - failed to create stack
    '''
    newstack = None

    # COULD ADD CHECK FOR DUPLICATE STACK NAME, HOWEVER UNLIKE MANY OTHER OPENSTACK
    # COMPONENTS, THE HEAT STACK CREATE NATIVE WILL RETURN A MESSAGE 'STACK ALERADY EXISTS, SO NOT 
    # SURE WE NEED TO ADD THIS.
  

    if ((not name) or (not stack)):
      self.parent.log_and_exit('name and stack are required for {0}'.format(inspect.getframeinfo(inspect.currentframe())[2]), 1903)

    self.stackname = name 
    self.stackdata = stack

    runningtime, newstack = omfbase.trace(self._create_stack)
    self.parent.log_and_print_info('Create Stack took: {0}'.format(runningtime))

    # WAIT FOR READINESS
    waiting = True
    _start = datetime.now()

    self._name_filter = self.stackname

    sys.stdout.write('Waiting for STACK {0} to be ready'.format(self._name_filter))

    while (waiting):
      waiting = False
      try:
        count, stack_gen, stack_list = self._stacks()
        if (count): #at least 1 stack
          if (not stack_list[0].stack_status.upper() == 'CREATE_COMPLETE'):
            waiting = True
            sys.stdout.write('. ')
            sys.stdout.flush()
            time.sleep(self.wait_time)
          else:
            self.parent.log_and_print_info('New STACK {0} is ready.'.format(stack_list[0].stack_name))
            self.parent.log_and_print_info('Verify STACK took: {0}'.format(datetime.now() - _start))
      except Exception as e:
        self.parent.log_and_exit(e, 1904)    

    return newstack
コード例 #5
0
ファイル: omf_nova.py プロジェクト: thetoolsmith/omf
  def get_flavors(self):
    '''
    Openstack native flavor list lookup

    INPUTS: none

    RETURN:
	
      LIST flavors

    '''
    runningtime, obj = omfbase.trace(self._flavors)
    self.parent.log_and_print_info('Flavors query took: {0}'.format(runningtime))

    return obj
コード例 #6
0
ファイル: omf_cinder.py プロジェクト: thetoolsmith/omf
  def get_quotas(self):
    '''
    Basic lookup of quotas

    INPUTS:
   
      * none

    RETURN:

      * Instance Openstack Quota object
    '''
    runningtime, obj = omfbase.trace(self._quotas)
    self.parent.log_and_print_info('Quota query took: {0}'.format(runningtime))

    return obj
コード例 #7
0
ファイル: omf_nova.py プロジェクト: thetoolsmith/omf
  def get_instances_with_status(self, servers=None, namefilter=None):
    '''
    Get list of details of instance on all or one hypervisor

    INPUT:	
      
      LIST servers - set of openstack server instances
      
      STRING namefilter - optional. Specify a specific hypervisor

    RETURN:
 
      NamedTuple Instance
    '''
    dataset = set([])

    if (namefilter):
      self._name_filter = namefilter

    if (not servers):
      self.parent.log_and_exit('HypervisorServers object required', 1614)

    runningtime, obj = omfbase.trace(self._instances)
    self.parent.log_and_print_info('Instance query took: {0}'.format(runningtime))

    for s in servers:
      _uuid = s.items()[0][1]
      _node = s.items()[1][1]
      _status = None
      _host = None

      for i in obj:

        if (_node.lower() == getattr(i, 'OS-EXT-SRV-ATTR:instance_name').lower()):
          _status = i.status
          _host = getattr(i, 'OS-EXT-SRV-ATTR:hypervisor_hostname')
          break
          #can also get status by getattr(i, 'OS-EXT-STS:vm_state') 

      _instance = Instance(host = _host, \
                           name = _node, \
                           uuid = _uuid, \
                           status = _status)

      dataset.add(_instance)

    return dataset
コード例 #8
0
ファイル: omf-osmgr.py プロジェクト: thetoolsmith/omf
def evacuate_host(host_instances=None):
  '''
  Calls native openstack host evacuate methods

  INPUT:

    * LIST host instances

  RETURN:

    INT failed count 

  '''  
  if (not host_instances):
    return 0

  failed = []

  # FIRST CALL METHOD TO POWER DOWN THE MACHINE BEFORE EVACUATION ROUTINE

  for i in host_instances:
    __evacuating_node = i['uuid']

    # FIRST CALL CISCO UCS AND POWER DOWN THE MACHINE BEFORE EVACUATION ROUTINE
    if (powerdown_node(i['name'])):
      failed.append(str(i['name']))
      continue

    runningtime, obj = omfbase.trace(_evacuate, i['uuid'])

    if (debug):
      os_client.log_and_print_info('Evacuate {0}:{1} took: {2}'.format(i['name'],i['uuid'], runningtime)) 
    else:
      os_client.log_info('Evacuate {0}:{1} took: {2}'.format(i['name'],i['uuid'], runningtime))

    if (obj):
      failed.append(str(i['name']))
    
      if (debug):
        os_client.log_and_print_error('Failed to evacuate {0}:{1}'.format(i['name'],i['uuid']))

  if (len(failed) > 0):
    if (debug):
      os_client.log_and_print_error('Total host failed to evacuate: {0} \n{1}'.format(len(failed), failed))
    return len(failed)
  else:
    return 0
コード例 #9
0
ファイル: omf_nova.py プロジェクト: thetoolsmith/omf
  def get_hypervisors_info(self, namefilter=None):
    '''
    Get list of details of all or one hypervisor

    INPUT:	
     
      STRING namefilter - optional. Specify a specific hypervisor

    RETURN:
 
      NamedTuple ComputeNode
    '''
    if (namefilter):
      self._name_filter = namefilter

    runningtime, obj = omfbase.trace(self._populate_compute_nodes)
    self.parent.log_and_print_info('Populate ComputeNode type took: {0}'.format(runningtime))

    return obj
コード例 #10
0
ファイル: omf_nova.py プロジェクト: thetoolsmith/omf
  def get_hypervisors(self, namefilter=None):
    '''
    Get list of all or one hypervisor

    INPUT:	
     
      STRING namefilter - optional. Specify a specific hypervisor

    RETURN:
 
      LIST openstack hypervisor host name
    '''
    if (namefilter):
      self._name_filter = namefilter

    runningtime, obj = omfbase.trace(self._hypervisors)
    self.parent.log_and_print_info('Host query took: {0}'.format(runningtime))

    return obj
コード例 #11
0
ファイル: omf_nova.py プロジェクト: thetoolsmith/omf
  def get_host_instances(self, namefilter=None):
    '''
    Look up instances on one or all OS hosts

    INPUT:	
     
      STRING namefilter - optional. Specify a specific hypervisor

    RETURN:
 
      LIST openstack Server objects
    '''
    if (namefilter):
      self._name_filter = namefilter

    runningtime, obj = omfbase.trace(self._host_instances)
    self.parent.log_and_print_info('Host server instance query took: {0}'.format(runningtime))

    return obj
コード例 #12
0
ファイル: omf_nova.py プロジェクト: thetoolsmith/omf
  def get_instance(self, namefilter=None):
    '''
    Look up instance or instances

    INPUT:	
     
      STRING namefilter - optional instance server name to lookup

    RETURN:
 
      LIST openstack Server objects
    '''
    if (namefilter):
      self._name_filter = namefilter

    runningtime, obj = omfbase.trace(self._instances)
    self.parent.log_info('Server query took: {0}'.format(runningtime))

    return obj
コード例 #13
0
ファイル: omf_neutron.py プロジェクト: thetoolsmith/omf
  def get_networks(self, namefilter=None):
    '''
    Returns a list of Openstack Networks

    INPUTS:

      * STRING namefilter - optional network name filter

    RETURN:

      LIST openstack networks
    '''
    if(namefilter):
      self.name_filter = namefilter

    runningtime, obj = omfbase.trace(self._networks)
    self.parent.log_and_print_info('Networks query took: {0}'.format(runningtime))

    return obj 
コード例 #14
0
ファイル: omf_cinder.py プロジェクト: thetoolsmith/omf
  def get_volumes_basic(self, namefilter=None):
    '''
    Basic volumes lookup 

    INPUT:
 
      * STRING namefilter - optional. filter by specific Volume name

    RETURN:

      * LIST Openstack Volume object
    '''
    if (namefilter):
      self._namefilter = namefilter

    runningtime, obj = omfbase.trace(self._volumes)
    self.parent.log_and_print_info('Volumes query took: {0}'.format(runningtime))

    return obj
コード例 #15
0
ファイル: omf_cinder.py プロジェクト: thetoolsmith/omf
  def create_volume(self, config, force=False):
    '''
    Create a new volume regardless of number of available volumes

    INPUT:
 
      * DICT config - dictionary of required volume data. name required at minimum

      * BOOL force - optional. force re-create volume if it pre-exists. default False

    RETURN:
    
      * Instance Openstack Volume object
    '''  
    if (not config):
      self.parent.log_and_exit('You must specify a volume config dictionary type name when creating', 1703)

    if (not config['name']):
      self.parent.log_and_exit('You must specify a Volume name.', 1703)

    if (not config['size']):
      config['size'] = self.vol_size

    vol = self.get_volumes_basic()

    for v in vol:
      if v.name == config['name']:
        self.parent.log_error('Duplicate Volume name. Name must not exist in tenent')
        if (force):
          self.parent.log_and_print_info('You specified to force re-create volume {0}'.format(config['name']))
          d = v.delete()
        else:
          self.parent.log_and_exit('Volume name specified is in use: {0}'.format(config['name']), 1707)

    self.vol_config = config

    runningtime, obj = omfbase.trace(self._create_volume)
    self.parent.log_and_print_info('Create Volume took: {0}'.format(runningtime))

    return obj
コード例 #16
0
ファイル: omf_nova.py プロジェクト: thetoolsmith/omf
  def hv_search(self, hvhost=None, sflag=False):
    '''
    Lookup hypervisor object

    INPUT:	
     
      STRING hvhost - optional. Specify a specific hypervisor

      BOOL sflag - optional return server property of hypervisor. default False

    RETURN:
 
      LIST openstack hypervisor object
    '''

    if not (hvhost):
      self.parent.log_and_exit('Hypervisor host required.', 114)

    self.sflag = sflag
    self.hvhost = hvhost
    runningtime, obj = omfbase.trace(self._search_hypervisors)
    self.parent.log_and_print_info('Hypervisor Search query took: {0}'.format(runningtime))

    return obj