def __init__(self):
     self.ROOT_URL = config.get(section, "SEC_CTRL_HOST")
     self.CLIENT_CERT = config.get(section, "CLIENT_CERT")
     self.NETCONF_PATH = config.get(section, "NETCONF_PATH")
     self.NETCONF_HOST = config.get(section, "NETCONF_HOST")
     # self.CLIENT_KEY = config.get(section, "CLIENT_KEY")
     # self.CERT_SERVER = config.get(section, "CERT_SERVER")
     # self.PAY_LOAD = {"somId": "myID"}
     # self.CERT = (self.CLIENT_CERT, self.CLIENT_KEY)
     self.CERT = (self.CLIENT_CERT)
     self.HEADERS = {'Accept': '*/*', "Content-Type": "application/json"}
     self.MAX_RETRIES = 5
예제 #2
0
 def get_version():
     """
     버전 확인
     :return:
     """
     body = {"jsonrpc": "2.0", "method": "apiinfo.version", "id": 1, "params": []}
     response = CustomHTTPClient.post_method(config.get(section, "ZABBIX_URL") + "/zabbix/api_jsonrpc.php",
                                             {"Content-Type": "application/json-rpc"}, body)
     return response["result"]
예제 #3
0
 def get_auth(user, password):
     """
     로그인
     :param user:
     :param password:
     :return:
     """
     body = {"jsonrpc": "2.0", "method": "user.login", "params": {"user": user, "password": password}, "id": 1}
     response = CustomHTTPClient.post_method(config.get(section, "ZABBIX_URL") + "/zabbix/api_jsonrpc.php",
                                             {"Content-Type": "application/json-rpc"}, body)
     result = json.loads(response.content)
     if result.get("result"):
         return result.get("result")
     else:
         return result.get("error")
예제 #4
0
def get_network_list(request):
    # logger.info("get_network_list")
    token = request.session.get('passToken')
    auth_url = request.session.get("auth_url")
    if request.method == "GET":
        if not token:
            return redirect(
                "/dashboard/domains/?next=/dashboard/admin/networks")
    neutron = NeutronRestAPI(auth_url, token)
    query = {}
    if request.method == "GET" and request.GET.get("project_id"):
        query["tenant_id"] = request.GET.get("project_id")
    elif request.method == "POST" and request.POST.get("project_id"):
        query["tenant_id"] = request.POST.get("project_id")
    result = neutron.get_network_list(q=query)

    if result.get("success"):
        keystone = KeystoneRestAPI(auth_url, token)
        projects = keystone.get_project_list(fields={"fields": ["id", "name"]})
        subnets = neutron.get_subnet_list(fields=["id", "name", "cidr"])
        for network in result["success"].get("networks"):
            # project id로 project_name 추가
            if projects.get("success"):
                for project in projects["success"].get("projects"):
                    if project.get("id") == network.get("tenant_id"):
                        network["project_name"] = project.get("name")
            # project id로 project_name 추가끝
            # subnet id로 subnetList 추가
            if subnets.get("success"):
                network["subnets"] = [
                    subnet for subnet_id in network.get("subnets")
                    for subnet in subnets["success"].get("subnets")
                    if subnet.get("id") == subnet_id
                ]
            # subnet id로 subnetList 추가끝
        result = result.get("success")
    if request.is_ajax():
        return JsonResponse(result)
    else:
        if request.method == "GET":
            try:
                soam_sync = bool(
                    config.get("SETTINGS", "PORTAL_SYNC") == "True")
            except Exception as e:
                soam_sync = False
            result["sync"] = soam_sync  # TODO: soam sync delete
            return render(request, 'admin/networks/index.html', result)
예제 #5
0
 def __init__(self, header=None, token=None, project_id=None, project_name=None, user_id=None, user_name=None,
              roles=None, content_type="application/json", auth_url=None):
     self.CTRL_URL = config.get("SETTINGS", "ctrl_url")
     if header:
         if not header.get("Content-Type"):
             header["Content-Type"] = content_type
         self.HEADER = header
     else:
         self.HEADER = {
             "X-Auth-Token": token,
             "X-Tenant-Id": project_id,
             "X-Tenant-Name": project_name,
             "X-User-Id": user_id,
             "X-User-Name": user_name,
             "Content-Type": content_type
         }
         if roles:
             self.HEADER["X-Roles"] = roles
         if auth_url:
             self.HEADER["X-Host-Uri"] = auth_url
예제 #6
0
def new_service(request):
    """
    서비스 생성 페이지
    :param request:
    :return:
    """
    if request.is_ajax() and request.method == 'POST':
        logger.info("newServicePOST")
        token = request.session.get("passToken")
        auth_url = request.session.get("auth_url")

        logger.info("newServicePOST_end_getpublic_network")
        neutron = NeutronRestAPI(auth_url, token)
        result = neutron.get_network_list()
        if result.get("success"):
            public_network = filter(lambda network: network["router:external"],
                                    result["success"]["networks"])
            return JsonResponse({
                'success': {
                    "service_detail": {}
                },
                "public_network": public_network
            })
        else:
            return JsonResponse(result)

    else:
        logger.info("newService_end")
        token = request.session.get('passToken')
        if not token:
            return redirect(
                "/dashboard/domains/?next=/dashboard/service/new_service")
        try:
            soam_sync = bool(config.get("SETTINGS", "PORTAL_SYNC") == "True")
        except Exception as e:
            soam_sync = False
        return render(request, 'service/info.html',
                      {"sync": soam_sync})  # TODO: soam sync delete
