def show_cluster_server_configuration(configuration_to_show):
    cluster_server_table_rows = []

    if configuration_to_show is not None:
        # Check that is not blank and there are entries
        if len(configuration_to_show) > 0:
            table_Heading = [
                'Services', 'Nodes', 'Compute', 'Storage size', 'Storage IOPs',
                'Storage type'
            ]
            for cluster_server_entry in configuration_to_show:
                server_Services = cluster_server_entry['services']
                server_Nodes = cluster_server_entry['size']
                server_Compute = cluster_server_entry['compute']
                server_Storage_Size = cluster_server_entry['storage']['size']
                server_Storage_IOPs = cluster_server_entry['storage']['IOPS']
                server_Storage_Type = cluster_server_entry['storage']['type']

                # Put the completed row in the table
                cluster_server_table_rows.append([
                    server_Services, server_Nodes, server_Compute,
                    server_Storage_Size, server_Storage_IOPs,
                    server_Storage_Type
                ])

            # Display the table, which uses pretty table to make things easier
            print(pretty_table(table_Heading, cluster_server_table_rows))
コード例 #2
0
def main(cmd_line_args):
    cappella_api = CapellaAPI()

    if cmd_line_args.debug:
        capella_logging('debug')
        cappella_api.set_logging_level('DEBUG')
    else:
        capella_logging('info')

    capella_api_response = cappella_api.get_clusters()

    # Check response code , 200 is success
    if capella_api_response.status_code == 200:
        clusters_table_rows = []

        # There could not be any clusters, lets check if that's the case
        if capella_api_response.json()['data'] == {}:
            cluster_entries = None
            print("No clusters found")
        else:
            cluster_entries = capella_api_response.json()['data']['items']

            # Got a list of clusters, just double check that we do have entries

            cluster_table_heading = [
                'Environment', 'Name', 'Cluster ID', 'Cloud ID', 'Project ID'
            ]
            for cluster_entry in cluster_entries:
                cluster_environment = cluster_entry['environment']
                cluster_id = cluster_entry['id']
                cluster_name = cluster_entry['name']
                project_id = cluster_entry['projectId']

                # if the cluster is inVPC, then we will have a cloud ID
                if cluster_environment == 'inVpc':
                    clusterCloudID = cluster_entry['cloudId']
                else:
                    clusterCloudID = 'N/A'

                # Put the completed row in the table
                clusters_table_rows.append([
                    cluster_environment, cluster_name, cluster_id,
                    clusterCloudID, project_id
                ])

            # Display the table, which uses pretty table to make things easier
            print('Capella Clusters ')
            print(pretty_table(cluster_table_heading, clusters_table_rows))

    else:
        print("Failed to get list of clusters ")
        print("Capella API returned " + str(capella_api_response.status_code))
        print("Full error message")
        print(capella_api_response.json()["message"])
コード例 #3
0
def main(cmd_line_args):
    cappella_api = CapellaAPI()

    if cmd_line_args.debug:
        capella_logging('debug')
        cappella_api.set_logging_level('DEBUG')
    else:
        capella_logging('info')

    # Check Capella API status
    if cappella_api.api_status().status_code == 200:
        capella_api_response = cappella_api.get_cluster_buckets(cmd_line_args.ClusterID)

        # Check response code , 200 is success
        if capella_api_response.status_code == 200:
            bucket_table_rows = []
            list_of_buckets = capella_api_response.json()

            # We should have a list of buckets, but just in case, check
            # Then we will build rows to show in a table
            if list_of_buckets is not None:
                # Check to see if we got any buckets back
                if len(list_of_buckets) > 0:
                    for bucket in list_of_buckets:
                        bucket_table_rows.append(bucket.values())

                    print('Buckets')
                    print(pretty_table(list_of_buckets[0].keys(), bucket_table_rows))
                else:
                    print("No buckets found")
            else:
                print("No buckets found")

        else:
            print("Failed to get buckets ")
            print("Capella API returned " + str(capella_api_response.status_code))
            print("Full error message")
            print(capella_api_response.json()["message"])

    else:
        print("Check Capella API is up.")
