Esempio n. 1
0
def get_alarms():
    """ get all alarms """
    alarm_list = []
    try:
        with openstack.OpenStack() as client:
            alarm_list = client.sysinv.ialarm.list()
    except Exception as e:
        LOG.exception("failed to get alarms")
        raise e
    return alarm_list
Esempio n. 2
0
def get_oam_ip():
    """ get OAM ip details """
    try:
        with openstack.OpenStack() as client:
            oam_list = client.sysinv.iextoam.list()
            if oam_list:
                return oam_list[0]
    except Exception as e:
        LOG.exception("failed to get OAM IP")
        raise e
    return None
Esempio n. 3
0
def get_host_data(hostname):
    """ get data for the specified host """
    try:
        with openstack.OpenStack() as client:
            hosts = get_hosts(client.admin_token, client.conf['region_name'])
            for host in hosts:
                if hostname == host.name:
                    return host
    except Exception as e:
        LOG.exception("failed to get host data")
        raise e
    return None
Esempio n. 4
0
def get_config_status(hostname):
    """ get config status of the host """
    try:
        with openstack.OpenStack() as client:
            hosts = get_hosts(client.admin_token, client.conf['region_name'])
            for host in hosts:
                if hostname == host.name:
                    return host.config_status
    except Exception as e:
        LOG.exception("failed to get config status")
        raise e
    return None
Esempio n. 5
0
def get_system_uuid():
    """ get system uuid """
    try:
        sysuuid = ""
        with openstack.OpenStack() as client:
            systems = client.sysinv.isystem.list()
            if systems:
                sysuuid = systems[0].uuid
    except Exception as e:
        LOG.exception("failed to get system uuid")
        raise e
    return sysuuid
Esempio n. 6
0
def get_shared_services():
    try:
        services = ""
        with openstack.OpenStack() as client:
            systems = client.sysinv.isystem.list()
            if systems:
                services = systems[0].capabilities.get("shared_services", "")
    except Exception as e:
        LOG.exception("failed to get shared services")
        raise e

    return services
Esempio n. 7
0
def get_mac_addresses(hostname):
    """ get MAC addresses for the host """
    macs = {}
    try:
        with openstack.OpenStack() as client:
            hosts = get_hosts(client.admin_token, client.conf['region_name'])
            for host in hosts:
                if hostname == host.name:
                    port_list = client.sysinv.ethernet_port.list(host.uuid)
                    macs = {port.name: port.mac for port in port_list}
    except Exception as e:
        LOG.exception("failed to get MAC addresses")
        raise e
    return macs
Esempio n. 8
0
def controller_enabled_provisioned(hostname):
    """ check if host is enabled """
    try:
        with openstack.OpenStack() as client:
            hosts = get_hosts(client.admin_token, client.conf['region_name'])
            for host in hosts:
                if (hostname == host.name
                        and host.is_controller_enabled_provisioned()):
                    LOG.info("host %s is enabled/provisioned" % host.name)
                    return True
    except Exception as e:
        LOG.exception("failed to check if host is enabled/provisioned")
        raise e
    return False
Esempio n. 9
0
def get_storage_backend_services():
    """ get all storage backends and their assigned services """
    backend_service_dict = {}
    try:
        with openstack.OpenStack() as client:
            backend_list = client.sysinv.storage_backend.list()
            for backend in backend_list:
                backend_service_dict.update(
                    {backend.backend: backend.services})

    except Exception as e:
        LOG.exception("failed to get storage backend services")
        raise e

    return backend_service_dict
Esempio n. 10
0
def do_worker_config_complete(hostname):
    """ enable worker functionality """
    try:
        with openstack.OpenStack() as client:
            hosts = get_hosts(client.admin_token, client.conf['region_name'])
            for host in hosts:
                if hostname == host.name:
                    # Create/apply worker manifests
                    values = {'action': "subfunction_config"}
                    patch = dict_to_patch(values)
                    LOG.info("Applying worker manifests: {} [{}]".format(
                        host, patch))
                    client.sysinv.ihost.update(host.uuid, patch)
    except Exception as e:
        LOG.exception("worker_config_complete failed")
        raise e
Esempio n. 11
0
def get_disk_serial_ids(hostname):
    """ get disk serial ids for the host """
    disk_serial_ids = {}
    try:
        with openstack.OpenStack() as client:
            hosts = get_hosts(client.admin_token, client.conf['region_name'])
            for host in hosts:
                if hostname == host.name:
                    disk_list = client.sysinv.idisk.list(host.uuid)
                    disk_serial_ids = {
                        disk.device_node: disk.serial_id
                        for disk in disk_list
                    }
    except Exception as e:
        LOG.exception("failed to get disks")
        raise e
    return disk_serial_ids
