adding projects to repo
This commit is contained in:
91
vrops-api/__dev/old/addhostcluster.py
Normal file
91
vrops-api/__dev/old/addhostcluster.py
Normal file
@@ -0,0 +1,91 @@
|
||||
import base64
|
||||
|
||||
# import os
|
||||
import sys
|
||||
|
||||
sys.path.append(
|
||||
'/Users/dtomlinson/OneDrive - William Hill Organisation Limited/Mac/'
|
||||
'projects/vrops-api/__dev'
|
||||
)
|
||||
# sys.path.remove(
|
||||
# '/Users/dtomlinson/OneDrive - William Hill Organisation Limited/Mac/'
|
||||
# 'projects/vrops-api/'
|
||||
# )
|
||||
from vropsAPI import vropsAPI
|
||||
|
||||
|
||||
# Authenticate:
|
||||
vrops = vropsAPI.authenticate(
|
||||
'https://sc1prapvro01/',
|
||||
'svc_splunkVROPS@Group.WilliamHill.PLC',
|
||||
'whgroup',
|
||||
base64.b64decode(b'UmFjaW5nMjEyMg==').decode(),
|
||||
verify=False,
|
||||
)
|
||||
|
||||
|
||||
# Get all clusters and store a list of Names:
|
||||
vrops.getClusters()
|
||||
vrops.getClusterIdentifiers()
|
||||
allClustersList = vropsAPI.getKeysList(vrops.allClusters)
|
||||
|
||||
|
||||
# Print all these clusters
|
||||
print(allClustersList)
|
||||
|
||||
|
||||
# Get all hosts and store a list of Names:
|
||||
vrops.getHostsFromCluster(cluster='SC1PRCONTXWHCUXCCL01')
|
||||
vrops.getHostIdentifiers()
|
||||
allHostsList = vrops.getKeysList(vrops.allHosts)
|
||||
|
||||
|
||||
# Print all these hosts
|
||||
print(allHostsList)
|
||||
|
||||
# # Add just 2 hots
|
||||
# counter = 0
|
||||
# hostList = []
|
||||
# for host in allHostsList:
|
||||
# if counter == 2:
|
||||
# break
|
||||
# else:
|
||||
# hostList.append(host)
|
||||
# counter += 1
|
||||
|
||||
|
||||
# Get all VMs and sore a list of IDs
|
||||
vrops.getVMSFromHost(allHostsList)
|
||||
vrops.getVMSIdentifiers()
|
||||
allVMSIdList = vrops.getValuesList(vrops.allVMS)
|
||||
|
||||
|
||||
# Save all VMs to disk
|
||||
vrops.saveToDisk(vrops.allVMS, indent=4, filePrefix='approach1-vms')
|
||||
|
||||
|
||||
# Get data for a vm
|
||||
vrops.getStatsFromVMS(
|
||||
begin=vrops.epochRelativeTime(vrops.epochNow, minutes=-11),
|
||||
end=vrops.epochNow,
|
||||
intervalType='MINUTES',
|
||||
intervalQuantifier='5',
|
||||
rollUpType='AVG',
|
||||
resourceId=allVMSIdList,
|
||||
statKey=['cpu|usage_average', 'config|hardware|num_Cpu'],
|
||||
)
|
||||
|
||||
|
||||
# Export the data into readable format
|
||||
vrops.exportVMData()
|
||||
|
||||
|
||||
# Save to disk
|
||||
vrops.saveToDisk(
|
||||
vrops.export,
|
||||
indent=4,
|
||||
filePrefix='approach1-export',
|
||||
breakLine=True,
|
||||
path='/Users/dtomlinson/OneDrive - William Hill Organisation Limited'
|
||||
'/Mac/projects/vrops-api/__dev',
|
||||
)
|
||||
22
vrops-api/__dev/old/authenticate.py
Normal file
22
vrops-api/__dev/old/authenticate.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import requests
|
||||
|
||||
url = "https://sc1prapvro01/suite-api/api/auth/token/acquire"
|
||||
|
||||
payload = "{\n\"username\" : \"dtomlinson@Group.WilliamHill.PLC\",\
|
||||
\n\"authSource\" : \"whgroup\",\n\"password\" : \"yi3Uw9Mw\"\n}"
|
||||
|
||||
headers = {
|
||||
'Accept': "application/json",
|
||||
'Content-Type': "application/json",
|
||||
'Cache-Control': "no-cache",
|
||||
'Host': "sc1prapvro01",
|
||||
'Accept-Encoding': "gzip, deflate",
|
||||
'Content-Length': "102",
|
||||
'Connection': "keep-alive",
|
||||
'cache-control': "no-cache"
|
||||
}
|
||||
|
||||
response = requests.request("POST", url, data=payload, headers=headers,
|
||||
verify=False)
|
||||
|
||||
print(response.text)
|
||||
87
vrops-api/__dev/old/getHostInfo.py
Normal file
87
vrops-api/__dev/old/getHostInfo.py
Normal file
@@ -0,0 +1,87 @@
|
||||
import base64
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.append(os.getcwd())
|
||||
from vropsAPI import vropsAPI
|
||||
|
||||
|
||||
# Authenticate:
|
||||
vrops = vropsAPI.authenticate(
|
||||
'https://sc1prapvro01/',
|
||||
'svc_splunkVROPS@Group.WilliamHill.PLC',
|
||||
'whgroup',
|
||||
base64.b64decode(b'UmFjaW5nMjEyMg==').decode(),
|
||||
verify=False,
|
||||
)
|
||||
|
||||
|
||||
# Get all clusters and store a list of Names:
|
||||
vrops.getClusters()
|
||||
vrops.getClusterIdentifiers()
|
||||
allClustersList = vrops.getKeysList(vrops.allClusters)
|
||||
|
||||
|
||||
# Print all these clusters
|
||||
print(allClustersList)
|
||||
|
||||
# Get all hosts and store a list of Names:
|
||||
vrops.getHostsFromCluster(cluster='SC1PRCONTXWHCUXCCL01')
|
||||
vrops.getHostIdentifiers()
|
||||
allHostsList = vrops.getValuesList(vrops.allHosts)
|
||||
|
||||
|
||||
# # Print all these hosts
|
||||
# print(allHostsList)
|
||||
|
||||
|
||||
# # Get all VMs and sore a list of IDs:
|
||||
# vrops.getVMSFromHost(allHostsList)
|
||||
# vrops.getVMSIdentifiers()
|
||||
# allVMSIdList = vrops.getValuesList(vrops.allVMS)
|
||||
|
||||
# # Save all VMs to disk
|
||||
# vrops.saveToDisk(vrops.allVMS, indent=4, filePrefix='approach1-vms')
|
||||
|
||||
# # Save all VMs:Hosts to disk
|
||||
# vrops.saveToDisk(
|
||||
# vrops.VMSHostsNames, indent=4, filePrefix='approach1-vms_hosts'
|
||||
# )
|
||||
|
||||
|
||||
# # Add a single VM to a list to pull back
|
||||
# myList = []
|
||||
# myList.append(allVMSIdList[0])
|
||||
|
||||
|
||||
# Get data for a vm
|
||||
vrops.getStatsFromVMS(
|
||||
begin=vrops.epochRelativeTime(
|
||||
vrops.epochNow, days=-3, hour=15, minute=0, second=0
|
||||
),
|
||||
end=vrops.epochRelativeTime(
|
||||
vrops.epochNow, days=-3, hour=17, minute=0, second=0
|
||||
),
|
||||
intervalType='MINUTES',
|
||||
intervalQuantifier='5',
|
||||
rollUpType='AVG',
|
||||
resourceId=allHostsList,
|
||||
statKey=['cpu|corecount_provisioned'],
|
||||
vropsType='host',
|
||||
)
|
||||
|
||||
|
||||
# Export the data into readable format
|
||||
vrops.exportVMData()
|
||||
|
||||
# Save to disk
|
||||
vrops.saveToDisk(
|
||||
vrops._vmsResources,
|
||||
indent=4,
|
||||
filePrefix='reddit-help-before',
|
||||
breakLine=True,
|
||||
)
|
||||
|
||||
vrops.saveToDisk(
|
||||
vrops.export, indent=4, filePrefix='reddit-help-after', breakLine=True
|
||||
)
|
||||
26
vrops-api/__dev/old/getMetrics.py
Normal file
26
vrops-api/__dev/old/getMetrics.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import requests
|
||||
|
||||
url = "https://sc1prapvro01/suite-api//api/resources/stats"
|
||||
|
||||
querystring = {"resourceId": "0389a5e4-9b4c-49aa-8139-92ef54f8dd9f",
|
||||
"begin": "1564587600000", "end": "1564588200000",
|
||||
"statKey":
|
||||
["cpu|workload", "mem|usage_average", "mem|swapped_average"],
|
||||
"currentOnly": "True"}
|
||||
|
||||
headers = {
|
||||
'Authorization': "vRealizeOpsToken f72a2910-88c3-442d-9dfb-58f61aa833fe"
|
||||
"::10e2fe6d-55dc-416e-ad3c-9177901f9b3a",
|
||||
'Content-Type': "application/json",
|
||||
'Accept': "application/json",
|
||||
'Cache-Control': "no-cache",
|
||||
'Host': "sc1prapvro01",
|
||||
'Accept-Encoding': "gzip, deflate",
|
||||
'Connection': "keep-alive",
|
||||
'cache-control': "no-cache"
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers, params=querystring,
|
||||
verify=False)
|
||||
|
||||
print(response.text)
|
||||
42
vrops-api/__dev/old/getVms.py
Normal file
42
vrops-api/__dev/old/getVms.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import requests
|
||||
import json
|
||||
import math
|
||||
|
||||
url = "https://sc1prapvro01/suite-api/api/resources"
|
||||
|
||||
querystring = {"page": "0", "regex": "^prdx*"}
|
||||
|
||||
headers = {
|
||||
'Content-Type': "application/json",
|
||||
'Authorization': "vRealizeOpsToken f72a2910-88c3-442d-9dfb-58f61aa833fe"
|
||||
"::29abe2bf-a1f7-464d-b48a-508320a98627",
|
||||
'Content-Type': "application/json",
|
||||
'Accept': "application/json",
|
||||
'Cache-Control': "no-cache",
|
||||
'Host': "sc1prapvro01",
|
||||
'Accept-Encoding': "gzip, deflate",
|
||||
'Connection': "keep-alive",
|
||||
'cache-control': "no-cache"
|
||||
}
|
||||
|
||||
response = requests.request("GET", url, headers=headers,
|
||||
params=querystring, verify=False)
|
||||
|
||||
t = json.loads(response.text)
|
||||
listNames = []
|
||||
totalVms = (t['pageInfo']['totalCount'])
|
||||
vmsPerPage = (t['pageInfo']['pageSize'])
|
||||
pages = math.ceil(totalVms/vmsPerPage)
|
||||
|
||||
queryList = [i for i in range(0, pages)]
|
||||
|
||||
for page in queryList:
|
||||
querystring = {'page': page}
|
||||
response = requests.request("GET", url, headers=headers,
|
||||
params=querystring, verify=False)
|
||||
for i in (range(0, 1000)):
|
||||
t = json.loads(response.text)
|
||||
listNames.append(t['resourceList'][i]['resourceKey']['name'])
|
||||
print(listNames[i])
|
||||
|
||||
print(listNames)
|
||||
134
vrops-api/__dev/old/getoutput.py
Normal file
134
vrops-api/__dev/old/getoutput.py
Normal file
@@ -0,0 +1,134 @@
|
||||
import base64
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
sys.path.append(os.getcwd())
|
||||
from vropsAPI import vropsAPI
|
||||
|
||||
|
||||
# Authenticate:
|
||||
vrops = vropsAPI.authenticate(
|
||||
'https://sc1prapvro01/',
|
||||
'svc_splunkVROPS@Group.WilliamHill.PLC',
|
||||
'whgroup',
|
||||
base64.b64decode(b'UmFjaW5nMjEyMg==').decode(),
|
||||
verify=False,
|
||||
)
|
||||
|
||||
# Load VM dict
|
||||
|
||||
with open('vms.json', 'r') as file:
|
||||
vrops.allVMS = json.load(file)
|
||||
|
||||
# Add a single VM to a list to pull back
|
||||
myList = []
|
||||
for i in range(0, len(vrops.allVMS)):
|
||||
myList.append(list(vrops.allVMS.values())[i])
|
||||
|
||||
testList = []
|
||||
testList.append(myList[10])
|
||||
testList.append(myList[11])
|
||||
|
||||
# print(myList)
|
||||
|
||||
# Get data for a vm
|
||||
vrops.getStatsFromVMS(
|
||||
begin=vrops.epochRelativeTime(vrops.epochNow, minutes=-20),
|
||||
end=vrops.epochNow,
|
||||
intervalType='MINUTES',
|
||||
intervalQuantifier='5',
|
||||
rollUpType='AVG',
|
||||
resourceId=testList,
|
||||
statKey=['cpu|usage_average', 'config|hardware|num_Cpu'],
|
||||
)
|
||||
|
||||
# print(vrops.vmsResources)
|
||||
|
||||
# Save output to disk
|
||||
# vrops.saveToDisk(vrops.vmsResources, indent=4, fileName='approach2-output')
|
||||
|
||||
export, metric = {}, {}
|
||||
|
||||
# All vms to loop through
|
||||
print(len(vrops.vmsResources['values']))
|
||||
|
||||
|
||||
# vm name
|
||||
print(vrops.vmsResources['values'][0]['name'])
|
||||
|
||||
|
||||
# data stored in
|
||||
print(vrops.vmsResources['values'][0]['stat-list']['stat'])
|
||||
|
||||
# how many keys there are
|
||||
print(len(vrops.vmsResources['values'][0]['stat-list']['stat']))
|
||||
|
||||
# timestamp earliest, -1 latest?
|
||||
print(vrops.vmsResources['values'][0]['stat-list']['stat'][0]['timestamps'][0])
|
||||
|
||||
# statkey
|
||||
print(
|
||||
vrops.vmsResources['values'][0]['stat-list']['stat'][0]['statKey']['key']
|
||||
)
|
||||
|
||||
# Rolluptype avg etc
|
||||
print(vrops.vmsResources['values'][0]['stat-list']['stat'][0]['rollUpType'])
|
||||
|
||||
# time interval
|
||||
print(vrops.vmsResources['values'][0]['stat-list']['stat'][0]['intervalUnit'][
|
||||
'quantifier'
|
||||
])
|
||||
|
||||
# intervaltype minutes etc
|
||||
print(vrops.vmsResources['values'][0]['stat-list']['stat'][0]['intervalUnit'][
|
||||
'intervalType'
|
||||
])
|
||||
|
||||
# data earliest, -1 latest?
|
||||
print(vrops.vmsResources['values'][0]['stat-list']['stat'][0]['data'][0])
|
||||
|
||||
|
||||
loopLength = len(vrops.vmsResources['values'])
|
||||
print(f'loop length - {loopLength}')
|
||||
|
||||
timeLength = len(
|
||||
vrops.vmsResources['values'][0]['stat-list']['stat'][0]['timestamps']
|
||||
)
|
||||
|
||||
metricLength = len(vrops.vmsResources['values'][0]['stat-list']['stat'])
|
||||
print(metricLength)
|
||||
|
||||
print('\n')
|
||||
|
||||
for i in range(0, loopLength):
|
||||
# timeLength = len(
|
||||
# vrops.vmsResources['values'][1]['stat-list']['stat'][0]['timestamps']
|
||||
# )
|
||||
# print(json.dumps({'name': vrops.vmsResources['values'][i]['name']}))
|
||||
pass
|
||||
|
||||
print(
|
||||
len(vrops.vmsResources['values'][0]['stat-list']['stat'][0]['timestamps']))
|
||||
|
||||
for i in range(0, loopLength):
|
||||
statKeyLength = len(vrops.vmsResources['values'][i]['stat-list']['stat'])
|
||||
timeLength = len(
|
||||
vrops.vmsResources['values'][i]['stat-list']['stat'][0]['timestamps']
|
||||
)
|
||||
for k in range(0, statKeyLength):
|
||||
for j in range(0, timeLength):
|
||||
print(type(
|
||||
json.dumps({
|
||||
'name': vrops.vmsResources['values'][i]['name'],
|
||||
'timesamp': vrops.vmsResources['values'][i]['stat-list']
|
||||
['stat'][0]['timestamps'][j],
|
||||
'data': vrops.vmsResources['values'][i]['stat-list']
|
||||
['stat'][k]['data'][j],
|
||||
'statKey': vrops.vmsResources['values'][i]['stat-list']
|
||||
['stat'][k]['statKey']['key'],
|
||||
'rollUpType': vrops.vmsResources['values'][i]['stat-list']
|
||||
['stat'][k]['rollUpType'],
|
||||
'intervalUnit': vrops.vmsResources['values'][i]
|
||||
['stat-list']['stat'][k]['intervalUnit']['quantifier']
|
||||
}),
|
||||
))
|
||||
12
vrops-api/__dev/old/regex.py
Normal file
12
vrops-api/__dev/old/regex.py
Normal file
@@ -0,0 +1,12 @@
|
||||
import re
|
||||
import json
|
||||
|
||||
data = "host info in {'pageInfo': {'totalCount': 37, 'page': 0, 'pageSize': 1000}, 'links': [{'href': '/suite-api/api/resources/15b3ea0c-9f62-4fc2-93b8-d4281196043e/relationships?page=0&pageSize=1000', 'rel': 'SELF', 'name': 'current'},"
|
||||
|
||||
pattern = r'(?:.*resources\/)(?P<host_id_response>[^\/]+)'
|
||||
|
||||
match = re.findall(pattern, data)
|
||||
|
||||
host = [x for x in match]
|
||||
|
||||
print(host)
|
||||
Reference in New Issue
Block a user