예제 #1
0
def main():

    # Get and log the config from the Env variable
    config = json.loads(os.environ["CUSTOM_SCRIPT_CONFIG"])
    INFO(config)

    # Get PC info from the config dict
    pc_info = config.get("tdaas_pc")
    pc_external_ip = pc_info.get("ips")[0][0]
    pc_internal_ip = pc_info.get("ips")[0][1]
    pc_password = pc_info.get("prism_password")

    try:

        # Read in our spec file
        autodc_spec = file_to_dict("specs/pc_autodc.json")
        INFO(f"autodc_spec: {autodc_spec}")

        # Make API call to configure the authconfig
        resp = create_via_v1_post(pc_external_ip, "authconfig/directories",
                                  pc_password, autodc_spec)

        # Log appropriately based on response
        if resp.code == 200 or resp.code == 202:
            INFO("Authconfig configured successfully.")
        else:
            raise Exception(f"Authconfig failed with:\n" + f"Resp: {resp}\n" +
                            f"Error Code: {resp.code}\n" +
                            f"Error Message: {resp.message}")

    except Exception as ex:
        ERROR(traceback.format_exc())
예제 #2
0
def main():

    # Get and log the config from the Env variable
    config = json.loads(os.environ["CUSTOM_SCRIPT_CONFIG"])
    print(config)

    # Get PC info from the config dict
    pc_info = config.get("tdaas_pc")
    pc_external_ip = pc_info.get("ips")[0][0]
    pc_internal_ip = pc_info.get("ips")[0][1]
    pc_password = pc_info.get("prism_password")

    try:

        # Read in our public key and create our payload
        public_key = file_to_string("/root/.ssh/id_rsa.pub")
        print(f"public_key: {public_key}")
        payload = {"name": "plugin-runner", "key": public_key}

        # Make API call to configure the authconfig
        resp = create_via_v1_post(
            pc_external_ip,
            "cluster/public_keys",
            pc_password,
            payload,
        )

        # Log appropriately based on response
        if resp.code == 200 or resp.code == 202:
            print("SSH Key added to PC successfully.")
        else:
            raise Exception(f"SSH Key failed to add to PC with:\n" +
                            f"Resp: {resp}\n" + f"Error Code: {resp.code}\n" +
                            f"Error Message: {resp.message}")

    except Exception as ex:
        print(traceback.format_exc())
        sys.exit(1)
예제 #3
0
def main():

    # Get and log the config from the Env variable
    config = json.loads(os.environ["CUSTOM_SCRIPT_CONFIG"])
    print(config)

    # Get PE info from the config dict
    pe_info = config.get("tdaas_cluster")
    pe_external_ip = pe_info.get("ips")[0][0]
    pe_internal_ip = pe_info.get("ips")[0][1]
    pe_password = pe_info.get("prism_password")

    try:

        # Read in our spec file
        ntp_spec = file_to_dict("specs/ntp.json")
        print(f"ntp_spec: {ntp_spec}")

        # Make API call to configure the authconfig
        resp = create_via_v1_post(
            pe_external_ip,
            "cluster/ntp_servers/add_list",
            pe_password,
            ntp_spec["entities"],
        )

        # Log appropriately based on response
        if resp.code == 200 or resp.code == 202:
            print("PE NTP configured successfully.")
        else:
            raise Exception(f"PE NTP config failed with:\n" +
                            f"Resp: {resp}\n" + f"Error Code: {resp.code}\n" +
                            f"Error Message: {resp.message}")

    except Exception as ex:
        print(traceback.format_exc())
        sys.exit(1)
예제 #4
0
def main():

    # Get and log the config from the Env variable
    config = json.loads(os.environ["CUSTOM_SCRIPT_CONFIG"])
    print(config)

    # Get PE info from the config dict
    pe_info = config.get("tdaas_cluster")
    pe_external_ip = pe_info.get("ips")[0][0]
    pe_internal_ip = pe_info.get("ips")[0][1]
    pe_password = pe_info.get("prism_password")

    try:

        # Read in our spec file
        user_spec = file_to_dict("specs/pe_users.json")
        print(f"user_spec: {user_spec}")

        # Loop through our users
        for user in user_spec["entities"]:

            # Make API call to configure the authconfig
            resp = create_via_v1_post(
                pe_external_ip,
                "users",
                pe_password,
                user,
            )

            # If the add was successful, update the user
            if resp.code == 200 or resp.code == 202:
                print(
                    f"PE user {user['profile']['username']} added successfully."
                )

                # Now make the user a non-viewer
                resp = update_via_v1_put(
                    pe_external_ip,
                    "users",
                    pe_password,
                    "karbon//roles",
                    user["roles"],
                )

                # Log appropriately based on response
                if resp.code == 200 or resp.code == 202:
                    print(
                        f"PE user {user['profile']['username']} updated successfully."
                    )
                else:
                    raise Exception(
                        f"PE user {user['profile']['username']} update failed with:\n"
                        + f"Resp: {resp}\n" + f"Error Code: {resp.code}\n" +
                        f"Error Message: {resp.message}")
            else:
                raise Exception(
                    f"PE user {user['profile']['username']} add failed with:\n"
                    + f"Resp: {resp}\n" + f"Error Code: {resp.code}\n" +
                    f"Error Message: {resp.message}")

    except Exception as ex:
        print(traceback.format_exc())
        sys.exit(1)