Skip to content

Commit 74003dd

Browse files
authored
Merge pull request #6 from f5devcentral/enhancements
Enhancements csv inventory
2 parents e337cc2 + f24e8ba commit 74003dd

File tree

3 files changed

+683
-198
lines changed

3 files changed

+683
-198
lines changed

README.md

Lines changed: 70 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ d) Are there application objects assigned to non-existent sites
2121
`python3 -m venv myenv`
2222

2323
2. Source the new environment:
24-
`source myenv/bin/activate`
24+
`source myenv/bin/activate`
2525

2626
3. Install required python modules:
2727
`python3 -m pip install -r requirements.txt`
@@ -32,12 +32,12 @@ The script uses a F5XC API Token to access a Tenant's configuration.
3232

3333
1. Create an API Token for our Tenant:
3434

35-
Sign in to the F5 XC Console with Administrative privileges and navigate to Administration. Under 'Personal Management' select 'Credentials'.
35+
Sign in to the F5 XC Console with Administrative privileges and navigate to Administration. Under 'Personal Management' select 'Credentials'.
3636
Then click 'Add Credentials' and populate the window. Make sure to select 'API Token' as the 'Credential Type' field. Save the generated API Token for the next step.
3737

3838
2. Define environment variables
3939

40-
Set environment variables with the API URL (replace tenant with your tenant name) and the generated API Token.
40+
Set environment variables with the API URL (replace tenant with your tenant name) and the generated API Token.
4141

4242
```
4343
export f5xc_api_url="https://<tenant>.console.ves.volterra.io/api"
@@ -46,32 +46,55 @@ export f5xc_api_token="............................"
4646

4747
Alternatively you can set command line options instead when running the script.
4848

49-
5049
## Usage
5150

5251
```
5352
$ ./get-sites.py
54-
usage: get-sites.py [-h] [-n NAMESPACE] [-a APIURL] [-t TOKEN] [-f FILE] [-w WORKERS] [--log-level LOG_LEVEL] [--log-stdout] [--log-file]
53+
usage: get-sites.py [-h] [-a APIURL] [-c CSV_FILE] [-f FILE] [-n NAMESPACE] [-q] [-s SITE] [-t TOKEN] [-w WORKERS] [--diff-file DIFF_FILE] [--log-level LOG_LEVEL] [--log-stdout] [--log-file]
5554
5655
Get F5 XC Sites command line arguments
5756
5857
options:
5958
-h, --help show this help message and exit
60-
-n NAMESPACE, --namespace NAMESPACE
61-
Namespace (not setting this option will process all namespaces)
6259
-a APIURL, --apiurl APIURL
6360
F5 XC API URL
61+
-c CSV_FILE, --csv-file CSV_FILE
62+
write inventory info to csv file
63+
-f FILE, --file FILE read/write api data to/from json file
64+
-n NAMESPACE, --namespace NAMESPACE
65+
namespace (not setting this option will process all namespaces)
66+
-q, --query run site query
67+
-s SITE, --site SITE site to be processed
6468
-t TOKEN, --token TOKEN
6569
F5 XC API Token
66-
-f FILE, --file FILE write site list to file
6770
-w WORKERS, --workers WORKERS
68-
maximum number of worker for concurrent processing
71+
maximum number of worker for concurrent processing (default 10)
72+
--diff-file DIFF_FILE
73+
compare to site
6974
--log-level LOG_LEVEL
7075
set log level to INFO or DEBUG
7176
--log-stdout write log info to stdout
7277
--log-file write log info to file
7378
```
7479

80+
### Example to get data from all namespaces:
81+
82+
```bash
83+
./get-sites.py -f ./get-sites-all-ns.json -q --log-level INFO --log-stdout
84+
```
85+
86+
### Example to get data from specific namespace:
87+
88+
```bash
89+
./get-sites.py -f ./get-sites-specific-ns.json -n default -q --log-level INFO --log-stdout
90+
```
91+
92+
### Example to get data for specific site:
93+
94+
```bash
95+
./get-sites.py -f ./get-sites-specific-site.json -q -s f5xc-waap-demo --log-level INFO --log-stdout
96+
```
97+
7598
The generated get-sites.json is now populated with application objects per namespace and site/virtual site and can be parsed
7699
e.g. using `gron` or inspected visually.
77100

@@ -125,7 +148,7 @@ a) What application objects are assigned to a site or virtual site and in what n
125148
. . .
126149
```
127150

128-
The site `alt-reg-site` has a loadbalancer f5dc-hello and origin pool `mw-test` assigned. Empty `site_labels` for this
151+
The site `alt-reg-site` has a loadbalancer f5dc-hello and origin pool `mw-test` assigned. Empty `site_labels` for this
129152
site `alt-reg-site` indicates the site no longer exists.
130153

131154
b) Who created an application object
@@ -173,28 +196,40 @@ json.sites_with_only_origin_pools[11] = "ce-rseries-integration";
173196

174197
d) Are there application objects assigned to non-existent sites
175198

176-
A list is written to the json file with site names that have been referenced by one of the objects but no longer
177-
exists:
178-
179-
```
180-
$ gron get-sites.json |grep orphaned
181-
json.orphaned_sites = [];
182-
json.orphaned_sites[1] = "aws-vpc-appstack-scale";
183-
json.orphaned_sites[2] = "casfdey-smsv2";
184-
json.orphaned_sites[3] = "smartretail-isv";
185-
json.orphaned_sites[4] = "f5dc-wdc-2-sat-cluster-2";
186-
json.orphaned_sites[5] = "cuyn-minikube2";
187-
json.orphaned_sites[6] = "erdc-chen-awsnet";
188-
json.orphaned_sites[7] = "fwabz-r5k-stage-2";
189-
json.orphaned_sites[8] = "mn-gw-pk8s";
190-
json.orphaned_sites[9] = "mn-aws";
191-
json.orphaned_sites[10] = "m-mn-az";
192-
json.orphaned_sites[11] = "m-mn-test";
193-
json.orphaned_sites[12] = "m-gcp-vip";
194-
```
195-
196-
197-
198-
199-
200-
199+
Look through the generated `get-sites.json` file for empty site_labels. See answer `a)` above.
200+
201+
### Compare function
202+
203+
This tool provides a comparison function to compare page information.
204+
The steps to compare site information are as follows:
205+
206+
- Run query for `siteA` and write data to `out_site_a.json`
207+
```bash
208+
./get-sites.py -f `./out_site_a_json` -q -s `siteA` --log-level INFO --log-stdout
209+
```
210+
- Run query for `siteB` and compare to `siteA` data
211+
```bash
212+
./get-sites.py -f `./out_site_b.json` -q -s `siteB` --diff-file `./ou_site_a_json` --log-level INFO --log-stdout
213+
```
214+
- Output
215+
```bash
216+
2024-10-22 16:11:09,129 - INFO - 1 site and 0 virtual site written to ./get-sites-diff-b.json
217+
2024-10-22 16:11:09,129 - INFO - compare started with data from get-sites-diff-a.json and current api run...
218+
2024-10-22 16:11:09,129 - INFO - 1 site and 0 virtual site read from ./get-sites-diff-a.json
219+
2024-10-22 16:11:09,129 - INFO - compare done with results: {'os': True, 'cpu': True, 'memory': True, 'network': [True]}
220+
```
221+
222+
Above output shows there are no differences for hardware info items __cpu__, __memory__ and __network__
223+
224+
### Create csv inventory file
225+
226+
This tool offers the function to create a CSV inventory file. This file can be read in and further processed by applying filters to the generated data.
227+
228+
- Run query for specif site or specific namespace or for all data
229+
```bash
230+
./get-sites.py -f ./get-sites-all-ns.json -q --log-level INFO --log-stdout
231+
```
232+
- Run create CSV inventory file function
233+
```bash
234+
./get-sites.py -f ./get-sites-all-ns.json -c inventory.csv --log-level INFO --log-stdout
235+
```

0 commit comments

Comments
 (0)