MagnetoDB CLI

MagnetoDB CLI client is dedicated to simplify communication with magnetodb server. It uses keystone v2/v3 for authentication. To provide auth info you need to export environment variables OS_TENANT_NAME, OS_USERNAME, OS_PASSWORD and OS_AUTH_URL or provide them on command call, e.g.:

$ magnetodb --os-auth-url http://127.0.0.1:5000/v3 --os-password pass --os-tenant-name admin --os-username admin <command> <args>

MagnetoDB CLI client provides following commands:

table-create

Creates a new table in MagnetoDB.

Command syntax:

$ magnetodb table-create --request-file <FILE>

<FILE> - path to file that contains json request:

{
    "attribute_definitions": [
        {
            "attribute_name": "string",
            "attribute_type": "string"
        }
    ],
    "key_schema": [
        {
            "attribute_name": "string",
            "key_type": "string"
        }
    ],
    "local_secondary_indexes": [
        {
            "index_name": "string",
            "key_schema": [
                {
                    "attribute_name": "string",
                    "key_type": "string"
                }
            ],
            "projection": {
                "non_key_attributes": [
                    "string"
                ],
                "projection_type": "string"
            }
        }
    ],
    "table_name": "string"
}

Sample:

$ magnetodb table-create --request-file ~/table-create-request.json

~/table-create-request.json contains:

{
    "attribute_definitions": [
        {
            "attribute_name": "ForumName",
            "attribute_type": "S"
        },
        {
            "attribute_name": "Subject",
            "attribute_type": "S"
        },
        {
            "attribute_name": "LastPostDateTime",
            "attribute_type": "S"
        }
    ],
    "table_name": "Thread",
    "key_schema": [
        {
            "attribute_name": "ForumName",
            "key_type": "HASH"
        },
        {
            "attribute_name": "Subject",
            "key_type": "RANGE"
        }
    ],
    "local_secondary_indexes": [
        {
            "index_name": "LastPostIndex",
            "key_schema": [
                {
                    "attribute_name": "ForumName",
                    "key_type": "HASH"
                },
                {
                    "attribute_name": "LastPostDateTime",
                    "key_type": "RANGE"
                }
            ],
            "projection": {
                "projection_type": "KEYS_ONLY"
            }
        }
    ]
}

table-list

Prints a list of tables in tenant.

Command syntax:

$ magnetodb table-list [--limit <max-tables-to-show>] [--start-table-name <table-name>]

–limit - max tables to show in a list –start-table-name - table name, after which tables will be listed

Sample:

$ magnetodb table-list --limit 3 --start-table-name Thread

table-delete

Deletes a table.

Command syntax:

$ magnetodb table-delete <table-name>

Sample:

$ magnetodb table-delete Thread

table-describe

Prints a description of a table.

Command syntax:

$ magnetodb table-describe <table-name>

Sample:

$ magnetodb table-describe Thread

index-list

Prints list of indexes of a given table.

Command syntax:

$ magnetodb index-list <table-name>

Sample:

$ magnetodb index-list Thread

index-show

Describes index of a table.

Command syntax:

$ magnetodb index-show <table-name> <index-name>

Sample:

$ magnetodb index-show Thread LastPostIndex

item-put

Puts item to a given table.

Command syntax:

$ magnetodb item-put <table-name> --request-file <FILE>

<FILE> - path to file that contains json request:

{
    "expected": {
        "string": {
            "exists": "boolean",
            "value": {
                "B": "blob",
                "BS": [
                    "blob"
                ],
                "N": "string",
                "NS": [
                    "string"
                ],
                "S": "string",
                "SS": [
                    "string"
                ]
            }
        }
    },
    "item": {
        "string": {
            "B": "blob",
            "BS": [
                "blob"
            ],
            "N": "string",
            "NS": [
                "string"
            ],
            "S": "string",
            "SS": [
                "string"
            ]
        }
    },
    "time_to_live": "number",
    "return_values": "string"
}

Sample:

$ magnetodb item-put Thread --request-file ~/item-put-request.json

~/item-put-request.json contains:

{
    "item": {
        "LastPostDateTime": {
            "S": "201303190422"
        },
        "Tags": {
            "SS": ["Update", "Multiple items", "HelpMe"]
        },
        "ForumName": {
            "S": "MagnetoDB"
        },
        "Message": {
            "S": "I want to update multiple items."
        },
        "Subject": {
            "S": "How do I update multiple items?"
        },
        "LastPostedBy": {
            "S": "fred@example.com"
        }
    },
    "expected": {
        "ForumName": {
            "exists": false
        },
        "Subject": {
            "exists": false
        }
    },
    "return_values": "ALL_OLD"
}

item-update

Updates item.

Command syntax:

$ magnetodb item-update <table-name> --request-file <FILE>

<FILE> - path to file that contains json request:

