Updates to the VMware Horizon Python Module

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.

To connect you now start like this:

import requests, getpass
import vmware_horizon

requests.packages.urllib3.disable_warnings()
url = input("URL\n")
username = input("Username\n")
domain = input("Domain\n")
pw = getpass.getpass()

hvconnectionobj = vmware_horizon.Connection(username = username,domain = domain,password = pw,url = url)
hvconnectionobj.hv_connect()

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.

monitor = vmware_horizon.Monitor(url=hvconnectionobj.url, access_token=hvconnectionobj.access_token)

To see what functions are available you can combine print with dir.

print(dir(monitor))

and the full list, the ones with (id) require an id:

  • ad_domain
  • connection_servers
  • connection_server(id)
  • event_database
  • farms
  • farm(id)
  • gateways
  • gateway(id)
  • rds_servers
  • rds_server(id)
  • saml_authenticators
  • saml_authenticator(id)
  • view_composers
  • view_composer(vcId)
  • virtual_centers
  • virtual_center(id)
  • remote_pods
  • remote_pod(id)
  • true_sso

As you can see I had to work with underscores instead of hyphens as python doesn’t like those in the names of functions

As said some of these might require an id but connection_servers works without one for example
print(monitor.connection_servers())

Todo: Error handling for wrong passwords, documentation

My #100DaysOfCode challenge: week 3

This week I learned about Object Orientated Programming, classes, modules, tuples and other things. I decided on skipping some days of the course because my goal of the 100 days is to learn new techniques to be used with Python. Some of the days are more about how to think in solving challenges than new techniques so I did look at the videos where it was clear that new stuff is being thought bit I do my own thing for the rest. I have also create a first version of a module to use the VMware Horizon REST API’s and blogged about it yesterday. On the positive side I learned that even though I was making long evenings with ControlUp’s yearly SKO I was still able to take in new information during my morning 100DaysOfCode ritual.

Learning points:

  • Even when making long days I can still take in new information during the mornings
  • I can’t be arsed to create code that I don’t care about
  • I still think this is a fun challenge
  • Python is cool

 

Week 2 of my #100DaysOfCode challenge

And with a higher or lower game I finished the second week of my 100DaysofCode #Python challenge. Sometimes when I don’t see the solution for something it takes ma ages to get on the right path but when I see it I finish the project pdq! The debugging that I have been applying for years in my powershell code also seems to apply to python and google is a coders best friend 🙂 Besides the python course I actually didn’t do a whole lot of coding in Powershell, maybe a couple of hours spread over the week and my “big project” is finally finished and ready to be published.

Good things:

  • focus
  • when it works it works

Bad things:

  • when my I start thinking in the wrong direction it will keep going wrong
  • I still sometimes think too difficult

 

My 100 Days of Code Challenge: done with the first week!

So the first seven days of coding for my 100 Days of Code Challenge have passed. I have already learned heaps from the Python course that I follow for the challenge but have also run into some walls where my thinking process brings me in the wrong direction. What I also notice is that I go a bit more advanced than the level the course currently is at because I google for some solution and try to understand that while there might be a more simple solution available that sometimes costs more lines of code. I do try to make sure that I understand what I use otherwise it doesn’t make sense to copy/paste some solution and seeing it work but having no idea on the why or how.

Not directly related to the code but the decision to do the course early in the morning works very well for me. It sharpens my senses for the rest of the day and when I sit behind my work laptop I am fully ready to go while normally I still had to get into the ‘production’ groove at that point. Sometimes I do need to finish the daily project after dinner but I don’t mind doing that. I always create the daily update page also at that moment so it’s a good combination also to refresh on what i have learned that day.

One thing that is related to code and what I have to get used to is that my coding during the day usually is 99% in PowerShell and I sometimes tend to confuse the 2 languages on how to do things at what point.

Good points:

  • I got a streak of 7 days
  • learned a lot
  • It’s fun
  • sharper for the rest of the day

less good things

  • confusing PS and Python code
  • I tend to over complicate things
  • I hate doing workflows on my pc, need to use my whiteboard

My 100 Days of Code challenge

If you follow me on Twitter or are a connection on Linkedin you might have seen the following pledge

I tweeted a bit more and have also created a Page for my challenge, you can find the pages and the daily reports in the menu above. So why am I doing this? I have been liking the idea of the challenge for a while already but never knew how to create the proper structure that I would need for it. A couple of days ago I found the Udemy Python in 100 days course and immediately knew that it was what I needed.

For the rest I don’t have a immediate project goal for the 100 days but plenty of ideas to work at afterwards. To be clear: I ahve done some basic work with Python in the past but never got further than the basics.