def deploy_hx_cluster():
    """Deploy HX cluster via the Intersight API."""

    try:
        handle = hyperflex_cluster_profile_api.HyperflexClusterProfileApi(
            api_instance)
        kwargs = dict(filter="Name eq 'sjc07-r13-hx-edge-4'")
        response = handle.hyperflex_cluster_profiles_get(**kwargs)

        response_dict = response.to_dict()
        if response_dict.get('results'):
            # get the 1st results object if a list was returned
            response_dict = response_dict['results'][0]
            if response_dict['config_context']['config_state'] == 'Associated':
                message = 'Your Intersight HyperFlex cluster is already deployed and in the ' + response_dict[
                    'config_context']['config_state'] + ' state'
            else:  # config_state != 'Associated'
                moid = response_dict['moid']
                api_body = dict(Action='Deploy')
                patch_response = handle.hyperflex_cluster_profiles_moid_patch(
                    moid, api_body)
                message = 'Your Intersight HyperFlex cluster is now being deployed, ask me later for the HyperFlex cluster configuration state'

    except Exception as err:
        print(err)
        message = (
            "There was an error connecting to or retrieving information from Cisco Intersight"
        )

    return message
Ejemplo n.º 2
0
def deploy_hx_cluster(cluster_name):
    """Deploy HX cluster via the Intersight API."""

    handle = hyperflex_cluster_profile_api.HyperflexClusterProfileApi(
        api_instance)
    kwargs = dict(filter="Name eq '%s' or \
            Tags/any(t:t/Key eq 'Location' and t/Value eq'%s')" %
                  (cluster_name, cluster_name))
    try:
        response = handle.hyperflex_cluster_profiles_get(**kwargs)
    except Exception as err:
        print(err)
        return 'There was an error connecting to or retrieving information from Cisco Intersight'

    message = ''
    response_dict = response.to_dict()
    if response_dict.get('results'):
        # get the 1st results object if a list was returned
        response_dict = response_dict['results'][0]
        if response_dict['config_context']['config_state'] == 'Associated':
            message = "Your %s cluster is already deployed and in the Associated state" % cluster_name
        else:  # config_state != 'Associated'
            moid = response_dict['moid']
            api_body = dict(Action='Deploy')
            response = handle.hyperflex_cluster_profiles_moid_patch(
                moid, api_body)
            message = "Your %s cluster is now being deployed.  "\
                "Ask Intersight, what is the status of my %s cluster to get current deployment status" % (cluster_name, cluster_name)

    return message
Ejemplo n.º 3
0
def get_datacenter_info():
    """Get information including health state of the specified cluster."""
    handle = hyperflex_cluster_profile_api.HyperflexClusterProfileApi(
        api_instance)
    message = ''
    try:
        response = handle.hyperflex_cluster_profiles_get()
    except Exception as err:
        print(err)
        message = (
            "There was an error connecting to or retrieving information from Cisco Intersight"
        )

    response_dict = response.to_dict()
    if response_dict.get('results'):
        for cluster in response_dict['results']:
            cluster_name = cluster['name']
            message += get_hx_config_state(cluster_name)
    else:
        message = 'Sorry, I could not find any information for your datacenter clusters'

    return message
def get_hx_config_state():
    """Get HX cluster configuration state via the Intersight API."""

    try:
        handle = hyperflex_cluster_profile_api.HyperflexClusterProfileApi(
            api_instance)
        kwargs = dict(filter="Name eq 'sjc07-r13-hx-edge-4'")
        response = handle.hyperflex_cluster_profiles_get(**kwargs)

        response_dict = response.to_dict()
        if response_dict.get('results'):
            # get the 1st results object if a list was returned
            response_dict = response_dict['results'][0]
            message = 'Your Intersight HyperFlex cluster is currently in the ' + response_dict[
                'config_context']['config_state'] + ' state'

    except Exception as err:
        print(err)
        message = (
            "There was an error connecting to or retrieving information from Cisco Intersight"
        )

    return message
Ejemplo n.º 5
0
def get_hx_config_state(cluster_name):
    """
    Get HX cluster configuration state and health via the Intersight API.
    Returns a string with state and health including any alarms present
    """

    handle = hyperflex_cluster_profile_api.HyperflexClusterProfileApi(
        api_instance)
    kwargs = dict(filter="Name eq '%s' or \
            Tags/any(t:t/Key eq 'Location' and t/Value eq'%s')" %
                  (cluster_name, cluster_name))
    try:
        response = handle.hyperflex_cluster_profiles_get(**kwargs)
    except Exception as err:
        print(err)
        return 'There was an error connecting to or retrieving information from Cisco Intersight'

    message = ''
    response_dict = response.to_dict()
    if response_dict.get('results'):
        # get the 1st results object if a list was returned
        response_dict = response_dict['results'][0]
        config_state = response_dict['config_context']['config_state']
        message = "Your %s cluster " % cluster_name
        if config_state == 'Associated':
            message += 'is deployed and '
            message += get_health(cluster_name, print_name=False)
            message += '.  '
        elif config_state == 'Assigned':
            message += 'is ready for deployment.  '
        elif config_state == 'Configuring':
            message += 'is currently being deployed.  '
        else:
            message += 'needs additional configuration before being deployed.  '

    return message