VMWare REST Api - access VM host details via REST API - rest

I'm using the VMWare REST API (/api/vcenter/host) to query information about the VM Hosts registered on a vCenter. At the moment I can only seem to get basic info like this :
{
"host": "host-10",
"name": "192.168.18.89",
"connection_state": "CONNECTED",
"power_state": "POWERED_ON"
}
but the Powershell "Get-VMHost | Format-List" has much more useful information such as ESXi version, hardware specs etc.
Can I get this kind of information via the REST API as well?
Thanks!

Yes you can get that kind of information, depending on exactly what info you are wanting. The REST API references are here that you can use to look up what you need. https://developer.vmware.com/apis/vsphere-automation/latest/
For example if you want to know what software is installed you can do something like this.
export basepw=$(echo -n 'administrator#vsphere.local:{password}' | base64)
export token3=$(curl -k -X POST -H "Authorization: Basic ${basepw}" https://{vCenterIP}/api/session/ | tr -d '"')
curl -k -X GET -H "vmware-api-session-id: ${token}" "https://{vCenterIP}/api/esx/software" -H "Content-Type: application/json" -d '{ "auth_type": "EXISTING", "host": "{host-##}"}' | jq .
It looks like vSphere 8 has more options that might fit what you want, like extracting the config https://developer.vmware.com/apis/vsphere-automation/latest/esx/settings/hosts.configuration/
From the looks, some other SDKs would be more developed that the REST API current state. Personally I like govmomi and pyvmomi and both have a CLI tool that can get you started pretty fast. The cli tool for govmomi, govc, doesn't require anything extra to run, so it is fairly portable and might help you with what you are doing.
https://github.com/vmware/govmomi
https://github.com/vmware/pyvmomi

Related

Trying to debug a spring dataflow stream deployed in kubernetes

I have succesfully deployed a stream using spring dataflow in eks, but I need to debug an application of the stream.
I have set up spring.cloud.deployer.kubernetes.environment-variables: JAVA_TOOL_OPTIONS='-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8000' in the application I want to debug, and the application starts an it is listening on that port.
Is there any property to tell kubernetes to map this port and make it accessible?
Thank you.
Try this:
And then try a kubectl port-forward
service/YOUR_SERVICE_NAME Host port:Service port
The documentation is really complete btw, there's a lot of information here:
https://docs.spring.io/spring-cloud-dataflow/docs/current/reference/htmlsingle/
Thanks #bguess for point me into the rigth direcction.
Finally this is what I have done:
When we are going to deploy With web interface we click edit button of the application we want to debug:
add JAVA_TOOL_OPTIONS='-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8000' into environment-variables.
In my case I have kubernetes on aws and is deployed in private mode and the only way I have found in this moment is to create a LoadBalancer for the application. I know it is insecure but itś enough for my needs.
Finally as #bguess pointed we have to add our debug port to serverPorts, this property isn't in the list when we psuh edit button in the application so we have to write it:
So this is the way to configure with the web interface.
If we want to use a terminal in linux or similar we can do this steps:
definition="app-source | app-process | app-sink"
curl "$scdf_url/streams/definitions" --write-out '%{http_code}' --silent --output /dev/null -X POST -d "name=poc-stream&definition=$definition&deploy=false"
Where definition is our stream definition and scdf_url is the spring cloud dataflow server url. After the curl call we will have our stream created but undeployed, To deploy with the debug configuration:
properties="$(cat << EOF
{
"deployer.app-source.kubernetes.environment-variables":
"JAVA_TOOL_OPTIONS=’-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8000’",
"deployer.app-source.kubernetes.servicePorts":"8000",
"deployer.app-source.kubernetes.create-load-balancer":"true"
}
EOF
)"
curl "$scdf_url/streams/deployments/poc-stream" --write-out '%{http_code}' --silent --output /dev/null -X POST -H "Content-Type: application/json" -d "$properties"
And that's the way I have configured it.
Additionally you will have to increase inactivity time of the LoadBalancer because his value is 60s and after that time it will disconnects you.

Unable to import test results to jira via rest api

i'm using the following curl command to import the output.xml file into jira test execution key and receiving error as below. I'm sure the test execution key is existing in jira and the project id is also correct. Any pointers?
curl -H "Content-Type: multipart/form-data" -u userid:pass -F "file=#output.xml" "https://server/rest/raven/latest/import/execution/robot?projectKey=PROJKEY+and+testExecKey=TESTEXNKEY" -o error.txt
The error i receive is as below
The User "userid" does not have permission to create issues
Why does it try to create new issue while the issue already exists? And why does it say the user doesn't have access when the access is there?
You probably mean Xray add-on and you probably use the same request per their documentation. The problem seems to be with your parameter syntax. It should be .../robot/?projectKey=PROJKEY&testExecKey=TESTEXNKEY (i.e. & instead of +and+).
Plus I would explicitly specify it's a POST request: curl -X POST ....
But their error message is not clear, anyway. I don't have Xray available right now, but if you keep having troubles, I would recommend checking with their support.

