Return environment details.
511435
def get_environment(self):
        """"""
        environment = junos_views.junos_environment_table(self.device)
        routing_engine = junos_views.junos_routing_engine_table(self.device)
        temperature_thresholds = junos_views.junos_temperature_thresholds(self.device)
        power_supplies = junos_views.junos_pem_table(self.device)
        environment.get()
        routing_engine.get()
        temperature_thresholds.get()
        environment_data = {}
        current_class = None

        for sensor_object, object_data in environment.items():
            structured_object_data = {k: v for k, v in object_data}

            if structured_object_data["class"]:
                # If current object has a 'class' defined, store it for use
                # on subsequent unlabeled lines.
                current_class = structured_object_data["class"]
            else:
                # Juniper doesn't label the 2nd+ lines of a given class with a
                # class name.  In that case, we use the most recent class seen.
                structured_object_data["class"] = current_class

            if structured_object_data["class"] == "Power":
                # Create a dict for the 'power' key
                try:
                    environment_data["power"][sensor_object] = {}
                except KeyError:
                    environment_data["power"] = {}
                    environment_data["power"][sensor_object] = {}

                environment_data["power"][sensor_object]["capacity"] = -1.0
                environment_data["power"][sensor_object]["output"] = -1.0

            if structured_object_data["class"] == "Fans":
                # Create a dict for the 'fans' key
                try:
                    environment_data["fans"][sensor_object] = {}
                except KeyError:
                    environment_data["fans"] = {}
                    environment_data["fans"][sensor_object] = {}

            status = structured_object_data["status"]
            env_class = structured_object_data["class"]
            if status == "OK" and env_class == "Power":
                # If status is Failed, Absent or Testing, set status to False.
                environment_data["power"][sensor_object]["status"] = True

            elif status != "OK" and env_class == "Power":
                environment_data["power"][sensor_object]["status"] = False

            elif status == "OK" and env_class == "Fans":
                # If status is Failed, Absent or Testing, set status to False.
                environment_data["fans"][sensor_object]["status"] = True

            elif status != "OK" and env_class == "Fans":
                environment_data["fans"][sensor_object]["status"] = False

            for temperature_object, temperature_data in temperature_thresholds.items():
                structured_temperature_data = {k: v for k, v in temperature_data}
                if structured_object_data["class"] == "Temp":
                    # Create a dict for the 'temperature' key
                    try:
                        environment_data["temperature"][sensor_object] = {}
                    except KeyError:
                        environment_data["temperature"] = {}
                        environment_data["temperature"][sensor_object] = {}
                    # Check we have a temperature field in this class (See #66)
                    if structured_object_data["temperature"]:
                        environment_data["temperature"][sensor_object][
                            "temperature"
                        ] = float(structured_object_data["temperature"])
                    # Set a default value (False) to the key is_critical and is_alert
                    environment_data["temperature"][sensor_object]["is_alert"] = False
                    environment_data["temperature"][sensor_object][
                        "is_critical"
                    ] = False
                    # Check if the working temperature is equal to or higher than alerting threshold
                    temp = structured_object_data["temperature"]
                    if temp is not None:
                        if structured_temperature_data["red-alarm"] <= temp:
                            environment_data["temperature"][sensor_object][
                                "is_critical"
                            ] = True
                            environment_data["temperature"][sensor_object][
                                "is_alert"
                            ] = True
                        elif structured_temperature_data["yellow-alarm"] <= temp:
                            environment_data["temperature"][sensor_object][
                                "is_alert"
                            ] = True
                    else:
                        environment_data["temperature"][sensor_object][
                            "temperature"
                        ] = 0.0

        # Try to correct Power Supply information
        pem_table = dict()
        try:
            power_supplies.get()
        except RpcError:
            # Not all platforms have support for this
            pass
        else:
            # Format PEM information and correct capacity and output values
            if "power" not in environment_data.keys():
                # Power supplies were not included from the environment table above
                # Need to initialize data
                environment_data["power"] = {}
                for pem in power_supplies.items():
                    pem_name = pem[0].replace("PEM", "Power Supply")
                    environment_data["power"][pem_name] = {}
                    environment_data["power"][pem_name]["output"] = -1.0
                    environment_data["power"][pem_name]["capacity"] = -1.0
                    environment_data["power"][pem_name]["status"] = False
            for pem in power_supplies.items():
                pem_name = pem[0].replace("PEM", "Power Supply")
                pem_table[pem_name] = dict(pem[1])
                if pem_table[pem_name]["capacity"] is not None:
                    environment_data["power"][pem_name]["capacity"] = pem_table[
                        pem_name
                    ]["capacity"]
                if pem_table[pem_name]["output"] is not None:
                    environment_data["power"][pem_name]["output"] = pem_table[pem_name][
                        "output"
                    ]
                environment_data["power"][pem_name]["status"] = pem_table[pem_name][
                    "status"
                ]

        for routing_engine_object, routing_engine_data in routing_engine.items():
            structured_routing_engine_data = {k: v for k, v in routing_engine_data}
            # Create dicts for 'cpu' and 'memory'.
            try:
                environment_data["cpu"][routing_engine_object] = {}
                environment_data["memory"] = {}
            except KeyError:
                environment_data["cpu"] = {}
                environment_data["cpu"][routing_engine_object] = {}
                environment_data["memory"] = {}
            # Calculate the CPU usage by using the CPU idle value.
            environment_data["cpu"][routing_engine_object]["%usage"] = (
                100.0 - structured_routing_engine_data["cpu-idle"]
            )
            try:
                environment_data["memory"]["available_ram"] = int(
                    structured_routing_engine_data["memory-dram-size"]
                )
            except ValueError:
                environment_data["memory"]["available_ram"] = int(
                    "".join(
                        i
                        for i in structured_routing_engine_data["memory-dram-size"]
                        if i.isdigit()
                    )
                )
            # Junos gives us RAM in %, so calculation has to be made.
            # Sadly, bacause of this, results are not 100% accurate to the truth.
            environment_data["memory"]["used_ram"] = int(
                round(
                    environment_data["memory"]["available_ram"]
                    / 100.0
                    * structured_routing_engine_data["memory-buffer-utilization"]
                )
            )

        return environment_data