コード例 #4
0
def main(cmd_line_args):
    cappella_api = CapellaAPI()

    if cmd_line_args.debug:
        capella_logging('debug')
        cappella_api.set_logging_level('DEBUG')
    else:
        capella_logging('info')

    # Check Capella API status
    if cappella_api.api_status().status_code == 200:
        capella_api_response = cappella_api.get_projects()

        # Check response code , 200 is success
        if capella_api_response.status_code == 200:
            project_table_rows = []
            list_of_projects = capella_api_response.json()

            for project in list_of_projects['data']:
                project_table_rows.append([
                    project['name'],
                    maya.parse(project['createdAt']), project['id']
                ])

            # Table heading / rows for the output
            project_table_headings = ['Name', 'Created at', 'ID']

            print('Projects')
            print(pretty_table(project_table_headings, project_table_rows))

        else:
            print("Failed to get projects ")
            print("Capella API returned " +
                  str(capella_api_response.status_code))
            print("Full error message")
            print(capella_api_response.json()["message"])

    else:
        print("Check Capella API is up.")
コード例 #5
0
def main(cmd_line_args):
    cappella_api = CapellaAPI()

    if cmd_line_args.debug:
        capella_logging('debug')
        cappella_api.set_logging_level('DEBUG')
    else:
        capella_logging('info')

    # Check Capella API status
    if cappella_api.api_status().status_code == 200:
        capella_api_response = cappella_api.get_clouds()

        # Check response code , 200 is success
        if capella_api_response.status_code == 200:
            cloud_table_rows = []
            list_of_clouds = capella_api_response.json()

            for cloud in list_of_clouds['data']:
                cloud_table_rows.append(cloud.values())

            # Table heading / rows for the output
            # The JSON keys are always the same across all clouds so we can use the
            # keys from the first entry that we got
            cloud_table_headings = list_of_clouds['data'][0].keys()

            print('Projects')
            print(pretty_table(cloud_table_headings, cloud_table_rows))

        else:
            print("Failed to get clouds ")
            print("Capella API returned " +
                  str(capella_api_response.status_code))
            print("Full error message")
            print(capella_api_response.json()["message"])

    else:
        print("Check Capella API is up.")
コード例 #6
0
def main(cmd_line_args):
    cappella_api = CapellaAPI()

    if cmd_line_args.debug:
        capella_logging('debug')
        cappella_api.set_logging_level('DEBUG')
    else:
        capella_logging('info')

    # Check Capella API status
    if cappella_api.api_status().status_code == 200:
        capella_api_response = cappella_api.get_cluster_allowlist(
            cmd_line_args.ClusterID)
        # Check response code , 200 is success
        if capella_api_response.status_code == 200:
            allowlist_table_header = [
                "cidrBlock", "comment", "createdAt", "duration", "expiresAt",
                "ruleType", "state", "updatedAt"
            ]
            allowlist_table_rows = []
            cluster_allowlist = capella_api_response.json()

            # We should have a list of buckets, but just in case, check
            # Then we will build rows to show in a table
            if cluster_allowlist is not None:
                # Check to see if we got any buckets back
                if len(cluster_allowlist) > 0:
                    for allowlist in cluster_allowlist:
                        # Make the two key:values with time stamps look nicer
                        allowlist['createdAt'] = maya.parse(
                            allowlist['createdAt'])
                        allowlist['updatedAt'] = maya.parse(
                            allowlist['updatedAt'])

                        if allowlist['ruleType'] == "permanent":
                            # These need to go into the right place in the dictionary
                            # or the table is messed up
                            new_allowlist = {}
                            for k in allowlist:
                                new_allowlist[k] = allowlist[k]
                                if k == 'createdAt':
                                    new_allowlist['duration'] = " n/a "
                                    new_allowlist['expiresAt'] = " n/a "
                            allowlist = new_allowlist
                        else:
                            allowlist['expiresAt'] = maya.parse(
                                allowlist['expiresAt'])

                        allowlist_table_rows.append(allowlist.values())

                    print('Allowlist')
                    print(
                        pretty_table(allowlist_table_header,
                                     allowlist_table_rows))
                else:
                    print("Allowlist not found")
            else:
                print("Allowlist not found")

        else:
            print("Failed to get allowlist ")
            print("Capella API returned " +
                  str(capella_api_response.status_code))
            print("Full error message")
            print(capella_api_response.json()["message"])

    else:
        print("Check Capella API is up.")
