github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/python/examples/sdk/sdk-basics.ipynb (about) 1 { 2 "cells": [ 3 { 4 "cell_type": "markdown", 5 "id": "e616503b", 6 "metadata": {}, 7 "source": [ 8 "# General operations for the client and cluster\n" 9 ] 10 }, 11 { 12 "cell_type": "markdown", 13 "metadata": { 14 "collapsed": false 15 }, 16 "source": [ 17 "## Client Options" 18 ] 19 }, 20 { 21 "cell_type": "code", 22 "execution_count": null, 23 "metadata": { 24 "collapsed": false 25 }, 26 "outputs": [], 27 "source": [ 28 "pip install aistore" 29 ] 30 }, 31 { 32 "cell_type": "code", 33 "execution_count": null, 34 "metadata": { 35 "collapsed": false 36 }, 37 "outputs": [], 38 "source": [ 39 "from aistore import Client\n", 40 "\n", 41 "# Use the client class to access the AIS cluster:\n", 42 "ais_url = \"http://localhost:8080\"\n", 43 "client = Client(ais_url)" 44 ] 45 }, 46 { 47 "cell_type": "markdown", 48 "metadata": { 49 "collapsed": false 50 }, 51 "source": [ 52 "### The client provides access to all the sdk functionality" 53 ] 54 }, 55 { 56 "cell_type": "code", 57 "execution_count": null, 58 "metadata": { 59 "collapsed": false 60 }, 61 "outputs": [], 62 "source": [ 63 "# All operations on buckets and objects inside\n", 64 "client.bucket(\"bucket-name\")\n", 65 "# For interacting with the AIS cluster\n", 66 "client.cluster()\n", 67 "# For starting, waiting on, and querying async jobs\n", 68 "client.job()\n", 69 "# For creating ETL jobs\n", 70 "client.etl(\"etl_name\")" 71 ] 72 }, 73 { 74 "cell_type": "markdown", 75 "metadata": { 76 "collapsed": false 77 }, 78 "source": [ 79 "## Cluster operations" 80 ] 81 }, 82 { 83 "cell_type": "markdown", 84 "metadata": { 85 "collapsed": false 86 }, 87 "source": [ 88 "### Check if aistore is running" 89 ] 90 }, 91 { 92 "cell_type": "code", 93 "execution_count": null, 94 "metadata": { 95 "collapsed": false 96 }, 97 "outputs": [], 98 "source": [ 99 "client.cluster().is_ready()" 100 ] 101 }, 102 { 103 "cell_type": "markdown", 104 "metadata": { 105 "collapsed": false 106 }, 107 "source": [] 108 }, 109 { 110 "cell_type": "markdown", 111 "metadata": { 112 "collapsed": false 113 }, 114 "source": [ 115 "### View cluster info" 116 ] 117 }, 118 { 119 "cell_type": "code", 120 "execution_count": null, 121 "metadata": { 122 "collapsed": false 123 }, 124 "outputs": [], 125 "source": [ 126 "client.cluster().get_info().dict()" 127 ] 128 }, 129 { 130 "cell_type": "markdown", 131 "metadata": { 132 "collapsed": false 133 }, 134 "source": [ 135 "### List all buckets in the cluster" 136 ] 137 }, 138 { 139 "cell_type": "code", 140 "execution_count": null, 141 "metadata": { 142 "collapsed": false 143 }, 144 "outputs": [], 145 "source": [ 146 "client.cluster().list_buckets()" 147 ] 148 }, 149 { 150 "cell_type": "markdown", 151 "metadata": { 152 "collapsed": false 153 }, 154 "source": [ 155 "## Working with jobs\n", 156 "\n", 157 "Some intensive actions run asynchronously from the sdk calls and will instead return a job id. This job id can be used to check the status and wait on the job if needed." 158 ] 159 }, 160 { 161 "cell_type": "code", 162 "execution_count": null, 163 "metadata": { 164 "collapsed": false 165 }, 166 "outputs": [], 167 "source": [ 168 "first_bck = client.bucket(\"my-first-bck\")\n", 169 "first_bck.create()\n", 170 "# Returns the id of the job\n", 171 "rename_job_id = first_bck.rename(\"new-bck\")\n", 172 "rename_job = client.job(rename_job_id)\n", 173 "# Check status\n", 174 "rename_job.status()\n", 175 "# Wait until job is finished\n", 176 "rename_job.wait()" 177 ] 178 }, 179 { 180 "cell_type": "markdown", 181 "metadata": { 182 "collapsed": false 183 }, 184 "source": [ 185 "### Querying jobs\n", 186 "You can also query the status of multiple jobs, filtered by the running cluster node or the kind of job" 187 ] 188 }, 189 { 190 "cell_type": "code", 191 "execution_count": null, 192 "metadata": { 193 "collapsed": false 194 }, 195 "outputs": [], 196 "source": [ 197 "# View all currently running jobs\n", 198 "client.cluster().list_running_jobs()\n", 199 "# View all jobs of a certain type\n", 200 "# client.cluster().list_running_jobs(job_kind=\"specific job kind\")" 201 ] 202 }, 203 { 204 "cell_type": "markdown", 205 "source": [ 206 "### Querying ETLs\n", 207 "\n", 208 "You can query for a list of running ETLs" 209 ], 210 "metadata": { 211 "collapsed": false 212 } 213 }, 214 { 215 "cell_type": "code", 216 "execution_count": null, 217 "outputs": [], 218 "source": [ 219 "client.cluster().list_running_etls()" 220 ], 221 "metadata": { 222 "collapsed": false 223 } 224 }, 225 { 226 "cell_type": "markdown", 227 "source": [], 228 "metadata": { 229 "collapsed": false 230 } 231 } 232 ], 233 "metadata": { 234 "kernelspec": { 235 "display_name": "Python 3", 236 "language": "python", 237 "name": "python3" 238 }, 239 "language_info": { 240 "codemirror_mode": { 241 "name": "ipython", 242 "version": 3 243 }, 244 "file_extension": ".py", 245 "mimetype": "text/x-python", 246 "name": "python", 247 "nbconvert_exporter": "python", 248 "pygments_lexer": "ipython3", 249 "version": "3.11.1 (main, Dec 7 2022, 01:11:34) [GCC 11.3.0]" 250 }, 251 "vscode": { 252 "interpreter": { 253 "hash": "ead1b95f633dc9c51826328e1846203f51a198c6fb5f2884a80417ba131d4e82" 254 } 255 } 256 }, 257 "nbformat": 4, 258 "nbformat_minor": 5 259 }