def create(contxt, auth_openstack=None, allow_duplicate=False):
    """create app node from a dict"""
    if contxt is None:
        contxt = context.get_admin_context()

    if not auth_openstack:
        raise exception.AppNodeInvalidInfo()

    ref = []
    """validate openstack access info"""
    try:
        token_url_id = _get_token(auth_openstack['os_tenant_name'],
                                  auth_openstack['os_username'],
                                  auth_openstack['os_password'],
                                  auth_openstack['os_auth_url'],
                                  auth_openstack['os_region_name'])
        if token_url_id != None:
            auth_openstack['ssh_status'] = "reachable"
        else:
            auth_openstack['ssh_status'] = "no cinder-volume"
    except:
        LOG.exception(_("Error to access to openstack"))
        auth_openstack['ssh_status'] = "unreachable"

    try:
        ref.append(db.appnodes_create(contxt, auth_openstack, allow_duplicate))
    except db_exc.DBError as e:
        LOG.exception(_("DB Error on creating Appnodes %s" % e))
        raise exception.AppNodeFailure()
    return ref
Example #2
0
def create(contxt, auth_openstack=None, allow_duplicate=False):
    """create app node from a dict"""
    if contxt is None:
        contxt = context.get_admin_context()

    appnode = auth_openstack
    if not appnode:
        raise exception.AppNodeInvalidInfo()

    auth_url = appnode['os_auth_url'].strip("/")
    ssh_user = appnode['ssh_user']
    tenant_name = appnode['os_tenant_name']
    username = appnode['os_username']
    password = appnode['os_password']
    region_name = appnode['os_region_name']

    os_controller_host = auth_url.split(":")[1][2:]
    result, err = utils.execute('check_xtrust_crudini',
                                ssh_user,
                                os_controller_host,
                                run_as_root=True)
    LOG.info("==============result: %s" % result)
    LOG.info("==============err: %s" % err)
    if "command not found" in err:
        raise Exception("Command not found on %s" % os_controller_host)
    if "Permission denied" in err:
        raise Exception(
            "Please check the mutual trust between vsm controller node "
            "and openstack controller node")
    if "No passwd entry" in err:
        raise Exception("Please check the trust user")

    # support keystone v3 ad v2.0
    keystone_version = auth_url.split("/")[-1]
    try:
        if keystone_version == "v3":
            result = _check_v3(tenant_name, username, password, auth_url,
                               region_name)
        elif keystone_version == "v2.0":
            result = _check_v2(tenant_name, username, password, auth_url,
                               region_name)
        else:
            raise Exception("Only support keystone v3 and v2.0 now.")
        if result:
            appnode['ssh_status'] = "reachable"
        else:
            appnode['ssh_status'] = "no cinder-volume"
    except:
        LOG.exception(_("Error to access to openstack"))
        appnode['ssh_status'] = "unreachable"

    ref = []
    try:
        ref.append(db.appnodes_create(contxt, appnode, allow_duplicate))
    except db_exc.DBError as e:
        LOG.exception(_("DB Error on creating Appnodes %s" % e))
        raise exception.AppNodeFailure()
    return ref
def create(contxt, auth_openstack=None, allow_duplicate=False):
    """create app node from a dict"""
    if contxt is None:
        contxt = context.get_admin_context()

    if not auth_openstack:
        raise exception.AppNodeInvalidInfo()

    os_controller_host = auth_openstack['os_auth_url'].split(":")[1][2:]
    result, err = utils.execute(
            'check_xtrust_crudini',
            auth_openstack['ssh_user'],
            os_controller_host,
            run_as_root = True
    )
    LOG.info("==============result: %s" % result)
    LOG.info("==============err: %s" % err)
    if "command not found" in err:
        raise Exception("Command not found on %s" % os_controller_host)
    if "Permission denied" in err:
        raise Exception("Please check the mutual trust between vsm controller node "
                        "and openstack controller node")
    if "No passwd entry" in err:
        raise Exception("Please check the trust user")

    ref = []

    """validate openstack access info"""
    try:
        token_url_id = _get_token(
            auth_openstack['os_tenant_name'],
            auth_openstack['os_username'],
            auth_openstack['os_password'],
            auth_openstack['os_auth_url'],
            auth_openstack['os_region_name']
        )
        if token_url_id != None:
            auth_openstack['ssh_status'] = "reachable"
        else:
            auth_openstack['ssh_status'] = "no cinder-volume"
    except:
        LOG.exception(_("Error to access to openstack"))
        auth_openstack['ssh_status'] = "unreachable"

    try:
        ref.append(db.appnodes_create(contxt, auth_openstack, allow_duplicate))
    except db_exc.DBError as e:
        LOG.exception(_("DB Error on creating Appnodes %s" % e))
        raise exception.AppNodeFailure()
    return ref