コード例 #7
0
def main(cmd_line_args):
    cappella_api = CapellaAPI()

    if cmd_line_args.debug:
        capella_logging('debug')
        cappella_api.set_logging_level('DEBUG')
    else:
        capella_logging('info')

    # Check Capella API status
    if cappella_api.api_status().status_code == 200:
        capella_api_response = cappella_api.get_cluster_health(cmd_line_args.ClusterID)

        print("Cluster status: " + capella_api_response.json()["status"] + "\n")
        if capella_api_response.status_code == 200:
            # Show a table with the node information
            table_rows = []
            table_header = ["Node name", "Services", "Status"]

            if "nodeStats" in capella_api_response.json():
                table_entries = capella_api_response.json()["nodeStats"]
            else:
                table_entries = None
                print("Node information not available\n")

            # We should have a list of nodes, but just in case, check
            # Then we will build the table
            if table_entries is not None:
                # Make sure the list is not empty
                if len(table_entries) > 0:
                    cluster_node_count = str(table_entries["totalCount"])
                    for entry in table_entries["serviceStats"]:
                        service_list_as_str = ' '.join(entry["services"])
                        table_rows.append([entry["nodeName"], service_list_as_str, entry["status"]])

                    print('Cluster nodes: ' + cluster_node_count)
                    print(pretty_table(table_header, table_rows))

            # Reset everything, we're going to do another table with the bucket information
            table_rows = []
            table_header = ["Bucket name", "Status"]

            if "bucketStats" in capella_api_response.json():
                table_entries = capella_api_response.json()["bucketStats"]
            else:
                table_entries = None
                print("Bucket information not available\n")

            if table_entries is not None:
                # Make sure the list is not empty
                if len(table_entries) > 0:
                    cluster_bucket_count = str(table_entries["totalCount"])
                    for entry_key in table_entries["healthStats"].keys():
                        table_rows.append([entry_key, table_entries["healthStats"][entry_key]])

                    print('Cluster buckets: ' + cluster_bucket_count)
                    print(pretty_table(table_header, table_rows))

        else:
            print("Failed to get health for cluster ID " + cmd_line_args.ClusterID)
            print("Capella API returned " + str(capella_api_response.status_code))
            print("Full error message")
            print(capella_api_response.json()["message"])

    else:
        print("Check Capella API is up.")
コード例 #8
0
def main(cmd_line_args):
    cappella_api = CapellaAPI()

    if cmd_line_args.debug:
        capella_logging('debug')
        cappella_api.set_logging_level('DEBUG')
    else:
        capella_logging('info')

    capella_api_response = cappella_api.get_cluster_users(
        False, cmd_line_args.ClusterID)

    # Check response code , 200 is success
    if capella_api_response.status_code == 200:
        cluster_user_table_rows = []
        cluster_users = capella_api_response.json()

        # We should have a list of users, but just in case, check
        # Then we will build rows to show in a table
        if cluster_users is not None:
            # Check to see if we got any users back
            if len(cluster_users) > 0:
                ClusterUserTableHeading = ['Name', 'Bucket', 'Access']
                for cluster_user in cluster_users:
                    user_name = cluster_user['username']
                    # We use this to determine if the user has access to more than one bucket
                    # to help with formatting the table
                    first_entry = True
                    for cluster_user_access in cluster_user['access']:
                        bucket_name = cluster_user_access['bucketName']
                        if bucket_name == '*':
                            bucket_name = 'All'
                        # Do they have read & write ?
                        if (len(cluster_user_access['bucketAccess'])) == 2:
                            bucket_access = cluster_user_access['bucketAccess'][0] + ' ' + \
                                            cluster_user_access['bucketAccess'][1]
                        else:
                            bucket_access = cluster_user_access[
                                'bucketAccess'][0]
                        # If it's the first entry, then we include the user name
                        # Otherwise we leave that out so the table looks ok
                        if first_entry:
                            cluster_user_table_rows.append(
                                [user_name, bucket_name, bucket_access])
                            first_entry = False
                        else:
                            cluster_user_table_rows.append(
                                ['', bucket_name, bucket_access])

                # Display the table, which uses pretty table to make things easier
                print('Cluster users')
                print(
                    pretty_table(ClusterUserTableHeading,
                                 cluster_user_table_rows))

            else:
                print("No users found for this cluster")
        else:
            print("No users found for this cluster")
    else:
        print("Failed to get list of users for this cluster ")
        print("Capella API returned " + str(capella_api_response.status_code))
        print("Full error message")
        print(capella_api_response.json()["message"])