{
    "attribute_updates": {
        "string": {
            "action": "string",
            "value": {
                "B": "blob",
                "BS": [
                    "blob"
                ],
                "N": "string",
                "NS": [
                    "string"
                ],
                "S": "string",
                "SS": [
                    "string"
                ]
            }
        }
    },
    "time_to_live": "number",
    "expected": {
        "string": {
            "exists": "boolean",
            "value": {
                "B": "blob",
                "BS": [
                    "blob"
                ],
                "N": "string",
                "NS": [
                    "string"
                ],
                "S": "string",
                "SS": [
                    "string"
                ]
            }
        }
    },
    "key": {
        "string": {
            "B": "blob",
            "BS": [
                "blob"
            ],
            "N": "string",
            "NS": [
                "string"
            ],
            "S": "string",
            "SS": [
                "string"
            ]
        }
    },
    "return_values": "string"
}

Sample:

$ magnetodb item-update Thread --request-file ~/item-update-request.json

~/item-put-request.json contains:

{
    "key": {
        "ForumName": {
            "S": "MagnetoDB"
        },
        "Subject": {
            "S": "How do I delete an item?"
        }
    },
    "attribute_updates": {
        "LastPostedBy": {
            "value": {
                "S": "me@test.com"
            },
            "action": "PUT"
        }
    },
    "expected": {
        "LastPostedBy": {
            "value": {
                "S": "fred@example.com"
            }
        },
         "Replies": {
            "exists": false
        }
   },
    "return_values": "ALL_NEW"
}

item-delete

Deletes item from a given table.

Command syntax:

$ magnetodb item-delete <table-name> --request-file <FILE>

<FILE> - path to file that contains json request:

{
    "key": {
        "string": {
            "B": "blob",
            "BS": [
                "blob"
            ],
            "N": "string",
            "NS": [
                "string"
            ],
            "S": "string",
            "SS": [
                "string"
            ]
        }
    },
    "expected": {
        "string": {
            "exists": "boolean",
            "value": {
                "B": "blob",
                "BS": [
                    "blob"
                ],
                "N": "string",
                "NS": [
                    "string"
                ],
                "S": "string",
                "SS": [
                    "string"
                ]
            }
        }
    },
    "return_values": "string"
}

Sample:

$ magnetodb item-delete Thread --request-file ~/item-delete-request.json

~/item-delete-request.json contains:

{
    "key": {
        "ForumName": {
            "S": "MagnetoDB"
        },
        "Subject": {
            "S": "How do I delete an item?"
        }
    },
    "attribute_updates": {
        "LastPostedBy": {
            "value": {
                "S": "me@test.com"
            },
            "action": "PUT"
        }
    },
    "expected": {
        "LastPostedBy": {
            "value": {
                "S": "fred@example.com"
            }
        },
         "Replies": {
            "exists": false
        }
   },
    "return_values": "ALL_NEW"
}

item-get

Gets item from a given table.

Command syntax:

$ magnetodb item-get <table-name> --request-file <FILE>

<FILE> - path to file that contains json request:

{
    "attributes_to_get": [
        "string"
    ],
    "consistent_read": "boolean",
    "key": {
        "string": {
            "B": "blob",
            "BS": [
                "blob"
            ],
            "N": "string",
            "NS": [
                "string"
            ],
            "S": "string",
            "SS": [
                "string"
            ]
        }
    }
}

Sample:

$ magnetodb item-get Thread --request-file ~/item-get-request.json

~/item-get-request.json contains:

{
    "key": {
        "ForumName": {
            "S": "MagnetoDB"
        },
        "Subject": {
            "S": "How do I update multiple items?"
        }
    },
    "attributes_to_get": ["LastPostDateTime", "Message", "Tags"],
    "consistent_read": true
}

query

Makes query request to a given table.

Command syntax:

$ magnetodb query <table-name> --request-file <FILE>

<FILE> - path to file that contains json request:

{
    "attributes_to_get": [
        "string"
    ],
    "consistent_read": "boolean",
    "exclusive_start_key": {
        "string": {
            "B": "blob",
            "BS": [
                "blob"
            ],
            "N": "string",
            "NS": [
                "string"
            ],
            "S": "string",
            "SS": [
                "string"
            ]
        }
    },
    "index_name": "string",
    "key_conditions": {
        "string": {
            "attribute_value_list": [
                {
                    "B": "blob",
                    "BS": [
                        "blob"
                    ],
                    "N": "string",
                    "NS": [
                        "string"
                    ],
                    "S": "string",
                    "SS": [
                        "string"
                    ]
                }
            ],
            "comparison_operator": "string"
        }
    },
    "limit": "number",
    "scan_index_forward": "boolean",
    "select": "string"
}

Sample:

$ magnetodb query Thread --request-file ~/query-request.json

~/query-request.json contains:

{
    "attributes_to_get": [
        "ForumName", "LastPostDateTime", "Posts"
    ],
    "exclusive_start_key": {
        "ForumName": {
            "S": "Testing OS API"
        },
        "LastPostDayTime": {
            "S": "3/1/14"
        }
    },
    "index_name": "LastPostIndex",
    "limit": 2,
    "consistent_read": true,
    "scan_index_forward": true,
    "key_conditions": {
        "ForumName": {
            "attribute_value_list": [
                {
                    "S": "Testing OS API"
                }
            ],
            "comparison_operator": "EQ"
        },
        "LastPostDateTime": {
            "attribute_value_list": [
                {
                    "S": "3/10/14"
                }
            ],
            "comparison_operator": "GT"
        }
    },
    "select": "SPECIFIC_ATTRIBUTES"
}

scan

Makes scan request to a given table.

Command syntax:

$ magnetodb scan <table-name> --request-file <FILE>

<FILE> - path to file that contains json request:

{
    "attributes_to_get": [
        "string"
    ],
    "exclusive_start_key": {
        "string": {
            "B": "blob",
            "BS": [
                "blob"
            ],
            "N": "string",
            "NS": [
                "string"
            ],
            "S": "string",
            "SS": [
                "string"
            ]
        }
    },
    "limit": "number",
    "scan_filter": {
        "string": {
            "attribute_value_list": [
                {
                    "B": "blob",
                    "BS": [
                        "blob"
                    ],
                    "N": "string",
                    "NS": [
                        "string"
                    ],
                    "S": "string",
                    "SS": [
                        "string"
                    ]
                }
            ],
            "comparison_operator": "string"
        }
    },
    "segment": "number",
    "select": "string",
    "total_segments": "number"
}

Sample:

$ magnetodb scan Thread --request-file ~/scan-request.json

~/scan-request.json contains:

{
    "attributes_to_get": [
        "ForumName", "LastPostDateTime", "Posts"
    ],
    "exclusive_start_key": {
        "ForumName": {
            "S": "Another forum"
        }
    },
    "limit": 2,
    "scan_filter": {
        "LastPostDateTime": {
            "attribute_value_list": [
                {
                    "S": "3/10/14"
                }
            ],
            "comparison_operator": "GT"
        }
    },
    "segment": 0,
    "select": "SPECIFIC_ATTRIBUTES",
    "total_segments": 1
}

batch-write

Makes batch write item request.

Command syntax:

$ magnetodb batch-write --request-file <FILE>

<FILE> - path to file that contains json request:

{
    "request_items": {
        "string": [
            {
                "delete_request": {
                    "key": {
                        "string": {
                            "B": "blob",
                            "BS": [
                                "blob"
                            ],
                            "N": "string",
                            "NS": [
                                "string"
                            ],
                            "S": "string",
                            "SS": [
                                "string"
                            ]
                        }
                    }
                },
                "put_request": {
                    "item": {
                        "string": {
                            "B": "blob",
                            "BS": [
                                "blob"
                            ],
                            "N": "string",
                            "NS": [
                                "string"
                            ],
                            "S": "string",
                            "SS": [
                                "string"
                            ]
                        }
                    },
                    "time_to_live": "number"
                }
            }
        ]
    }
}

Sample:

$ magnetodb batch-write --request-file ~/batch-write-request.json

~/batch-write-request.json contains:

{
    "request_items": {
        "Forum": [
            {
                "put_request": {
                    "item": {
                        "Name": {
                            "S": "MagnetoDB"
                        },
                        "Category": {
                            "S": "OpenStack KVaaS"
                        }
                    }
                }
            },
            {
                "put_request": {
                    "item": {
                        "Name": {
                            "S": "Nova"
                        },
                        "Category": {
                            "S": "OpenStack Core"
                        }
                    }
                }
            },
            {
                "put_request": {
                    "item": {
                        "Name": {
                            "S": "KeyStone"
                        },
                        "Category": {
                            "S": "OpenStack Core"
                        }
                    }
                }
            },
            {
                "delete_request": {
                    "key": {
                        "Name": {
                            "S": "Cinder"
                        },
                        "Category": {
                            "S": "OpenStack Core"
                        }
                    }
                }
            }
        ]
    }
}

batch-get

Makes batch get item request.

Command syntax:

$ magnetodb batch-get --request-file <FILE>

<FILE> - path to file that contains json request:

{
    "request_items": {
        "string": {
            "attributes_to_get": [
                "string"
            ],
            "consistent_read": "boolean",
            "keys": [

                {
                    "string": {
                        "B": "blob",
                        "BS": [
                            "blob"
                        ],
                        "N": "string",
                        "NS": [
                            "string"
                        ],
                        "S": "string",
                        "SS": [
                            "string"
                        ]
                    }
                }
            ]
        }
    }
}

Sample:

$ magnetodb batch-get --request-file ~/batch-get-request.json

~/batch-get-request.json contains:

{
    "request_items": {
        "Forum": {
            "keys": [
                {
                    "Name": {
                        "S": "MagnetoDB"
                    },
                    "Category": {
                        "S": "OpenStack KVaaS"
                    }
                },
                {
                    "Name": {
                        "S": "Nova"
                    },
                    "Category": {
                        "S": "OpenStack Core"
                    }
                }
            ]
        },
        "Thread": {
            "keys": [
                {
                    "Name": {
                        "S": "MagnetoDB"
                    },
                    "Category": {
                        "S": "OpenStack KVaaS"
                    }
                },
                {
                    "Name": {
                        "S": "Nova"
                    },
                    "Category": {
                        "S": "OpenStack Core"
                    }
                }
            ]
        }
    }
}