# Path: stack_configs/influx_functions.py
# def getInfluxConnection():
#     
#     config=settings.INFLUXDB
#     
#     logger.info('Connecting to influx %s', config['host'])
#     
#     try:
#         myClient = InfluxDBClient(host=config['host'],port=config['port'],username=config['user'],password=config['password'],ssl=config['use_ssl'],verify_ssl=config['verify_certs'])
#     except Exception as e: 
#         logger.critical('couldnt connect to influx %s,', e)
#                            
#         return str(e)
#     return myClient  


from django.contrib.auth.models import User
from django.conf import settings
from .influx_functions import getInfluxConnection
    from requests import Request, Session
import logging
import email
import json
import random
import string
        data={}
        apiurl="/api/user/using/"+str(self.orgId)
        result=getFromGrafanaApi(apiurl,data,'POST')
        if not(result.status_code==200):
            logger.warning('unable to change user to organization %s',self.orgId)
            return False 
        
        #check to see if datasource exists once we have changed active organization
        logger.debug('Adding datasource.  Checking if datasource already exists for %s,',self.username)
        if self.datasource_exists():
            logger.debug('datasource already exists %s,',self.username)
            return True
        
               
        
        #add datasource to organization
        DBname= "dab"+str(self.username)
        DBusername="gu"+str(self.username)
        DBpassword=id_generator(size=20)
        
        if (settings.INFLUXDB['use_ssl']):
            Urlprotocol="https://"
        else:
            Urlprotocol="http://"
            
        
        Urlstring= Urlprotocol+settings.INFLUXDB['host']+":"+str(settings.INFLUXDB['port'])
        
        #createInfluxReadOnlyUser for database
        logger.debug('trying to create influx user for datasource %s',DBusername)

# Path: stack_configs/influx_functions.py
# def getInfluxConnection():
#     
#     config=settings.INFLUXDB
#     
#     logger.info('Connecting to influx %s', config['host'])
#     
#     try:
#         myClient = InfluxDBClient(host=config['host'],port=config['port'],username=config['user'],password=config['password'],ssl=config['use_ssl'],verify_ssl=config['verify_certs'])
#     except Exception as e: 
#         logger.critical('couldnt connect to influx %s,', e)
#                            
#         return str(e)
#     return myClient  


# Path: stack_configs/grafana_functions.py
from django.contrib.auth.models import User
from django.conf import settings
from .influx_functions import getInfluxConnection
    from requests import Request, Session
import logging
import email
import json
import random
import string

        data={}
        apiurl="/api/user/using/"+str(self.orgId)
        result=getFromGrafanaApi(apiurl,data,'POST')
        if not(result.status_code==200):
            logger.warning('unable to change user to organization %s',self.orgId)
            return False 
        
        #check to see if datasource exists once we have changed active organization
        logger.debug('Adding datasource.  Checking if datasource already exists for %s,',self.username)
        if self.datasource_exists():
            logger.debug('datasource already exists %s,',self.username)
            return True
        
               
        
        #add datasource to organization
        DBname= "dab"+str(self.username)
        DBusername="gu"+str(self.username)
        DBpassword=id_generator(size=20)
        
        if (settings.INFLUXDB['use_ssl']):
            Urlprotocol="https://"
        else:
            Urlprotocol="http://"
            
        
        Urlstring= Urlprotocol+settings.INFLUXDB['host']+":"+str(settings.INFLUXDB['port'])
        
        #createInfluxReadOnlyUser for database
        logger.debug('trying to create influx user for datasource %s',DBusername)

        client=getInfluxConnection()