Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to python-ovirt-engine-sdk4 #21

Closed
wefixit-AT opened this issue Jul 3, 2016 · 14 comments
Closed

Upgrade to python-ovirt-engine-sdk4 #21

wefixit-AT opened this issue Jul 3, 2016 · 14 comments

Comments

@wefixit-AT
Copy link
Owner

There are a lot of changes between oVirt 3.* and 4.*.
I have started working on this

@Aleksey-Maksimov
Copy link

Any news?

@adiazc87
Copy link

Work with oVirt 4.0?

Thanks @wefixit-AT

@wefixit-AT
Copy link
Owner Author

Hi, yes it works with oVirt 4.0 but not with the latest ovirt sdk4. I started working on it but it's not so easy because there are zero documentation and all information's have to gather from the python ovirt library or trough the engine java source.

@adiazc87
Copy link

It works correctly, thanks for everything

This was referenced Oct 26, 2016
@mykaul
Copy link

mykaul commented Oct 26, 2016

@wefixit-AT - there are many examples @ https://github.com/oVirt/ovirt-engine-sdk/tree/master/sdk/examples (and we'll add more).
Also, the oVirt Ansible module uses it and can be used as a good reference.

@wefixit-AT
Copy link
Owner Author

Hi, examples are good but a documentation is much better. It's hard for software engineers to learn by try and error or copy/paste from examples :-(
On the other hand I work in my one-man company currently 14-16 hours from monday to sunday. When I find a reliable employee I will finish all the work for my open source and research projects.

@KKoukiou
Copy link
Contributor

Hi, I am opening discussion for this issue since I am willing to implement the support for the new api, though before starting to implement anything I would like some feedback.

There are two main approaches that I can see right now:

My first thought was that we should have both ovirt-engine-sdk-python packages installed on the system (although they have the same name it can be done by installing the packages with -I option in pip), and support both APIs in the same file. This should be done by importing the default module or if only one available, the existing module, and then having some common interface for the API calls that we need, which will map us to the right API function call.

The other approach that we could follow, is completely separate the support for the new API into different branch, however this is not preferable in my opinion, since it will results it double effort to maintain the project.

Please let me know your thoughts on these.

@mykaul
Copy link

mykaul commented Mar 31, 2017

Here are my thoughts on moving from SDK to SDK4:

  • There is an advantage of coexistence - it allows to migrate function by function, module by module, while keeping functionality working. This is what ovirt-system-tests has done successfully.
  • If going with a clean sheet approach, I'd consider doing it using the oVirt Ansible modules, creating roles and then playbacks for backup and restore. It is based on the the Python SDK4, it is more integrated with anything else you'd like to automate (using Ansible) and I'd reckon roles can be re-used in other playbooks. I feel a lot of boilerplate code would be spared this way as well, which otherwise you'd have to implement (or copy-paste from the oVirt Ansible modules - also a reasonable idea).
    We also have an implementation of ovirt-system-tests which is using only the Ansible modules.

@wefixit-AT
Copy link
Owner Author

Does anybody has ideas, or worked on moving to sdk4 or to ansible?

@zyxobo
Copy link

zyxobo commented Apr 27, 2020

I managed to make Ansible role with tasks like this:

---
# tasks file for ovbackup
- name: Backup VMs via oVirt engine
  block:
  - name: Return current time
    local_action:
      module: command
      cmd: 'date +%Y%m%dT%H%M%S'
    register: current_time
    changed_when: false
  - name: Obtain SSO token
    local_action:
      module: ovirt_auth
      url: "{{ovirt_url}}"
      username: "{{ovirt_user}}"
      ca_file: "{{ovirt_ca}}"
      password: "{{ovirt_pass}}"
    run_once: True
  - name: "Create snapshots of virtual machines"
    local_action:
      module: ovirt_snapshot
      auth: "{{ovirt_auth}}"
      vm_name: "{{vm_name}}"
      description: "{{snapshot_name}}"
      use_memory: false
      timeout: 600
    register: snapshot
  - name: "Gather info for snapshots of virtual machines"
    local_action:
      module: ovirt_snapshot_info
      auth: "{{ovirt_auth}}"
      vm: "{{vm_name}}"
      description: "{{snapshot_name}}"
    register: result
  - name: "Snapshots statuses"
    debug:
      msg: "{{snapshot_name}}: {{ result.ovirt_snapshots[0].snapshot_status }}"
  - name: "Pause for 1 minute to settle down"
    pause:
      minutes: 1
  - name: "Create clones of virtual machines"
    local_action:
      module: ovirt_vm
      auth: "{{ovirt_auth}}"
      snapshot_vm: "{{vm_name}}"
      snapshot_name: "{{snapshot_name}}"
      name: "{{vm_clone_name}}"
      state: present
      timeout: 3600
  - name: "Delete snapshots of virtual machines"
    local_action:
      module: ovirt_snapshot
      auth: "{{ovirt_auth}}"
      vm_name: "{{vm_name}}"
      state: absent
      snapshot_id: "{{ snapshot.id }}"
      timeout: 600
  - name: "Export images of virtual machines"
    local_action:
      module: ovirt_vm
      auth: "{{ovirt_auth}}"
      name: "{{vm_clone_name}}"
      state: exported
      cluster: "{{cluster}}"
      export_domain: "{{export_domain}}"
      timeout: 3600
  - name: "Remove clones of virtual machines"
    local_action:
      module: ovirt_vm
      auth: "{{ovirt_auth}}"
      state: absent
      name: "{{vm_clone_name}}"
      timeout: 600
  always:
  - name: Revoke the SSO token
    local_action:
      module: ovirt_auth
      state: absent
      ovirt_auth: "{{ovirt_auth}}"

Unfortunately I couldn't find a way for housekeeping backups in export domain.

@wefixit-AT
Copy link
Owner Author

Thanks I try it on my environment.
I played the last weeks with snapshots and duplicity to find a backup solution which does not need the SDK. The disadvantage is that you have to mount the raw image files and identify the main files an snapshots of the VM's but in case of a disaster recovery it's okay for me.

@zyxobo
Copy link

zyxobo commented Apr 30, 2020

Be aware, you need to reduce parallel tasks. I do this by setting serial = 2:

---
- hosts: backup_vms
  gather_facts: no
  serial: 2
  roles:
    - role: ovbackup

If you need, my defaults for role look like this:

---
# defaults file for ovbackup

ovirt_url: https://ovirt.engine.host/ovirt-engine/api
ovirt_ca: /path/to/ovirt/ca.crt
ovirt_user: ovirtuser@internal
ovirt_pass: ovirtpass

cluster: ovirt_cluster
snapshot_name: ovbackup_playbook
export_domain: export
vm_name: "{{ inventory_hostname | regex_replace('^([a-z0-9-]+)\\..*$', '\\1') }}"
vm_clone_name: "{{vm_name}}_BCK_{{current_time.stdout}}"

I think it would be quite neat solution if I manage somehow to delete old backups from export domain.

@wefixit-AT
Copy link
Owner Author

Done with the latest pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants