Skip to content

Commit bea3bce

Browse files
committed
add-domain-tasks-update-back
1 parent 791af78 commit bea3bce

1 file changed

Lines changed: 111 additions & 0 deletions

File tree

cloudify_libvirt/domain_tasks.py

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,3 +805,114 @@ def perfomance(**kwargs):
805805
ctx.logger.info("Statistics: {}".format(repr(statistics)))
806806
finally:
807807
conn.close()
808+
809+
810+
@operation
811+
def update_domain_flags(**kwargs):
812+
ctx.logger.info("Update domain")
813+
814+
libvirt_auth, template_params = common.get_libvirt_params(**kwargs)
815+
resource_id = ctx.instance.runtime_properties.get('resource_id')
816+
817+
if not resource_id:
818+
# not uninstall workflow, raise exception
819+
raise cfy_exc.NonRecoverableError("No servers for update")
820+
821+
libvirt_auth, _ = common.get_libvirt_params(**kwargs)
822+
conn = libvirt.open(libvirt_auth)
823+
if conn is None:
824+
raise cfy_exc.NonRecoverableError(
825+
'Failed to open connection to the hypervisor'
826+
)
827+
828+
try:
829+
try:
830+
dom = conn.lookupByName(resource_id)
831+
except libvirt.libvirtError as e:
832+
raise cfy_exc.NonRecoverableError(
833+
'Failed to find the domain: {}'.format(repr(e))
834+
)
835+
836+
state, _ = dom.state()
837+
if state == libvirt.VIR_DOMAIN_RUNNING:
838+
ctx.logger.info("Looks as running. Stop before updating")
839+
return
840+
xmlconfig = common.gen_xml_template(kwargs, template_params, 'domain')
841+
dom.updateDeviceFlags(xmlconfig)
842+
ctx.logger.info('Domain {0} updated.'.format(resource_id))
843+
finally:
844+
conn.close()
845+
846+
847+
@operation
848+
def detach_device_flags(**kwargs):
849+
ctx.logger.info("Update domain")
850+
851+
libvirt_auth, template_params = common.get_libvirt_params(**kwargs)
852+
resource_id = ctx.instance.runtime_properties.get('resource_id')
853+
854+
if not resource_id:
855+
# not uninstall workflow, raise exception
856+
raise cfy_exc.NonRecoverableError("No servers for update")
857+
858+
libvirt_auth, _ = common.get_libvirt_params(**kwargs)
859+
conn = libvirt.open(libvirt_auth)
860+
if conn is None:
861+
raise cfy_exc.NonRecoverableError(
862+
'Failed to open connection to the hypervisor'
863+
)
864+
865+
try:
866+
try:
867+
dom = conn.lookupByName(resource_id)
868+
except libvirt.libvirtError as e:
869+
raise cfy_exc.NonRecoverableError(
870+
'Failed to find the domain: {}'.format(repr(e))
871+
)
872+
873+
state, _ = dom.state()
874+
if state == libvirt.VIR_DOMAIN_RUNNING:
875+
ctx.logger.info("Looks as running. Stop before updating")
876+
return
877+
xmlconfig = common.gen_xml_template(kwargs, template_params, 'domain')
878+
dom.detachDeviceFlags(xmlconfig)
879+
ctx.logger.info('Domain {0} updated.'.format(resource_id))
880+
finally:
881+
conn.close()
882+
883+
884+
@operation
885+
def attach_device_flags(**kwargs):
886+
ctx.logger.info("Update domain")
887+
888+
libvirt_auth, template_params = common.get_libvirt_params(**kwargs)
889+
resource_id = ctx.instance.runtime_properties.get('resource_id')
890+
891+
if not resource_id:
892+
# not uninstall workflow, raise exception
893+
raise cfy_exc.NonRecoverableError("No servers for update")
894+
895+
libvirt_auth, _ = common.get_libvirt_params(**kwargs)
896+
conn = libvirt.open(libvirt_auth)
897+
if conn is None:
898+
raise cfy_exc.NonRecoverableError(
899+
'Failed to open connection to the hypervisor'
900+
)
901+
902+
try:
903+
try:
904+
dom = conn.lookupByName(resource_id)
905+
except libvirt.libvirtError as e:
906+
raise cfy_exc.NonRecoverableError(
907+
'Failed to find the domain: {}'.format(repr(e))
908+
)
909+
910+
state, _ = dom.state()
911+
if state == libvirt.VIR_DOMAIN_RUNNING:
912+
ctx.logger.info("Looks as running. Stop before updating")
913+
return
914+
xmlconfig = common.gen_xml_template(kwargs, template_params, 'domain')
915+
dom.attachDeviceFlags(xmlconfig)
916+
ctx.logger.info('Domain {0} updated.'.format(resource_id))
917+
finally:
918+
conn.close()

0 commit comments

Comments
 (0)