IBM Urbancode Deploy get current component versions deployed to an environment

I am trying get current component version of component that is deployed to an environment in UCD via REST API/Curl command . Below is sample code which returns all versions of that component which is available in UCD. It does not give me latest version of that component deployed to an environment. Any help / suggestion?
curl -k -u userName:passw0rd \
-H "Accept: application/json" \
"https://myserver.example.com:8443/rest/deploy/environment/{environmentID}/versions/{componentID}"
uDeploy has a bunch of api endpoints that are undocumented. I could not figure out how to do this from their docs but inspecting the uDeploy web interface many times can help you find the endpoint to hit.
https://{your-udeploy-url}/rest/deploy/environment/{your-environment-id}/latestDesiredInventory/true?rowsPerPage=10000&pageNumber=1&orderField=name&sortType=desc
This will return json that you can parse to get the versions deployed in an environment.

How to get the disk size of portable disks via cURL

I would like to get the portable disk size per each of my vms.
Get ID of VMs by requesting
curl --user ":" -sk https://api.softlayer.com/rest/v3/SoftLayer_Account/getVirtualDiskImages
Get List of VMs by requesting with Key=ID
curl --user ":" -sk https://api.softlayer.com/rest/v3//SoftLayer_Virtual_Guest/Key
No method to get PortableStorageVolumes with key=VM's ID
There is only method to get PortableStorageVolumes under 'SoftLayer_Account' so that i cannot get volume size per vm id.
Unfortunately, there is not method in SoftLayer_VIrtual_Guest service which can help to retrieve portable storage volumes information.
As workaround, It's possible to get this information through SoftLayer_Account::getPortableStorageVolumes but we need to use an Object Filter, below a request which can help to retrieve Portable Storage for a specific Virtual Guest:
curl -k "https://$user:$apiKey#api.softlayer.com/rest/v3.1/SoftLayer_Account/getPortableStorageVolumes?objectFilter={"portableStorageVolumes":{"blockDevices":{"guest":{"id":{"operation":123123123}}}}}"
Replace: $user, $apiKey and 123123123(VSI id) with your own information
If you have a problem with encoding, try this:
curl -k "https://$user:$apiKey#api.softlayer.com/rest/v3.1/SoftLayer_Account/getPortableStorageVolumes?objectFilter=%7B%22portableStorageVolumes%22%3A%7B%22blockDevices%22%3A%7B%22guest%22%3A%7B%22id%22%3A%7B%22operation%22%3A123123123%7D%7D%7D%7D%7D"
Replace: $user, $apiKey and 123123123(VirtualGuest's id)

What is the equivalent to --cacerts in Scala or Java?

In my development and qa environments, I will be hitting a rest endpoint using internally signed certs. The policy where I work is to put internal certs in a separate bundle on our Linux servers.
The following works perfectly well in curl:
curl -X GET -H "Content-Type: application/json" -H "Accept: application/json" --negotiate --cacert /etc/pki/tls/out-internal-bundle.pem -u : "https://<dev or qa root>/api/profile/8461869a8b6e4558b20b14411337440b"
My actual client for this endpoint is written in Scala, however. Currently I'm making my call using scala.io.Source:
val url = s"$baseUrl/data-profiler/$id"
using(Source.fromURL(url)) { source => {
val result = source.mkString
val jsonAst = result.parseJson
jsonAst.convertTo[Job]
}}
I would like to figure out how, in my dev and qa environments, to use our internal bundle. Anyone doing that in Scala or Java?
You need to configure the "truststore" used by the JVM, with the "javax.net.ssl.trustStore" option when you launch java, i.e.
java -Djavax.net.ssl.trustStore=/etc/pki/tls/out-internal-bundle.jks ...
(sbt will take the same -D argument if you are using SBT to launch your app)
You'll need to get your CA certs into JKS format.
See:
Curl cacert to Java HttpClient equivalent
https://docs.oracle.com/cd/E19509-01/820-3503/6nf1il6er/index.html
http://docs.oracle.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html#X509TrustManager
I would entirely recommend you to use Gatling for this kind of things. Gatling is a really cool framework for load-testing and it provides support for many protocols like jms, jdbc, and of course http among others. Please take a look on it here http://gatling.io/#/ (This framework is build on Scala) and it provides support for the things that you are searching for