본문 바로가기

Language/Python

openstack Openrc File 자동등록 스크립트

#!/bin/env python3
import os

class Openrc :
    def __init__(self):
        pass

    def setenv(self, user, project) :
        path = "파일 PAHT"
        if os.path.isfile(path) :
            cmd = f"grep OS {path}"
            values = subprocess.check_output(cmd.split(),universal_newlines=True).replace('"',"").split('\n')
            os.environ['OS_AUTH_URL'] = values[0].split('=')[1]
            os.environ['OS_PROJECT_ID'] = values[1].split('=')[1]
            os.environ['OS_PROJECT_NAME'] = values[2].split('=')[1]
            os.environ['OS_USER_DOMAIN_NAME'] = values[3].split('=')[1]
            os.environ['OS_PROJECT_DOMAIN_ID'] = values[4].split('=')[1]
            os.environ['OS_USERNAME'] = values[5].split('=')[1]
            os.environ['OS_PASSWORD'] = values[6].split('=')[1]
            os.environ['OS_REGION_NAME'] = values[7].split('=')[1]
            os.environ['OS_INTERFACE'] = values[8].split('=')[1]
            os.environ['OS_IDENTITY_API_VERSION'] = values[9].split('=')[1]
        else :
            print(f"[ERROR] {path} : No such file or directory")

'Language > Python' 카테고리의 다른 글

heat YAML파일로 인스턴스 자동 생성  (0) 2021.05.20
Openstack Instance 자동 생성 스크립트  (0) 2021.05.17