So after 5 weeks of following the #Python training for my 100DaysOfCode challenge I have decided that my main goal for the challenge itself will be to work on the Horizon Python Module. With the course some things I find really boring and I need a real target to really learn things instead of just repeating someone else is doing as well.
I will still do some of the fun parts of it in time like databases and such when I need it but for now I will focus on the module. This weekend I added handling of the Instant Clone domain accounts to the module and also added documentation both in the module and the github repository. I know I will still learn heaps because almost all of it is still rather new and repetition works best for me.
I have just pushed some changes to the Horizon Python module. With these changes I am more complying with the Python coding standards by initiating an object before being able to use the functions inside a class. Also I added a bunch of the api calls available in the monitor parts.
so technically you first initiate a Connection class object and than you use the hv_connect function inside that class after which the access token is stored inside the object itself.
Now to use the monitors for example you create an object for this.
The first call I will show is immediately one of the more important ones: session information. Currently only local sessions seem to be available so we’ll have to wait for global session information. This is the call I will use:
So s lot of data but less directly readable results than the soap api’s but we do see all of it including deeper levels. For applications we do see something new though.
Yes that’s actually the local application that the user launched. In this case it was through a Global Entitlement named Global_Notepad so it’s not showing that. According to the soap api’s this should also be shown there but they never do as far as I know.
[sta_anchor id=”messages” /]
Messages
One of the other things that we can do is send messages. For this we need to create an variable with the following information:
Not a lot of new data, just less things we don’t need.
[sta_anchor id=”reset” unsan=”Reset” /]
Reset
If you look good you’ll see that the machine I was showing is in the already used state. In my lab this happens because often I power down the lab while I still have some sessions running. Let’s reset this machine. What do we need for this first the api method and that’s /inventory/v1/machines/action/reset for requires:
Since I am far from fluent in REST api’s and json this took me a while to find out but I did it like this
so I use the method to pull the machines, filter on the state being “ALREADY_USED”, take the id of this as a string and convert that to json. When select the body I need to add the quotes and straight brackets because if it is a single string the json won’t be usable json. I will show it later with multiple systems that it’s not needed with multiples.
One of the options already available using the Horizon REST API‘s is working with Instant Clone Administrators. In total there are 5 API calls available and I will give an explanation for al 5 on how to use them. As you can see you’ll run all of them against /rest/config/v1/ic-domain-accounts.
As you can see I currently have 2 accounts configured.
[sta_anchor id=”post” unsan=”POST” /]
POST
With post we can configure a new Instant Clone Domain account. Let’s see what we need. According to the API explorer it looks like we need to supply a domain ID, password and account.
To get the domain ID we’ll actually need to do a GET against another url:
Now I will create the json that we’ll need to configure the account. The $data variable is just a regular powershell array that afterwards convert to the actual json
There are a few remarks about this: no propper error is returned when a wrong username and password is used. Wen you try to create an account that already exists it will return a 409 conflict.
[sta_anchor id=”post” unsan=”GETID” /]
GET with ID
This is straightforward again, just extend the url for the get with the ID of the account you want to get. I grabbed this from the regular pul request and filtered on the user account I just created
$icaccounts= Invoke-RestMethod -Method Get -uri "$url/rest/config/v1/ic-domain-accounts" -ContentType "application/json" -Headers (Get-HRHeader -accessToken $accessToken)
$accountid=($icaccounts | where {$_.username -eq "username"}).id
Invoke-RestMethod -Method Get -uri "$url/rest/config/v1/ic-domain-accounts/$accountid" -ContentType "application/json" -Headers (Get-HRHeader -accessToken $accessToken)
[sta_anchor id=”post” unsan=”PUT” /]
PUT
Put can be used to change a users password. It’s requires a combination of the url with the ID from the get with id and a body like in the Post.
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here:
Cookie Policy