|
1 |
| -# Astra Shell |
| 1 | +# Getting Started with Astra CLI |
2 | 2 |
|
3 | 3 | [](http://www.apache.org/licenses/LICENSE-2.0)
|
4 | 4 |
|
5 |
| -_This component is in heavy development that can lead to breaking changes._ |
| 5 | +Astra Shell is a standalone command line interface proposing functions to operate the Datastax Astra platform. |
6 | 6 |
|
| 7 | +## A. Installation |
7 | 8 |
|
8 |
| -## Installation |
| 9 | +### Prequisites |
9 | 10 |
|
10 |
| -Installing ASTRA-CLI on UNIX-like platforms is as easy as ever. ASTRA-CLI installs smoothly on macOS, Linux, WSL, Cygwin, Solaris and FreeBSD. We also support Bash and ZSH shells. |
| 11 | +On your machine you will need : |
| 12 | +- A bash shell |
| 13 | +- Commands: `unzip`, `curl` |
| 14 | +- A Java JRE or JDK 8+ (temporary) |
11 | 15 |
|
12 |
| -- Open a new terminal and enter: |
| 16 | +You will also need to: |
| 17 | +- [Create an Astra account](https://astra.datastax.com) |
| 18 | +- [Create an authentication token](https://dtsx.io/create-astra-token) |
13 | 19 |
|
| 20 | +### Installation |
| 21 | + |
| 22 | +``` |
| 23 | +curl -Ls "https://dtsx.io/get-astra-cli" | bash |
| 24 | +``` |
| 25 | + |
| 26 | +### Setup |
| 27 | + |
| 28 | +- 1/3 - Execute the following |
| 29 | +``` |
| 30 | +astra setup |
| 31 | +``` |
| 32 | + |
| 33 | +- 2/3 When asked provides a token of your choice: |
| 34 | + |
| 35 | +``` |
| 36 | +• Enter your token (AstraCS...) : |
| 37 | +AstraCS:....... |
14 | 38 | ```
|
15 |
| -curl -Ls curl -s "https://dtsx.io/get-astra-cli" | bash |
| 39 | + - 3/3 Open a new TAB to finalize install |
| 40 | + |
| 41 | +``` |
| 42 | +astra --version |
| 43 | +astra help |
16 | 44 | ```
|
17 | 45 |
|
18 |
| -- Follow the instructions on-screen to complete installation. |
| 46 | +## B. Working with configurations |
19 | 47 |
|
20 |
| -- To get autocompletion open a new terminal : |
| 48 | +- **List Configurations** |
21 | 49 |
|
22 | 50 | ```
|
23 |
| -source "$HOME/.astra/install/astra-init.sh" |
| 51 | +astra config list |
24 | 52 | ```
|
25 | 53 |
|
26 |
| -- Lastly, run the following code snippet to ensure that installation succeeded: |
| 54 | +- **Create new configuration** |
| 55 | + |
| 56 | +If you have multiple organizations it could be useful to switch from one to another. To create another config, the latest created org will become the default. |
27 | 57 |
|
28 | 58 | ```
|
29 |
| -astra -v |
| 59 | +astra config create dev -t <token_of_org_2> |
30 | 60 | ```
|
31 | 61 |
|
32 |
| -If all went well, the version should be displayed. Something like: |
| 62 | +``` |
| 63 | +astra config list |
| 64 | +``` |
| 65 | + |
| 66 | +When you issue any command the config is now loaded for you: |
33 | 67 |
|
34 | 68 | ```
|
35 |
| -0.3.2-SNAPSHOT |
| 69 | +astra user list |
36 | 70 | ```
|
37 | 71 |
|
38 |
| -## Setup |
| 72 | +- **Change default configuration**: |
39 | 73 |
|
40 |
| -- Run the following command and provide your token when needed |
| 74 | +You can change the default org at any time with the following command: |
41 | 75 |
|
42 | 76 | ```
|
43 |
| -astra setup |
| 77 | +astra config default dev && astra config list |
44 | 78 | ```
|
45 | 79 |
|
46 |
| -- You should be good to go |
| 80 | +- Test again, user list should be different |
47 | 81 |
|
48 | 82 | ```
|
| 83 | +astra user list |
| 84 | +``` |
| 85 | + |
| 86 | +- Back to original org (change with your email) |
| 87 | + |
| 88 | +``` |
| 89 | +astra config default [email protected] && astra config list |
| 90 | +``` |
| 91 | + |
| 92 | +- You can use any organization without switching default configuration with `--config` or `-t` |
| 93 | + |
| 94 | +``` |
| 95 | +astra user list --config dev |
| 96 | +``` |
| 97 | + |
| 98 | +- **Delete configuration** |
| 99 | + |
| 100 | +You can delete any organization. I see you.. if you delete the default one you are on your own and you would need to define a new one. |
| 101 | + |
| 102 | +``` |
| 103 | +astra config delete dev |
49 | 104 | astra config list
|
50 | 105 | ```
|
51 | 106 |
|
| 107 | +## C. Working with Databases |
| 108 | + |
| 109 | +- **List Databases**: |
| 110 | + |
52 | 111 | ```
|
53 |
| -+-----------------------------------------+ |
54 |
| -| configuration | |
55 |
| -+-----------------------------------------+ |
56 |
| - |
57 |
| -| DatastaxDevs | |
58 |
| - |
59 |
| -+-----------------------------------------+ |
| 112 | +astra db list |
60 | 113 | ```
|
61 | 114 |
|
62 |
| -- And access Astra |
| 115 | +- **Create a new database:** |
| 116 | + |
| 117 | +If not provided the region will be the default free region and the keyspace will be the database name but you can change then with `-r` and `-k` respectivitely. |
63 | 118 |
|
64 | 119 | ```
|
| 120 | +astra db create demo |
65 | 121 | astra db list
|
66 | 122 | ```
|
67 | 123 |
|
| 124 | +- **Get information on your database** |
| 125 | + |
| 126 | +Notice how you never provide any the technical ids. |
| 127 | + |
| 128 | +``` |
| 129 | +astra db get demo |
68 | 130 | ```
|
69 |
| -+---------------------+--------------------------------------+---------------------+----------------+ |
70 |
| -| name | id | default-region | status | |
71 |
| -+---------------------+--------------------------------------+---------------------+----------------+ |
72 |
| -| mtg | dde308f5-a8b0-474d-afd6-81e5689e3e25 | eu-central-1 | ACTIVE | |
73 |
| -| workshops | 3ed83de7-d97f-4fb6-bf9f-82e9f7eafa23 | eu-west-1 | ACTIVE | |
74 |
| -| sdk_tests | 06a9675a-ca62-4cd0-9b94-aefaf395922b | us-east-1 | ACTIVE | |
75 |
| -| api_days_dubai_2022 | 53f07b2a-8856-4741-b595-72b03be56bc6 | us-east1 | ACTIVE | |
76 |
| -| free_db | 8642763c-8ba7-4ede-a031-82355c7c34a7 | us-east1 | ACTIVE | |
77 |
| -+---------------------+--------------------------------------+---------------------+----------------+ |
| 131 | + |
| 132 | +- **Change output format** |
| 133 | + |
| 134 | +This CLI wil be used by CI/CD and script, sometimes the output must be parsed. There are 3 outputs: *human,json,csv" |
| 135 | + |
78 | 136 | ```
|
| 137 | +astra db list -o json |
| 138 | +``` |
| 139 | + |
| 140 | +``` |
| 141 | +astra db list -o csv |
| 142 | +``` |
| 143 | + |
| 144 | +The return type is also important to check the errors. O mean everything is OK |
| 145 | + |
| 146 | +``` |
| 147 | +echo $? |
| 148 | +``` |
| 149 | + |
| 150 | +``` |
| 151 | +astra db get i_do_not_exist && echo $? |
| 152 | +``` |
| 153 | + |
| 154 | +Error codes tables |
| 155 | + |
| 156 | +| Error | Code | |
| 157 | +|-------------------|-----------| |
| 158 | +| SUCCESS | 0 | |
| 159 | +| PARSE_ERROR | 1 | |
| 160 | +| INVALID_PARAMETER | 10 | |
| 161 | +| NOT_FOUND | 20 | |
| 162 | +| CONFLICT | 21 | |
| 163 | +| ALREADY_EXIST | 22 | |
| 164 | +| CANNOT_CONNECT | 30 | |
| 165 | +| INTERNAL_ERROR | 40 | |
| 166 | + |
| 167 | + |
| 168 | +- The cli implemented `If not Exist` for both keyspace and database (convenient for workshops and training) |
| 169 | + |
| 170 | +``` |
| 171 | +astra help db create |
| 172 | +astra db create demo --if-not-exist |
| 173 | +``` |
| 174 | + |
| 175 | +- All commands can also be in versbose mode anytime with `-v` |
| 176 | + |
| 177 | +``` |
| 178 | +astra db create demo --if-not-exist -v |
| 179 | +``` |
| 180 | + |
| 181 | +Make sure the database is now Active or you will get some expected errors. |
| 182 | + |
| 183 | +- **Create a new keyspace** |
| 184 | + |
| 185 | +``` |
| 186 | +astra db create-keyspace demo -k ks2 |
| 187 | +``` |
| 188 | + |
| 189 | +Need helps ? |
| 190 | +``` |
| 191 | +astra help db create-keyspace |
| 192 | +``` |
| 193 | + |
| 194 | +- Now let's blow your mind 🥁 |
| 195 | + |
| 196 | +``` |
| 197 | +astra db cqlsh demo |
| 198 | +``` |
| 199 | + |
| 200 | + |
| 201 | +## D. Interactive mode |
| 202 | + |
| 203 | + |
| 204 | +## E. Working with Users |
| 205 | + |
| 206 | + |
| 207 | +## F. Working with Roles |
| 208 | + |
| 209 | + |
79 | 210 |
|
80 | 211 |
|
81 | 212 |
|
|
0 commit comments