1127795
def get_env():
    
    env = os.getenv('ENV', os.getenv('env', None))
    if env:
        env = env.lower()
    return env
306124
def get_envs(self, log=True):
        """"""
        if log:
            logger.debug('')
#        return self._call_and_parse(['info', '--json'],
#                                    callback=lambda o, e: o['envs'])
        envs = os.listdir(os.sep.join([self.ROOT_PREFIX, 'envs']))
        envs = [os.sep.join([self.ROOT_PREFIX, 'envs', i]) for i in envs]

        valid_envs = [e for e in envs if os.path.isdir(e) and
                      self.environment_exists(prefix=e)]

        return valid_envs
392301
def get_environ(self):
        """"""
        ssl_environ = {
            'HTTPS': 'on',
            # pyOpenSSL doesn't provide access to any of these AFAICT
            # 'SSL_PROTOCOL': 'SSLv2',
            # SSL_CIPHER    string  The cipher specification name
            # SSL_VERSION_INTERFACE     string  The mod_ssl program version
            # SSL_VERSION_LIBRARY   string  The OpenSSL program version
        }

        if self.certificate:
            # Server certificate attributes
            cert = open(self.certificate, 'rb').read()
            cert = crypto.load_certificate(crypto.FILETYPE_PEM, cert)
            ssl_environ.update({
                'SSL_SERVER_M_VERSION': cert.get_version(),
                'SSL_SERVER_M_SERIAL': cert.get_serial_number(),
                # 'SSL_SERVER_V_START':
                #   Validity of server's certificate (start time),
                # 'SSL_SERVER_V_END':
                #   Validity of server's certificate (end time),
            })

            for prefix, dn in [
                ('I', cert.get_issuer()),
                ('S', cert.get_subject()),
            ]:
                # X509Name objects don't seem to have a way to get the
                # complete DN string. Use str() and slice it instead,
                # because str(dn) == "<X509Name object '/C=US/ST=...'>"
                dnstr = str(dn)[18:-2]

                wsgikey = 'SSL_SERVER_%s_DN' % prefix
                ssl_environ[wsgikey] = dnstr

                # The DN should be of the form: /k1=v1/k2=v2, but we must allow
                # for any value to contain slashes itself (in a URL).
                while dnstr:
                    pos = dnstr.rfind('=')
                    dnstr, value = dnstr[:pos], dnstr[pos + 1:]
                    pos = dnstr.rfind('/')
                    dnstr, key = dnstr[:pos], dnstr[pos + 1:]
                    if key and value:
                        wsgikey = 'SSL_SERVER_%s_DN_%s' % (prefix, key)
                        ssl_environ[wsgikey] = value

        return ssl_environ
