Re: [ovirt-users] Power Management with python SDK
On 12/01/2015 03:16 PM, Giulio Casella wrote: > Hi everybody, > I'm trying to enable power management on a host using python, but I'm stuck. > > Previously (ovirt 3.5) I directly wrote power management parameters into > PowerManagement structure (and everything was working fine), but > starting from 3.6 this is not possible. > > This is what I do now: > > agent = params.Agent() > agent.set_options(params.Options()) > agent.set_type("ilo3") > agent.set_username("admin") > agent.set_password("mysecret") > agent.set_address("172.20.20.1") > > agents=params.Agents() > agents.add_agent(agent) > > pm=params.PowerManagement() > pm.set_agents(agents) > pm.set_enabled(True) > > myhost=api.hosts.get("myhost") > myhost.set_power_management(pm) > try: > myhost.update() > except Exception as e: > print "Error: %s" % e > > and I get: > > Error: > status: 400 > reason: Bad Request > detail: Cannot edit Host. Power Management is enabled for Host but no > Agent type selected. > > > If I dont't enable PM (pm.set_enabled line above) I get no error, but no > agent is added. > > My software is: > - ovirt-engine-3.6.0.3-1.el6 > - ovirt-engine-sdk-python-3.6.0.3-1.el6 > on a CentOS 6.6 distro. > > Any ideas? > > Thanks in advance, > Giulio In 3.6 fencing agents have been converted into a sub-collection of the host entity: https://.../ovirt-engine/api/hosts/{host:id}/fenceagents This means that the recommended way to add/remove/update fencing agents now in Python is now this: ---8<--- # Find the host: host = api.hosts.get(name="myhost"); # Enable power management: host.get_power_management().set_enabled(True) host.update() # Add the fencing agent: agent = params.Agent() agent.set_options(params.Options()) agent.set_type("ilo3") agent.set_username("admin") agent.set_password("mysecret") agent.set_address("172.20.20.1") agent.set_order(1); host.fenceagents.add(agent) --->8--- You can use this as a workaround. However the mechanism used in 3.5 should continue working in 3.6. If it doesn't it is a bug. The script that you shared is the one you used in 3.5? -- Dirección Comercial: C/Jose Bardasano Baos, 9, Edif. Gorbea 3, planta 3ºD, 28016 Madrid, Spain Inscrita en el Reg. Mercantil de Madrid – C.I.F. B82657941 - Red Hat S.L. ___ Users mailing list Users@ovirt.org http://lists.ovirt.org/mailman/listinfo/users
[ovirt-users] Power Management with python SDK
Hi everybody, I'm trying to enable power management on a host using python, but I'm stuck. Previously (ovirt 3.5) I directly wrote power management parameters into PowerManagement structure (and everything was working fine), but starting from 3.6 this is not possible. This is what I do now: agent = params.Agent() agent.set_options(params.Options()) agent.set_type("ilo3") agent.set_username("admin") agent.set_password("mysecret") agent.set_address("172.20.20.1") agents=params.Agents() agents.add_agent(agent) pm=params.PowerManagement() pm.set_agents(agents) pm.set_enabled(True) myhost=api.hosts.get("myhost") myhost.set_power_management(pm) try: myhost.update() except Exception as e: print "Error: %s" % e and I get: Error: status: 400 reason: Bad Request detail: Cannot edit Host. Power Management is enabled for Host but no Agent type selected. If I dont't enable PM (pm.set_enabled line above) I get no error, but no agent is added. My software is: - ovirt-engine-3.6.0.3-1.el6 - ovirt-engine-sdk-python-3.6.0.3-1.el6 on a CentOS 6.6 distro. Any ideas? Thanks in advance, Giulio ___ Users mailing list Users@ovirt.org http://lists.ovirt.org/mailman/listinfo/users
Re: [ovirt-users] Power Management with python SDK
Hi Juan, Il 01/12/2015 16:48, Juan Hernández ha scritto: On 12/01/2015 03:16 PM, Giulio Casella wrote: Hi everybody, I'm trying to enable power management on a host using python, but I'm stuck. Previously (ovirt 3.5) I directly wrote power management parameters into PowerManagement structure (and everything was working fine), but starting from 3.6 this is not possible. This is what I do now: agent = params.Agent() agent.set_options(params.Options()) agent.set_type("ilo3") agent.set_username("admin") agent.set_password("mysecret") agent.set_address("172.20.20.1") agents=params.Agents() agents.add_agent(agent) pm=params.PowerManagement() pm.set_agents(agents) pm.set_enabled(True) myhost=api.hosts.get("myhost") myhost.set_power_management(pm) try: myhost.update() except Exception as e: print "Error: %s" % e and I get: Error: status: 400 reason: Bad Request detail: Cannot edit Host. Power Management is enabled for Host but no Agent type selected. If I dont't enable PM (pm.set_enabled line above) I get no error, but no agent is added. My software is: - ovirt-engine-3.6.0.3-1.el6 - ovirt-engine-sdk-python-3.6.0.3-1.el6 on a CentOS 6.6 distro. Any ideas? Thanks in advance, Giulio In 3.6 fencing agents have been converted into a sub-collection of the host entity: https://.../ovirt-engine/api/hosts/{host:id}/fenceagents This means that the recommended way to add/remove/update fencing agents now in Python is now this: ---8<--- # Find the host: host = api.hosts.get(name="myhost"); # Enable power management: host.get_power_management().set_enabled(True) host.update() # Add the fencing agent: agent = params.Agent() agent.set_options(params.Options()) agent.set_type("ilo3") agent.set_username("admin") agent.set_password("mysecret") agent.set_address("172.20.20.1") agent.set_order(1); host.fenceagents.add(agent) --->8--- This piece of code is working, thanks! But only if host.update() is called after adding an agent (e.g moving host.update() at the bottom). I don't have any fence agent configured before, and setting enabled=True and calling update, lead to the 400 HTTP error. You can use this as a workaround. However the mechanism used in 3.5 should continue working in 3.6. If it doesn't it is a bug. The script that you shared is the one you used in 3.5? In 3.5 I used: myhost=api.hosts.get("myhost") pm=params.PowerManagement(type_="ilo3",enabled=True,address="172.20.20.1",username="admin",password="mysecret") myhost.set_power_management(pm) myhost.update() not working in 3.6 (according to bug https://bugzilla.redhat.com/show_bug.cgi?id=1118329, marked CLOSED WONTFIX, there is no backward compatibility). Anyway I reached my goal, thank you! Giulio ___ Users mailing list Users@ovirt.org http://lists.ovirt.org/mailman/listinfo/users