Searches for a db instance named :attr:`name`.

        :param str name:  The name of the target db instance

        :param bool running:  A flag to only look for instances that are
            actually *running*.

        :rtype:  :class:`dict`
188277
def find_db_instance(self, name, running=True):
        
        found = None
        for i in self.provider.reddwarf_client.instances.list():
            if i.name == name:
                if not running:  # don't care if it's running or not
                    found = i
                if i.status == 'running':
                    found = i
        if found:
            log.info("Found existing db, %s (%s)" % (found.name, found.id))
            return db_to_dict(found)
1088725
def DbGetInstanceNameList(self, argin):
        
        self._log.debug("In DbGetInstanceNameList()")
        return self.db.get_instance_name_list(argin)
941095
def container_running(self, id=None, name=None):
        
        running = False
        if id:
            running = self.inspect_container(id)['State']['Running']
        elif name:
            running = self.inspect_container(name)['State']['Running']
        return running
994220
def get_connection_by_name(self, name):
        ''''''
        with self._mutex:
            for conn in self.connections:
                if conn.name == name:
                    return conn
            return None
655563
def _find_existing_instance(self):
        
        if not self.connection:
            return None

        domains = yield self.connection.all()
        for d in domains:
            name = yield d.name()
            if name.startswith(self.workername):
                self.domain = d
                break

        self.ready = True
519177
def server_by_name(self, name):
        '''
        
        '''
        return self.server_show_libcloud(
            self.server_list().get(name, {}).get('id', '')
        )
439188
def find_existing(self):
        
        instances = self.consul.find_servers(self.tags)
        maxnames = len(instances)
        while instances:
            i = instances.pop(0)
            server_id = i[A.server.ID]
            if self.namespace.add_if_unique(server_id):
                log.info('Found existing server, %s' % server_id)
                self.server_attrs = i
                break
            if len(self.namespace.names) >= maxnames:
                break
            instances.append(i)
529687
def _get_db_names(self, dbs, strict=True):
        
        dbs = utils.coerce_to_list(dbs)
        db_names = [utils.get_name(db) for db in dbs]
        if strict:
            good_dbs = self.instance.list_databases()
            good_names = [utils.get_name(good_db) for good_db in good_dbs]
            bad_names = [db_name for db_name in db_names
                    if db_name not in good_names]
            if bad_names:
                bad = ", ".join(bad_names)
                raise exc.NoSuchDatabase("The following database(s) were not "
                        "found: %s" % bad)
        return db_names
64883
def _check_db_exists(self, instance):
        

        dsn, host, username, password, database, driver = self._get_access_info(instance, self.DEFAULT_DB_KEY)
        context = "{} - {}".format(host, database)
        if self.existing_databases is None:
            cursor = self.get_cursor(instance, None, self.DEFAULT_DATABASE)

            try:
                self.existing_databases = {}
                cursor.execute(DATABASE_EXISTS_QUERY)
                for row in cursor:
                    self.existing_databases[row.name] = True

            except Exception as e:
                self.log.error("Failed to check if database {} exists: {}".format(database, e))
                return False, context
            finally:
                self.close_cursor(cursor)

        return database in self.existing_databases, context
605395
def get_by_name(self, name):
        
        result = self.get_by("name", name)

        if result:
            data = result[0]
            new_resource = self.new(self._connection, data)
        else:
            new_resource = None

        return new_resource
648789
def get_name(tags_or_instance_or_id):
  

  ec2 = get_ec2_resource()
  if hasattr(tags_or_instance_or_id, 'tags'):
    tags = tags_or_instance_or_id.tags
  elif isinstance(tags_or_instance_or_id, str):
    tags = ec2.Instance(tags_or_instance_or_id).tags
  elif tags_or_instance_or_id is None:
    return EMPTY_NAME
  else:
    assert isinstance(tags_or_instance_or_id,
                      Iterable), "expected iterable of tags"
    tags = tags_or_instance_or_id

  if not tags:
    return EMPTY_NAME
  names = [entry['Value'] for entry in tags if entry['Key'] == 'Name']
  if not names:
    return ''
  if len(names) > 1:
    assert False, "have more than one name: " + str(names)
  return names[0]
789353
def vm_running(name):
    '''
    

    '''
    name = name.lower()
    ret = {'name': name,
           'changes': {},
           'result': None,
           'comment': ''}

    if name in __salt__['vmadm.list'](order='hostname', search='state=running'):
        # we're good
        ret['result'] = True
        ret['comment'] = 'vm {0} already running'.format(name)
    else:
        # start the vm
        ret['result'] = True if __opts__['test'] else __salt__['vmadm.start'](name, key='hostname')
        if not isinstance(ret['result'], bool) and ret['result'].get('Error'):
            ret['result'] = False
            ret['comment'] = 'failed to start {0}'.format(name)
        else:
            ret['changes'][name] = 'running'
            ret['comment'] = 'vm {0} started'.format(name)

    return ret
1116353
def db(cls, dbname=None):
        

        cls._load_entry_points()

        dbname = dbname or config.get('eop', 'dbname', fallback=cls.DEFAULT_DBNAME)

        if dbname not in cls._dbs.keys():
            raise EopError("Unknown database '%s'" % dbname)

        if isclass(cls._dbs[dbname]):
            # Instanciation
            try:
                cls._dbs[dbname] = cls._dbs[dbname]()
            except Exception as e:
                # Keep the exception in cache in order to not retry instanciation
                # every single time EopDb.db() is called, as instanciation
                # of database is generally a time consumming operation.
                # If it failed once, it will most probably fail again
                cls._dbs[dbname] = e

        if isinstance(cls._dbs[dbname], Exception):
            raise EopError("Problem at database instanciation") from cls._dbs[dbname]

        return cls._dbs[dbname]
68931
def lookup(self, name):
        

        if name in self.attributes():
            return getattr(self, IMPL_PREFIX + name)
        raise exceptions.AttributeInferenceError(target=self._instance, attribute=name)
1037899
def lookup_instance(name: str, instance_type: str = '', image_name: str = '',
                    states: tuple = ('running', 'stopped', 'initializing')):
  

  ec2 = get_ec2_resource()

  instances = ec2.instances.filter(
    Filters=[{'Name': 'instance-state-name', 'Values': states}])

  prefix = get_prefix()
  username = get_username()

  # look for an existing instance matching job, ignore instances launched
  # by different user or under different resource name
  result = []
  for i in instances.all():
    instance_name = get_name(i)
    if instance_name != name:
      continue

    seen_prefix, seen_username = parse_key_name(i.key_name)
    if prefix != seen_prefix:
      print(f"Found {name} launched under {seen_prefix}, ignoring")
      continue
    if username != seen_username:
      print(f"Found {name} launched by {seen_username}, ignoring")
      continue

    if instance_type:
      assert i.instance_type == instance_type, f"Found existing instance for job {name} but different instance type ({i.instance_type}) than requested ({instance_type}), terminate {name} first or use new task name."

    if image_name:
      assert i.image.name == image_name, f"Found existing instance for job {name} but launched with different image ({i.image.name}) than requested ({image_name}), terminate {name} first or use new task name."
    result.append(i)

    assert len(result) < 2, f"Found two instances with name {name}"
    if not result:
      return None
    else:
      return result[0]
959410
def _name_exists(self, name):
        
        for i in range(self.count()):
            if self.tabText(i) == name:
                return True
        return False
678696
def in_tree(self, name):
        
        """
        if self._validate_node_name(name):
            raise RuntimeError("Argument `name` is not valid")
        return name in self._db