Example #4
0
def create(contxt, auth_openstack=None, allow_duplicate=False):
    """create app node from a dict"""
    if contxt is None:
        contxt = context.get_admin_context()

    if not auth_openstack:
        raise exception.AppNodeInvalidInfo()

    os_controller_host = auth_openstack['os_auth_url'].split(":")[1][2:]
    result, err = utils.execute('check_xtrust_crudini',
                                auth_openstack['ssh_user'],
                                os_controller_host,
                                run_as_root=True)
    LOG.info("==============result: %s" % result)
    LOG.info("==============err: %s" % err)
    if "command not found" in err:
        raise Exception("Command not found on %s" % os_controller_host)
    if "Permission denied" in err:
        raise Exception(
            "Please check the mutual trust between vsm controller node "
            "and openstack controller node")
    if "No passwd entry" in err:
        raise Exception("Please check the trust user")

    ref = []
    """validate openstack access info"""
    try:
        token_url_id = _get_token(auth_openstack['os_tenant_name'],
                                  auth_openstack['os_username'],
                                  auth_openstack['os_password'],
                                  auth_openstack['os_auth_url'],
                                  auth_openstack['os_region_name'])
        if token_url_id != None:
            auth_openstack['ssh_status'] = "reachable"
        else:
            auth_openstack['ssh_status'] = "no cinder-volume"
    except:
        LOG.exception(_("Error to access to openstack"))
        auth_openstack['ssh_status'] = "unreachable"

    try:
        ref.append(db.appnodes_create(contxt, auth_openstack, allow_duplicate))
    except db_exc.DBError as e:
        LOG.exception(_("DB Error on creating Appnodes %s" % e))
        raise exception.AppNodeFailure()
    return ref
def create(contxt, ips=None, allow_duplicate=False):
    """create app node from a dict"""
    if contxt is None:
        contxt = context.get_admin_context()

    if not ips:
        raise exception.AppNodeInvalidInfo()
    """validate Ipv4 address"""
    ref = []
    for ip in ips:
        if not utils.is_valid_ipv4(ip):
            msg = _("Invalid Ipv4 address %s for app node." % ip)
            raise exception.InvalidInput(reason=msg)
        else:
            attr = {'ip': ip}
            try:
                ref.append(db.appnodes_create(contxt, attr, allow_duplicate))
            except db_exc.DBError as e:
                LOG.exception(_("DB Error on creating Appnodes %s" % e))
                raise exception.AppNodeFailure()
    return ref
def create(contxt, ips=None, allow_duplicate=False):
    """create app node from a dict"""
    if contxt is None:
        contxt = context.get_admin_context()

    if not ips:
        raise exception.AppNodeInvalidInfo()

    """validate Ipv4 address"""
    ref = []
    for ip in ips:
        if not utils.is_valid_ipv4(ip):
            msg = _("Invalid Ipv4 address %s for app node." % ip)
            raise exception.InvalidInput(reason=msg)
        else:
            attr = {
                'ip': ip
            }
            try:
                ref.append(db.appnodes_create(contxt, attr, allow_duplicate))
            except db_exc.DBError as e:
                LOG.exception(_("DB Error on creating Appnodes %s" % e))
                raise exception.AppNodeFailure()
    return ref