예제 #7
0
def get_volume_list(request):
    # logger.info("get_volume_list")
    token = request.session.get('passToken')
    auth_url = request.session.get("auth_url")
    cinder = CinderRestAPI(auth_url, token)
    keystone = KeystoneRestAPI(auth_url, token)
    result_volume_list = cinder.get_volume_detail_list()
    if result_volume_list.get("success"):
        volume_list = result_volume_list["success"].get("volumes")
        for volume in volume_list:
            result_project = keystone.get_project(volume.get("os-vol-tenant-attr:tenant_id"))
            if result_project.get("success"):
                project = result_project["success"].get("project")
                volume["project_name"] = project.get("name")
            volume["host"] = volume.get("os-vol-host-attr:host")
    else:
        volume_list = result_volume_list
        volume_list["error"]["message"] = volume_list["error"]["message"].replace("<br /><br />\n \n\n", "")
    # TODO: soam sync delete
    try:
        soam_sync = bool(config.get("SETTINGS", "PORTAL_SYNC") == "True")
    except Exception as e:
        soam_sync = False
    return render(request, 'admin/volumes/index.html', {'volume_list': volume_list, "sync": soam_sync})
예제 #8
0
# _*_ coding:utf-8 _*_
import requests
import logging
import pprint

from sdsec.settings import config
from sdsecgui.tools.keystone_exception import Unauthorized

logger = logging.getLogger("myapp.myLogger")
section = "SETTINGS"
LOG_LEVEL = config.get(section, "LOG_LEVEL")


class CustomHTTPClient:
    @staticmethod
    def get_method(url, headers=None, body=None):
        return requests.get(url, headers=headers, json=body)

    @staticmethod
    def post_method(url, headers=None, body=None, verify=None, cert=None):
        return requests.post(url,
                             headers=headers,
                             json=body,
                             verify=verify,
                             cert=cert)

    @staticmethod
    def delete_method(url, headers=None, body=None):
        return requests.delete(url, headers=headers, json=body)

    @staticmethod
예제 #9
0
 def __init__(self, auth):
     self.ID = config.get(section, "ZABBIX_ID")
     self.PASSWORD = config.get(section, "ZABBIX_PASS")
     self.URL = config.get(section, "ZABBIX_URL")
     self.request_no = 1
     self.AUTH = auth
예제 #10
0
def get_instance_list(request):
    token = request.session.get('passToken')
    auth_url = request.session.get("auth_url")
    nova = NovaRestAPI(auth_url, token)
    glance = GlanceRestAPI(auth_url, token)
    keystone = KeystoneRestAPI(auth_url, token)
    power_state_list = ["NoState", "Running", "", "Paused", "Shutdown", "", "Crashed", "Suspended"]
    result_instance_list = nova.get_server_detail_list({"all_tenants": 1})
    instance_list = result_instance_list.get("success").get("servers")

    result_flavors = nova.get_flavor_detail_list()
    flavors = []
    if result_flavors.get("success"):
        flavors = result_flavors["success"].get("flavors")

    result_images = glance.get_image_list()
    images = []
    if result_images.get("success"):
        images = result_images["success"].get("images")

    result_projects = keystone.get_project_list()
    projects = []
    if result_projects.get("success"):
        projects = result_projects["success"].get("projects")

    for instance in instance_list:
        if instance.get("flavor"):
            for flavor in flavors:
                if flavor.get("id") == instance["flavor"].get("id"):
                    instance["flavor"]["name"] = flavor.get("name")
                    instance["flavor"]["id"] = flavor.get("id")
                    instance["flavor"]["vcpus"] = flavor.get("vcpus")
                    instance["flavor"]["ram"] = flavor.get("ram")
                    instance["flavor"]["disk"] = flavor.get("disk")

        if instance.get("image"):
            for image in images:
                if image.get("id") == instance["image"].get("id"):
                    instance["image"] = image

        if instance.get("tenant_id"):
            for project in projects:
                if project.get("id") == instance.get("tenant_id"):
                    instance["project_name"] = project.get("name")

        instance["host_name"] = instance.get("OS-EXT-SRV-ATTR:host")
        instance["task_state"] = instance.get("OS-EXT-STS:task_state")
        instance["power_state"] = power_state_list[instance.get("OS-EXT-STS:power_state")]
        instance["networks"] = {}
        for key in instance.get("addresses").keys():
            instance["networks"][key] = []
            for address in instance.get("addresses").get(key):
                instance["networks"][key].append(address["addr"])

    if request.method == 'POST':
        result = {"success": {'instanceList': instance_list}}
    else:
        result = {"success": {'instanceList': instance_list}}
    if request.method == 'POST':
        return JsonResponse(result)
    else:
        try:
            soam_sync = bool(config.get("SETTINGS", "PORTAL_SYNC") == "True")
        except Exception as e:
            soam_sync = False
        result["sync"] = soam_sync  # TODO: soam sync delete
        return render(request, 'admin/instances/index.html', result)
예제 #11
0
 def __init__(self):
     DBConnector.__init__(self)
     self.DB_NM = config.get(section, 'PORTAL_DB_NM')
     self.DB_USER = config.get(section, 'PORTAL_DB_USER')
     self.DB_PASS = config.get(section, 'PORTAL_DB_PASS')
     self.DB_IP = config.get(section, 'PORTAL_DB_IP')