Esempio n. 12
0
def update_clone_system(descr, hostname):
    """ update system parameters on clone installation """
    try:
        with openstack.OpenStack() as client:
            systems = client.sysinv.isystem.list()
            if not systems:
                return False
            values = {'name': "Cloned_system", 'description': descr}
            patch = dict_to_patch(values)
            LOG.info("Updating system: {} [{}]".format(systems[0].name, patch))
            client.sysinv.isystem.update(systems[0].uuid, patch)

            hosts = get_hosts(client.admin_token, client.conf['region_name'])
            for host in hosts:
                if hostname == host.name:
                    values = {'location': {}, 'serialid': ""}
                    patch = dict_to_patch(values)
                    client.sysinv.ihost.update(host.uuid, patch)
                    LOG.info("Updating host: {} [{}]".format(host, patch))
    except Exception as e:
        LOG.exception("failed to update system parameters")
        raise e
    return True
Esempio n. 13
0
def DiscoveryMain(Framework):
    OSHVResult = ObjectStateHolderVector()

    endpoint = Framework.getDestinationAttribute('endpoint')
    ip = Framework.getDestinationAttribute('ip')
    protocols = Framework.getAvailableProtocols(ip, "http")

    if len(protocols) == 0:
        msg = 'Protocol not defined or IP out of protocol network range'
        logger.reportWarning(msg)
        logger.error(msg)
        return OSHVResult

    novaApi = None
    cinderApi = None
    glanceApi = None
    neutronApi = None

    zoneOshDict = {}
    serverOshDict = {}
    networkOshDict = {}

    for protocol in protocols:
        try:
            username = Framework.getProtocolProperty(
                protocol, CollectorsConstants.PROTOCOL_ATTRIBUTE_USERNAME)
            credential = Framework.getProtocolProperty(
                protocol, CollectorsConstants.PROTOCOL_ATTRIBUTE_PASSWORD)

            keystoneApi = buildApi('openstack-keystone', endpoint, username,
                                   credential, KeystoneApi)
            logger.debug('keystoneApi:', keystoneApi)

            tenant_discover = openstack_discoverer.TenantDiscoverer(
                keystoneApi)
            tenants = tenant_discover.discover()
            if tenants:
                openstack_software = openstack.OpenStack(ip)
                openstack_osh, openstack_vector = openstack_software.report()
                OSHVResult.addAll(openstack_vector)
            else:
                continue

            for tenant in tenants:
                try:
                    logger.debug("connecting to tenant:", tenant.name)
                    tenant_osh = tenant.report()
                    OSHVResult.add(tenant_osh)
                    OSHVResult.add(
                        modeling.createLinkOSH("composition", openstack_osh,
                                               tenant_osh))

                    identity = tenant.name + ":" + username

                    novaApi = buildApi('openstack-nova', endpoint, identity,
                                       credential, NovaApi)
                    cinderApi = buildApi('openstack-cinder', endpoint,
                                         identity, credential, CinderApi)
                    glanceApi = buildApi('openstack-glance', endpoint,
                                         identity, credential, GlanceApi)
                    neutronApi = buildApi('openstack-neutron', endpoint,
                                          identity, credential, NeutronApi)

                    regions = novaApi.getConfiguredRegions()
                    if regions:
                        tenant_osh.setStringAttribute('credentials_id',
                                                      protocol)

                    for tmp_region in regions:
                        logger.debug("region:", tmp_region)
                        region = openstack.Region(tmp_region)
                        region_osh = region.report(tenant_osh)
                        OSHVResult.add(region_osh)

                        OSHVResult.addAll(
                            getZones(novaApi, region.name, region_osh,
                                     zoneOshDict))
                        logger.debug("zoneOshDict:", zoneOshDict)

                        OSHVResult.addAll(
                            getImages(glanceApi, region.name, region_osh))
                        OSHVResult.addAll(
                            getHypervisors(novaApi, region.name, region_osh))
                        OSHVResult.addAll(
                            getVms(novaApi, region.name, region_osh,
                                   serverOshDict))

                        OSHVResult.addAll(
                            getVolumes(cinderApi, region.name, region_osh,
                                       zoneOshDict, serverOshDict))
                        logger.debug("serverOshDict:", serverOshDict)

                        OSHVResult.addAll(
                            getNetworks(neutronApi, region.name, region_osh,
                                        networkOshDict, openstack_osh))
                        logger.debug("networkOshDict:", networkOshDict)

                        OSHVResult.addAll(
                            getPorts(neutronApi, region.name, serverOshDict,
                                     networkOshDict))

                        OSHVResult.addAll(
                            getSubnets(neutronApi, region.name, networkOshDict,
                                       openstack_osh))

                        OSHVResult.addAll(
                            getFlavors(novaApi, region.name, region_osh))
                except:
                    strException = str(sys.exc_info()[1])
                    excInfo = logger.prepareJythonStackTrace('')
                    logger.debug(strException)
                    logger.debug(excInfo)
                    pass
        except:
            strException = str(sys.exc_info()[1])
            excInfo = logger.prepareJythonStackTrace('')
            logger.debug(strException)
            logger.debug(excInfo)
            pass
        finally:
            if novaApi:
                Closeables.close(novaApi, True)
            if cinderApi:
                Closeables.close(cinderApi, True)
            if glanceApi:
                Closeables.close(glanceApi, True)
            if neutronApi:
                Closeables.close(neutronApi, True)

    reportError = OSHVResult.size() == 0
    if reportError:
        msg = 'Failed to connect using all protocols'
        logger.reportError(msg)
        logger.error(msg)
    return OSHVResult