def create(contxt, auth_openstack=None, allow_duplicate=False):
    """create app node from a dict"""
    if contxt is None:
        contxt = context.get_admin_context()

    appnode = auth_openstack
    if not appnode:
        raise exception.AppNodeInvalidInfo()

    auth_url = appnode['os_auth_url'].strip("/")
    ssh_user = appnode['ssh_user']
    tenant_name = appnode['os_tenant_name']
    username = appnode['os_username']
    password = appnode['os_password']
    region_name = appnode['os_region_name']

    os_controller_host = auth_url.split(":")[1][2:]
    result, err = utils.execute(
        'check_xtrust_crudini',
        ssh_user,
        os_controller_host,
        run_as_root = True
    )
    LOG.info("==============result: %s" % result)
    LOG.info("==============err: %s" % err)
    if "command not found" in err:
        raise Exception("Command not found on %s" % os_controller_host)
    if "Permission denied" in err:
        raise Exception("Please check the mutual trust between vsm controller node "
                        "and openstack controller node")
    if "No passwd entry" in err:
        raise Exception("Please check the trust user")

    # support keystone v3 ad v2.0
    keystone_version = auth_url.split("/")[-1]
    try:
        if keystone_version == "v3":
            result = _check_v3(tenant_name,
                               username,
                               password,
                               auth_url,
                               region_name)
        elif keystone_version == "v2.0":
            result = _check_v2(tenant_name,
                               username,
                               password,
                               auth_url,
                               region_name)
        else:
            raise Exception("Only support keystone v3 and v2.0 now.")
        if result:
            appnode['ssh_status'] = "reachable"
        else:
            appnode['ssh_status'] = "no cinder-volume"
    except:
        LOG.exception(_("Error to access to openstack"))
        appnode['ssh_status'] = "unreachable"

    ref = []
    try:
        ref.append(db.appnodes_create(contxt, appnode, allow_duplicate))
    except db_exc.DBError as e:
        LOG.exception(_("DB Error on creating Appnodes %s" % e))
        raise exception.AppNodeFailure()
    return ref
def create(contxt, auth_openstack=None, allow_duplicate=False):
    """create app node from a dict"""
    if contxt is None:
        contxt = context.get_admin_context()

    if not auth_openstack:
        raise exception.AppNodeInvalidInfo()

    novaclient = nc.Client(
        auth_openstack["os_username"],
        auth_openstack["os_password"],
        auth_openstack["os_tenant_name"],
        auth_openstack["os_auth_url"],
        region_name=auth_openstack["os_region_name"],
    )
    nova_services = novaclient.services.list()
    nova_compute_hosts = []
    for nova_service in nova_services:
        if nova_service.binary == "nova-compute":
            nova_compute_hosts.append(nova_service.host)

    cinderclient = cc.Client(
        auth_openstack["os_username"],
        auth_openstack["os_password"],
        auth_openstack["os_tenant_name"],
        auth_openstack["os_auth_url"],
        region_name=auth_openstack["os_region_name"],
    )
    cinder_services = cinderclient.services.list()
    cinder_volume_hosts = []
    for cinder_service in cinder_services:
        if cinder_service.binary == "cinder-volume":
            cinder_volume_hosts.append(cinder_service.host)

    hosts = list(set(nova_compute_hosts + cinder_volume_hosts))
    print hosts

    for host in hosts:
        result, err = utils.execute("check_xtrust_crudini", auth_openstack["xtrust_user"], host, run_as_root=True)
        LOG.info("==============result: %s" % result)
        LOG.info("==============result: %s" % err)
        if "command not found" in err:
            raise Exception("Command not found on %s" % host)
        if "Permission denied" in err:
            raise Exception("Please check the mutual trust between vsm nodes and openstack nodes")

    ref = []

    """validate openstack access info"""
    try:
        token_url_id = _get_token(
            auth_openstack["os_tenant_name"],
            auth_openstack["os_username"],
            auth_openstack["os_password"],
            auth_openstack["os_auth_url"],
            auth_openstack["os_region_name"],
        )
        if token_url_id != None:
            auth_openstack["ssh_status"] = "reachable"
        else:
            auth_openstack["ssh_status"] = "no cinder-volume"
    except:
        LOG.exception(_("Error to access to openstack"))
        auth_openstack["ssh_status"] = "unreachable"

    try:
        ref.append(db.appnodes_create(contxt, auth_openstack, allow_duplicate))
    except db_exc.DBError as e:
        LOG.exception(_("DB Error on creating Appnodes %s" % e))
        raise exception.AppNodeFailure()
    return ref