def send_email(self): try: sender = os.get_env('SENDER_EMAIL') receiver = os.get_env('RECEIVER_EMAIL') subject = "Test Subject" text = "Test Email Body" message = """\From: %s\nTo: %s\nSubject: %s\n\n%s""" % ( sender, ", ".join(receiver), subject, text) smtp_obj = smtplib.SMTP('smtp.gmail.com', 587) smtp_obj.ehlo() smtp_obj.starttls() except: print >> sys.stderr, ">>>>>>>>>>>>> Sending Email Failed <<<<<<<<<<<<<<<", traceback.format_exc( )
from os import getenv as get_env from dotenv import load_dotenv load_dotenv() TOKEN = get_env('GITHUB_TOKEN') or '' headers = { 'Content-Type': 'application/json', 'Authorization': 'token {}'.format(TOKEN) } GITHUB_API = 'https://api.github.com' orgs = [ '/twitter/repos', '/auth0/repos', '/nasa/repos', 'mozilla/repos', 'adobe/repos' ]
def add_node(manager, env_name, node_name, template_volume): try: environment = manager.environment_get(env_name) except: # Exception as e: pass #print e #exit(1) admin_node = environment.node_by_name('admin') admin_ip = admin_node.get_ip_address_by_network_name('admin') try: tempest_node = manager.node_create(name=node_name, environment=environment, boot=['hd']) except: # Exception as e: pass #print e ## tempest_node = environment.node_by_name(name=node_name) #exit(2) br_net = _safe_get_bridge(manager, environment, os.get_env('HOST_BRIDGE', 'br0')) # TODO: implement create_or_get to host networks #def interface_create(self, network, node, type='network', # mac_address=None, model='virtio'): manager.interface_create(node=tempest_node, network=br_net, type='bridge') job_params = os.getenv('JENKINS_JOB_PARAMS', None) if job_params is not None: job_params = json.load(job_params) cfg = { 'jenkins': { 'url': os.getenv('JENKINS_URL', 'http://osci-jenkins.srt.mirantis.net:8080'), # 'keys': 'JOB_NAME': os.getenv('JENKINS_JOB_NAME', 'tempest-fuel-3.2-auto'), 'JOB_PARAMS': job_params, }, 'environment': { 'name': environment.name, }, 'nailgun': { 'ip_address': admin_ip, }, 'node': { 'name': tempest_node.name, 'networks': [ { 'iface': 'eth0', 'name': br_net.name, 'alias': None, 'ip_network': br_net.ip_network, 'ip': None, }, ] } } # connect to internal network for net in environment.networks: if net.name != br_net.name: try: # env_net = environment.network_by_name('management') manager.interface_create(node=tempest_node, network=net) ip = tempest_node.get_ip_address_by_network_name(net.name) cfg['node']['networks'].append({ 'iface': 'eth' + str(len(cfg['node']['networks'])), 'name': net.name, 'alias': iface_aliases[net.name], 'ip_network': net.ip_network, 'ip': str(ip), }) except: # Exception as e: pass #print e #exit(3) logger.info('NODE_CONFIG: %s' % (json.dumps(cfg))) # create and connect volume vol_tpl = manager.volume_get_predefined(template_volume) vol_base = manager.volume_create_child(node_name + 'test_vol', backing_store=vol_tpl, environment=environment) manager.node_attach_volume(node=tempest_node, volume=vol_base) vol_base.define() # data injection dev = nbd.connect(vol_base.get_path(), read_only=False) mount_path = nbd.mount(dev) shutil.copy2('node_prepare/node_init.sh', os.sep.join((mount_path, 'home/jenkins'))) file_name = 'home/jenkins/node_init' #with open(os.sep.join((mount_path, file_name + '.yaml')), 'w') as f: # yaml.safe_dump(cfg, f) with open(os.sep.join((mount_path, file_name + '.json')), 'w') as f: f.write(json.dumps(cfg, indent=4, separators=(',', ':'))) #with open(os.sep.join((mount_path, 'etc/rc.local')), 'r') as f: # insert_to_file(f, # 'sudo -i -u jenkins /home/jenkins/node_init.sh', # template='exit 0') nbd.disconnect(dev) tempest_node.define() tempest_node.start() exit()
from os import getenv as get_env VERSION = '0.1.0' DEFAULT_ROLES = ['Admin', 'Monitor', 'Operator'] AUTH_HEADER_KEY = 'Authorization' TOKENS = [ 'c1954ae0-9ab9-4c70-a619-cae70e72728c', 'bc98abbc-2034-4043-9baf-6116205745de', '8b642f4c-69b8-4ee0-afc5-6d1e96f45a13' ] LIMIT_PER_PAGE = 5 MIGRATION_FOLDER = 'migrations' TESTING_DB = 'testing.db' FALLBACK_DB = 'database.db' REQUESTS_LIMIT_HOURS = 5 REQUESTS_LIMIT_PER_HOURS = 20 FLASK_ENV = get_env('FLASK_ENV', 'production') PRODUCTION = FLASK_ENV == 'production' TESTING = FLASK_ENV == 'testing' DEVELOPMENT = FLASK_ENV == 'development'
"").replace("/issues", "") repo_splits = repo_name.split('/') repo_name = repo_splits[0] + '/' + repo_splits[1] projects.append(repo_name) projects_meta_data[repo_splits[1]] = { "mentor_name": proj['mentor'], 'title': proj['title'] } # print(projects[0]) # successful in generating the project names # token = open(root_dir + '/secrets/token.txt', 'r').read().split('\n')[0] headers = {'Authorization': 'token ' + os.get_env('GITHUB_TOKEN')} languages_json = json.load(open("languages.json", 'r')) stats = {} """ Structure of stats : key : username (In lowercase) value : dict key : avatar_url value : string key : name value : string
import atexit as at_exit import sentry_sdk from os import getenv as get_env, path, remove from sentry_sdk.integrations.flask import FlaskIntegration from .constants import TESTING_DB, FALLBACK_DB, PRODUCTION, TESTING, DEVELOPMENT basedir = path.abspath(path.dirname(__file__)) configuration = { 'SQLALCHEMY_TRACK_MODIFICATIONS': False, 'SECRET_KEY': get_env('SECRET_KEY'), 'RESTX_VALIDATE': True, 'DEBUG': True } if PRODUCTION: sentry_dsn = get_env('SENTRY_DSN') sentry_dsn and sentry_sdk.init(dsn=sentry_dsn, integrations=[FlaskIntegration()]) configuration.update({ 'SQLALCHEMY_DATABASE_URI': get_env('DATABASE_URI'), 'DEBUG': False }) elif TESTING: configuration.update({ 'SQLALCHEMY_DATABASE_URI': f'sqlite:///{TESTING_DB}', 'TESTING': True }) db_path = path.join(basedir, TESTING_DB) at_exit.register(lambda: path.isfile(db_path) and remove(db_path)) elif DEVELOPMENT:
def add_node(manager, env_name, node_name, template_volume): try: environment = manager.environment_get(env_name) except: # Exception as e: pass #print e #exit(1) admin_node = environment.node_by_name('admin') admin_ip = admin_node.get_ip_address_by_network_name('admin') try: tempest_node = manager.node_create(name=node_name, environment=environment, boot=['hd']) except: # Exception as e: pass #print e ## tempest_node = environment.node_by_name(name=node_name) #exit(2) br_net = _safe_get_bridge(manager, environment, os.get_env('HOST_BRIDGE', 'br0')) # TODO: implement create_or_get to host networks #def interface_create(self, network, node, type='network', # mac_address=None, model='virtio'): manager.interface_create(node=tempest_node, network=br_net, type='bridge') job_params = os.getenv('JENKINS_JOB_PARAMS', None) if job_params is not None: job_params = json.load(job_params) cfg = { 'jenkins': { 'url': os.getenv('JENKINS_URL', 'http://osci-jenkins.srt.mirantis.net:8080'), # 'keys': 'JOB_NAME': os.getenv('JENKINS_JOB_NAME', 'tempest-fuel-3.2-auto'), 'JOB_PARAMS': job_params, }, 'environment': { 'name': environment.name, }, 'nailgun': { 'ip_address': admin_ip, }, 'node': { 'name': tempest_node.name, 'networks': [ { 'iface': 'eth0', 'name': br_net.name, 'alias': None, 'ip_network': br_net.ip_network, 'ip': None, }, ] } } # connect to internal network for net in environment.networks: if net.name != br_net.name: try: # env_net = environment.network_by_name('management') manager.interface_create(node=tempest_node, network=net) ip = tempest_node.get_ip_address_by_network_name(net.name) cfg['node']['networks'].append( { 'iface': 'eth' + str(len(cfg['node']['networks'])), 'name': net.name, 'alias': iface_aliases[net.name], 'ip_network': net.ip_network, 'ip': str(ip), }) except: # Exception as e: pass #print e #exit(3) logger.info('NODE_CONFIG: %s' % (json.dumps(cfg))) # create and connect volume vol_tpl = manager.volume_get_predefined(template_volume) vol_base = manager.volume_create_child(node_name + 'test_vol', backing_store=vol_tpl, environment=environment) manager.node_attach_volume(node=tempest_node, volume=vol_base) vol_base.define() # data injection dev = nbd.connect(vol_base.get_path(), read_only=False) mount_path = nbd.mount(dev) shutil.copy2('node_prepare/node_init.sh', os.sep.join((mount_path, 'home/jenkins'))) file_name = 'home/jenkins/node_init' #with open(os.sep.join((mount_path, file_name + '.yaml')), 'w') as f: # yaml.safe_dump(cfg, f) with open(os.sep.join((mount_path, file_name + '.json')), 'w') as f: f.write(json.dumps(cfg, indent=4, separators=(',', ':'))) #with open(os.sep.join((mount_path, 'etc/rc.local')), 'r') as f: # insert_to_file(f, # 'sudo -i -u jenkins /home/jenkins/node_init.sh', # template='exit 0') nbd.disconnect(dev) tempest_node.define() tempest_node.start() exit()
if int(selection) > 0: print("Bootstrapping new device of type - " + device_type) print("Provide unique device id (or press enter to generate one)") device_id = input() if (len(device_id) == 0): letters = string.ascii_lowercase length = 6 device_id = ''.join(random.choices(string.ascii_uppercase + string.digits, k=length)) print("Registering device with id - " + device_id ) else: print("Registering device with id - " + selection) print("Registering device in Watson IoTP via OSLC APIs") iotp_url = os.get_env('iotp_oslc_url') || "127.0.0.1" iotp_org = os.get_env('iotp_org') endpoint = "/iotp/services/iotp" + iotp_org # See if device type is already registered check_device_type = requests.get( iotp_url + endpoint + "/devicetype/" + devicetype ) if ( check_device_type.status == 200): # if get request is not 200, device type doesn't exist, so create it here create_device_type = requests.post( iotp_url + endpoint + "/devicetype/" + devicetype ) print("Device Type " + devicetype + " created" ) create_device = requests.post( iotp_url + endpoint + "/device/" + device_id ) # requests.post(iotp_url, headers) print("IoTP Device Registered") print("Registering device in Maximo via OSLC APIs")
def get_env(): return os.get_env('ENV', 'development')
self.driver.switch_to.frame(element) self.activateVideo() self.driver.switch_to.default_content() time.sleep(5) for request in driver.requests: if request.response and re.search('index', request.url, re.IGNORECASE): print(request.url, request.response.status_code) time.sleep(60) def activateVideo(self): try: print( self.driver.find_element_by_css_selector( '#copyrightNoticeContainer').get_attribute('style')) WebDriverWait(self.driver, 60).until( EC.invisibility_of_element_located( (By.ID, "copyrightNoticeContainer"))) element = WebDriverWait(self.driver, 120).until( EC.visibility_of_element_located( (By.CSS_SELECTOR, "#player > div.fp-player > div.fp-ui"))) element.click() request = self.driver.wait_for_request('.+/index.m3u8', timeout=60) print(request.url) finally: pass if __name__ == '__main__': x = VideoBroswer(os.get_env('URL'))