Skip to content

Commit

Permalink
Merge pull request #273 from mshriver/fix-rhevm-storage
Browse files Browse the repository at this point in the history
[1LP] Update RHEVMSystem ovirtsdk4 use
  • Loading branch information
mshriver authored Jun 7, 2018
2 parents a4b25a0 + 5d3ec7a commit aa6eb7d
Showing 1 changed file with 40 additions and 9 deletions.
49 changes: 40 additions & 9 deletions wrapanapi/rhevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,12 +356,43 @@ def _get_vm_nic_service(self, vm_name, nic_name):
def _get_vm_nic(self, vm_name, nic_name):
return self._get_vm_nic_service(vm_name, nic_name).get()

def update_vm_nic(self, vm_name, network_name, nic_name='nic1',
interface=types.NicInterface.VIRTIO):
def _get_network(self, network_name):
"""retreive a network object by name"""
networks = self.api.system_service().networks_service().list(
search='name={}'.format(network_name))
try:
return networks[0]
except IndexError:
raise ItemNotFound('No match for network by "name={}"'.format(network_name))

def update_vm_nic(self, vm_name, network_name, nic_name='nic1', interface='VIRTIO'):
nic = self._get_vm_nic(vm_name, nic_name)
nic_service = self._get_vm_nic_service(vm_name, nic_name)
nic.network = types.Network(name=network_name)
nic.interface = interface
nic.network = self._get_network(network_name)
try:
nic.vnic_profile = [v
for v in self.api.system_service().vnic_profiles_service().list()
if v.name == network_name][0]
except IndexError:
raise ItemNotFound('Unable to find vnic_profile matching network {}'
.format(network_name))
nic.interface = getattr(types.NicInterface, interface)
self._get_vm_nic_service(vm_name, nic_name).update(nic)

# TODO combine with vm function above to update nic for either
def update_template_nic(self, template_name, network_name, nic_name='nic1', interface='VIRTIO'):
nic = [n
for n in self._get_template_service(template_name).nics_service().list()
if n.name == nic_name][0]
nic.network = self._get_network(network_name)
try:
nic.vnic_profile = [v
for v in self.api.system_service().vnic_profiles_service().list()
if v.name == network_name][0]
except IndexError:
raise ItemNotFound('Unable to find vnic_profile matching network {}'
.format(network_name))
nic.interface = getattr(types.NicInterface, interface)
nic_service = self._get_template_service(template_name).nics_service().nic_service(nic.id)
nic_service.update(nic)

def _get_cluster(self, cluster_name):
Expand Down Expand Up @@ -391,7 +422,7 @@ def deploy_template(self, template, *args, **kwargs):
)
)
if 'ram' in kwargs:
vm_kwargs['memory'] = int(kwargs['ram']) * 1024 * 1024 # MB
vm_kwargs['memory'] = int(kwargs['ram'])
self._vms_service.add(types.Vm(**vm_kwargs))
self.wait_vm_stopped(kwargs['vm_name'], num_sec=timeout)
if power_on:
Expand Down Expand Up @@ -691,7 +722,7 @@ def add_disk_to_vm(self, vm_name, storage_domain=None, size=None, interface=None
)
]
),
interface=types.DiskInterface(interface),
interface=types.DiskInterface(getattr(types.DiskInterface, interface or 'VIRTIO')),
active=active
)
)
Expand Down Expand Up @@ -780,9 +811,9 @@ def import_template(self, edomain, sdomain, cluster, temp_template):
export_template = self.get_template_from_storage_domain(temp_template, edomain)
target_storage_domain = self._get_storage_domain(sdomain)
cluster_id = self._get_cluster(cluster).id
template_service = export_sd_service.templates_service().template_service(
sd_template_service = export_sd_service.templates_service().template_service(
export_template.id)
template_service.import_(
sd_template_service.import_(
storage_domain=types.StorageDomain(id=target_storage_domain.id),
cluster=types.Cluster(id=cluster_id),
template=types.Template(id=export_template.id)
Expand Down

0 comments on commit aa6eb7d

Please sign in to comment.