Manage Host life cycle
| 3300 | |
| 3301 | |
| 3302 | class Host: |
| 3303 | """Manage Host life cycle""" |
| 3304 | |
| 3305 | def __init__(self, items): |
| 3306 | self.__dict__.update(items) |
| 3307 | |
| 3308 | @classmethod |
| 3309 | def create(cls, apiclient, cluster, services, zoneid=None, podid=None, hypervisor=None): |
| 3310 | """ |
| 3311 | 1. Creates the host based upon the information provided. |
| 3312 | 2. Verifies the output of the adding host and its state post addition |
| 3313 | Returns FAILED in case of an issue, else an instance of Host |
| 3314 | """ |
| 3315 | try: |
| 3316 | cmd = addHost.addHostCmd() |
| 3317 | cmd.hypervisor = hypervisor |
| 3318 | cmd.url = services["url"] |
| 3319 | cmd.clusterid = cluster.id |
| 3320 | |
| 3321 | if zoneid: |
| 3322 | cmd.zoneid = zoneid |
| 3323 | else: |
| 3324 | cmd.zoneid = services["zoneid"] |
| 3325 | |
| 3326 | if podid: |
| 3327 | cmd.podid = podid |
| 3328 | else: |
| 3329 | cmd.podid = services["podid"] |
| 3330 | |
| 3331 | if "clustertype" in services: |
| 3332 | cmd.clustertype = services["clustertype"] |
| 3333 | if "username" in services: |
| 3334 | cmd.username = services["username"] |
| 3335 | if "password" in services: |
| 3336 | cmd.password = services["password"] |
| 3337 | |
| 3338 | ''' |
| 3339 | Adds a Host, |
| 3340 | If response is valid and host is up return |
| 3341 | an instance of Host. |
| 3342 | If response is invalid, returns FAILED. |
| 3343 | If host state is not up, verify through listHosts call |
| 3344 | till host status is up and return accordingly. Max 3 retries |
| 3345 | ''' |
| 3346 | host = apiclient.addHost(cmd) |
| 3347 | ret = validateList(host) |
| 3348 | if ret[0] == PASS: |
| 3349 | if str(host[0].state).lower() == 'up': |
| 3350 | return Host(host[0].__dict__) |
| 3351 | retries = 3 |
| 3352 | while retries: |
| 3353 | lh_resp = apiclient.listHosts(host[0].id) |
| 3354 | ret = validateList(lh_resp) |
| 3355 | if (ret[0] == PASS) and \ |
| 3356 | (str(ret[1].state).lower() == 'up'): |
| 3357 | return Host(host[0].__dict__) |
| 3358 | retries += -1 |
| 3359 | return FAILED |
no outgoing calls