646795
def get_env_setting(setting):
    
    try:
        return os.environ[setting]
    except KeyError:
        error_msg = "Set the %s env variable" % setting
        raise ImproperlyConfigured(error_msg)
155757
def env(*vars, **kwargs):
    
    for v in vars:
        value = os.environ.get(v)
        if value:
            return value
    return kwargs.get('default', '')
254633
def find_kernel_specs_for_envs(self):
        """"""
        data = self._get_env_data()
        return {name: data[name][0] for name in data}
955490
def envs(self):
        '''
        
        '''
        load = {'cmd': '_file_envs'}
        return salt.utils.data.decode(self.channel.send(load)) if six.PY2 \
            else self.channel.send(load)
947534
def log_env_info():
    
    logging.info('Collecting environment information...')
    env_info = torch.utils.collect_env.get_pretty_env_info()
    logging.info(f'{env_info}')
1288536
def collect_environment(no_cache: bool = False) -> dict:
    
    global _env
    if _env is None or no_cache:
        _env = collect_environment_without_packages()
        _env["packages"] = collect_loaded_packages()
    return _env
1298667
def execution_environment():
    """"""
    context = {}
    context['conf'] = config()
    if relation_id():
        context['reltype'] = relation_type()
        context['relid'] = relation_id()
        context['rel'] = relation_get()
    context['unit'] = local_unit()
    context['rels'] = relations()
    context['env'] = os.environ
    return context
845024
def get_env(name, default=None):
    """"""
    if name in os.environ:
        return os.environ[name]

    if default is not None:
        return default

    error_msg = "Set the {} env variable".format(name)
    raise ImproperlyConfigured(error_msg)
358552
def get_environ(self, sock):
        """"""
        cipher = sock.cipher()
        ssl_environ = {
            "wsgi.url_scheme": "https",
            "HTTPS": "on",
            'SSL_PROTOCOL': cipher[1],
            'SSL_CIPHER': cipher[0]
##            SSL_VERSION_INTERFACE 	string 	The mod_ssl program version
##            SSL_VERSION_LIBRARY 	string 	The OpenSSL program version
            }
        return ssl_environ
471417
def get_details(app_url=defaults.APP_URL):
    
    url = '%s/environment' % app_url
    response = requests.get(url)

    if response.status_code == 200:
        return response.json()
    else:
        raise JutException('Unable to retrieve environment details from %s, got %s: %s' %
                           (url, response.status_code, response.text))
899625
def getenv(option_name, default=None):
    """"""
    env = "%s_%s" % (NAMESPACE.upper(), option_name.upper())
    return os.environ.get(env, default)
78972
def _get_environ(environ):
    # type: (Dict[str, str]) -> Iterator[Tuple[str, str]]
    
    keys = ["SERVER_NAME", "SERVER_PORT"]
    if _should_send_default_pii():
        # Add all three headers here to make debugging of proxy setup easier.
        keys += ["REMOTE_ADDR", "HTTP_X_FORWARDED_FOR", "HTTP_X_REAL_IP"]

    for key in keys:
        if key in environ:
            yield key, environ[key]
142897
def get_api_envs():
    """"""
    client_id = os.environ.get('CLIENT_ID')
    user_id = os.environ.get('USER_ID')
    if not client_id or not user_id:
        raise ValueError('API keys are not found in the environment')
    return client_id, user_id