def set_dc_quota_audit(api):
    dcs_service = api.system_service().data_centers_service()
    dc = dcs_service.list(search='name=%s' % DC_NAME)[0]
    dc_service = dcs_service.data_center_service(dc.id)
    nt.assert_true(
        dc_service.update(
            types.DataCenter(quota_mode=types.QuotaModeType.AUDIT, ), ))
Esempio n. 2
0
 def build_entity(self):
     if self.param('external_provider'):
         ons_service = self._connection.system_service(
         ).openstack_network_providers_service()
         on_service = ons_service.provider_service(
             get_id_by_name(ons_service, self.param('external_provider')))
     return otypes.Network(
         name=self._module.params['name'],
         comment=self._module.params['comment'],
         description=self._module.params['description'],
         id=self._module.params['id'],
         data_center=otypes.DataCenter(
             name=self._module.params['data_center'], )
         if self._module.params['data_center'] else None,
         vlan=otypes.Vlan(self._module.params['vlan_tag'], )
         if self._module.params['vlan_tag'] else None,
         usages=[
             otypes.NetworkUsage.VM
             if self._module.params['vm_network'] else None
         ] if self._module.params['vm_network'] is not None else None,
         mtu=self._module.params['mtu'],
         external_provider=otypes.OpenStackNetworkProvider(
             id=on_service.get().id)
         if self.param('external_provider') else None,
     )
Esempio n. 3
0
 def build_entity(self):
     return otypes.Event(
         description=self._module.params['description'],
         severity=otypes.LogSeverity(self._module.params['severity']),
         origin=self._module.params['origin'],
         custom_id=self._module.params['custom_id'],
         id=self._module.params['id'],
         cluster=otypes.Cluster(
             id=self._module.params['cluster']
         ) if self._module.params['cluster'] is not None else None,
         data_center=otypes.DataCenter(
             id=self._module.params['data_center']
         ) if self._module.params['data_center'] is not None else None,
         host=otypes.Host(
             id=self._module.params['host']
         ) if self._module.params['host'] is not None else None,
         storage_domain=otypes.StorageDomain(
             id=self._module.params['storage_domain']
         ) if self._module.params['storage_domain'] is not None else None,
         template=otypes.Template(
             id=self._module.params['template']
         ) if self._module.params['template'] is not None else None,
         user=otypes.User(
             id=self._module.params['user']
         ) if self._module.params['user'] is not None else None,
         vm=otypes.Vm(
             id=self._module.params['vm']
         ) if self._module.params['vm'] is not None else None,
     )
Esempio n. 4
0
 def import_external_network(self):
     ons_service = self._connection.system_service().openstack_network_providers_service()
     on_service = ons_service.provider_service(get_id_by_name(ons_service, self.param('external_provider')))
     networks_service = on_service.networks_service()
     network_service = networks_service.network_service(get_id_by_name(networks_service, self.param('name')))
     network_service.import_(data_center=otypes.DataCenter(name=self._module.params['data_center']))
     return {"network": get_dict_of_struct(network_service.get()), "changed": True}
Esempio n. 5
0
    def create_network(self,
                       name,
                       cidr=None,
                       dhcp=True,
                       nat=True,
                       domain=None,
                       plan='kvirt',
                       pxe=None,
                       vlan=None):
        """

        :param name:
        :param cidr:
        :param dhcp:
        :param nat:
        :param domain:
        :param plan:
        :param pxe:
        :param vlan:
        :return:
        """
        if vlan is None:
            return {'result': 'failure', 'reason': "Missing Vlan"}
        networks_service = self.conn.system_service().networks_service()
        networks_service.add(
            network=types.Network(name=name,
                                  data_center=types.DataCenter(
                                      name=self.datacenter),
                                  vlan=types.Vlan(vlan),
                                  usages=[types.NetworkUsage.VM],
                                  mtu=1500))
        return
def add_mac_pool_to_dc(pname, pfrom, pto, pdc):

    print('Adding MAC Pool : ' + pname + 'to DC ...')
    # Add a new MAC pool:
    pool = pools_service.add(
        types.MacPool(
            name=pname,
            ranges=[
                types.Range(
                    from_=pfrom,
                    to=pto,
                ),
            ],
        ), )

    # Find the DC:
    dc = dcs_service.list(search='name=' + pdc)[0]

    # Find the service that manages the DC, as we need it in order to
    # do the update:
    dc_service = dcs_service.data_center_service(dc.id)

    # Update the DC so that it uses the new MAC pool:
    dc_service.update(types.DataCenter(mac_pool=types.MacPool(
        id=pool.id, ), ), )
Esempio n. 7
0
 def ui_command_create(self, name, description=None, local=False):
     self._dcs_service.add(
         types.DataCenter(
             name=name,
             description=description if description is not None else '',
             local=local,
         ), )
     self.refresh()
Esempio n. 8
0
    def create_external_network(self, datacenter):
        self.service.import_(**{
            'async': False,
            'data_center': types.DataCenter(id=datacenter.id)
        })

        ovirt_network = Network(datacenter)
        ovirt_network.import_by_name(self.get_sdk_type().name)
        return ovirt_network
def add_dc(pname, pdescription, plocal, pmajor, pminor):
    print('Adding DC : ' + pname + '...')
    dc = dcs_service.add(
        types.DataCenter(
            name=pname,
            description=pdescription,
            local=plocal,
            version=types.Version(major=pmajor, minor=pminor),
        ), )
Esempio n. 10
0
    def ui_command_rename(self, name, new_name):
        search_query = 'name=%s' % name
        try:
            dc = self._dcs_service.list(search=search_query)[0]
        except:
            self.shell.log.info('Data center %s not found. Check spelling' %
                                name)
            return

        dc_service = self._dcs_service.data_center_service(dc.id)
        dc_service.update(types.DataCenter(name=new_name, ), )
Esempio n. 11
0
def add_cluster(pname, pdescription, ptype, pdc):
    print('Adding Cluster : ' + pname + '...')
    clusters_service.add(
        types.Cluster(
            name=pname,
            description=pdescription,
            cpu=types.Cpu(
                architecture=types.Architecture.X86_64,
                type=ptype,
            ),
            data_center=types.DataCenter(name=pdc, ),
        ), )
Esempio n. 12
0
 def add(self, storage_type):
     """
     Add a new data center.
     """
     if not self.name:
         self.name = "my_datacenter"
     try:
         logging.info('Creating a %s type datacenter %s'
                      % (storage_type, self.name))
         if self.dcs_service.add(types.DataCenter(name=self.name, storage_type=storage_type, version=self.version)):
             logging.info('Data center was created successfully')
     except Exception as e:
         logging.error('Failed to create data center:\n%s' % str(e))
Esempio n. 13
0
 def build_entity(self):
     return otypes.DataCenter(
         name=self._module.params['name'],
         comment=self._module.params['comment'],
         description=self._module.params['description'],
         quota_mode=otypes.QuotaModeType(self._module.params['quota_mode'])
         if self._module.params['quota_mode'] else None,
         local=self._module.params['local'],
         version=otypes.Version(
             major=self.__get_major(
                 self._module.params['compatibility_version']),
             minor=self.__get_minor(
                 self._module.params['compatibility_version']),
         ) if self._module.params['compatibility_version'] else None,
     )
Esempio n. 14
0
 def build_entity(self):
     return otypes.Network(
         name=self._module.params['name'],
         comment=self._module.params['comment'],
         description=self._module.params['description'],
         data_center=otypes.DataCenter(
             name=self._module.params['data_center'],
         ) if self._module.params['data_center'] else None,
         vlan=otypes.Vlan(
             self._module.params['vlan_tag'],
         ) if self._module.params['vlan_tag'] else None,
         usages=[
             otypes.NetworkUsage.VM if self._module.params['vm_network'] else None
         ] if self._module.params['vm_network'] is not None else None,
         mtu=self._module.params['mtu'],
     )
Esempio n. 15
0
 def build_entity(self):
     return otypes.DataCenter(
         name=self._module.params['name'],
         comment=self._module.params['comment'],
         description=self._module.params['description'],
         mac_pool=otypes.MacPool(
             id=getattr(self._get_mac_pool(), 'id', None),
         ) if self._module.params.get('mac_pool') else None,
         quota_mode=otypes.QuotaModeType(
             self._module.params['quota_mode']
         ) if self._module.params['quota_mode'] else None,
         local=self._module.params['local'],
         version=otypes.Version(
             major=self.__get_major(self._module.params['compatibility_version']),
             minor=self.__get_minor(self._module.params['compatibility_version']),
         ) if self._module.params['compatibility_version'] else None,
     )
Esempio n. 16
0
def add_iscsi_storage_domain(prefix):
    # FIXME
    # if API_V4:
    #    return add_iscsi_storage_domain_4(prefix)

    api = prefix.virt_env.engine_vm().get_api_v4()

    # Find LUN GUIDs
    ret = prefix.virt_env.get_vm(SD_ISCSI_HOST_NAME).ssh(
        ['cat', '/root/multipath.txt'])
    nt.assert_equals(ret.code, 0)

    lun_guids = ret.out.splitlines()[:SD_ISCSI_NR_LUNS]

    p = types.StorageDomain(
        name=SD_ISCSI_NAME,
        data_center=types.DataCenter(name=DC_NAME, ),
        type_='data',
        storage_format=SD_FORMAT,
        host=_random_host_from_dc_4(api, DC_NAME),
        storage=types.Storage(
            type_='iscsi',
            volume_group=types.VolumeGroup(logical_unit=[
                types.LogicalUnit(
                    id=lun_id,
                    address=_get_host_ip(
                        prefix,
                        SD_ISCSI_HOST_NAME,
                    ),
                    port=SD_ISCSI_PORT,
                    target=SD_ISCSI_TARGET,
                    username='******',
                    password='******',
                ) for lun_id in lun_guids
            ]),
        ),
    )
    _add_storage_domain(api, p)
Esempio n. 17
0
def main():
    argument_spec = ovirt_full_argument_spec(
        state=dict(
            choices=['present', 'absent'],
            default='present',
        ),
        data_center=dict(required=True),
        id=dict(default=None),
        name=dict(required=True),
        description=dict(default=None),
        comment=dict(default=None),
        external_provider=dict(default=None),
        vlan_tag=dict(default=None, type='int'),
        vm_network=dict(default=None, type='bool'),
        mtu=dict(default=None, type='int'),
        clusters=dict(default=None, type='list'),
        label=dict(default=None),
    )
    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
    )

    check_sdk(module)
    check_params(module)

    try:
        auth = module.params.pop('auth')
        connection = create_connection(auth)
        clusters_service = connection.system_service().clusters_service()
        networks_service = connection.system_service().networks_service()
        networks_module = NetworksModule(
            connection=connection,
            module=module,
            service=networks_service,
        )
        state = module.params['state']
        search_params = {
            'name': module.params['name'],
            'datacenter': module.params['data_center'],
        }
        if state == 'present':
            imported = False
            if module.params.get('external_provider') and module.params.get('name') not in [net.name for net in networks_service.list()]:
                # Try to import network
                ons_service = connection.system_service().openstack_network_providers_service()
                on_service = ons_service.provider_service(get_id_by_name(ons_service, module.params.get('external_provider')))
                on_networks_service = on_service.networks_service()
                if module.params.get('name') in [net.name for net in on_networks_service.list()]:
                    network_service = on_networks_service.network_service(get_id_by_name(on_networks_service, module.params.get('name')))
                    network_service.import_(data_center=otypes.DataCenter(name=module.params.get('data_center')))
                    imported = True

            ret = networks_module.create(search_params=search_params)
            ret['changed'] = ret['changed'] or imported
            # Update clusters networks:
            if module.params.get('clusters') is not None:
                for param_cluster in module.params.get('clusters'):
                    cluster = search_by_name(clusters_service, param_cluster.get('name'))
                    if cluster is None:
                        raise Exception("Cluster '%s' was not found." % param_cluster.get('name'))
                    cluster_networks_service = clusters_service.service(cluster.id).networks_service()
                    cluster_networks_module = ClusterNetworksModule(
                        network_id=ret['id'],
                        cluster_network=param_cluster,
                        connection=connection,
                        module=module,
                        service=cluster_networks_service,
                    )
                    if param_cluster.get('assigned', True):
                        ret = cluster_networks_module.create()
                    else:
                        ret = cluster_networks_module.remove()

        elif state == 'absent':
            ret = networks_module.remove(search_params=search_params)

        module.exit_json(**ret)
    except Exception as e:
        module.fail_json(msg=str(e), exception=traceback.format_exc())
    finally:
        connection.close(logout=auth.get('token') is None)
 def build_entity(self):
     sched_policy = self._get_sched_policy()
     return otypes.Cluster(
         id=self.param('id'),
         name=self.param('name'),
         comment=self.param('comment'),
         description=self.param('description'),
         ballooning_enabled=self.param('ballooning'),
         gluster_service=self.param('gluster'),
         virt_service=self.param('virt'),
         threads_as_cores=self.param('threads_as_cores'),
         ha_reservation=self.param('ha_reservation'),
         trusted_service=self.param('trusted_service'),
         optional_reason=self.param('vm_reason'),
         maintenance_reason_required=self.param('host_reason'),
         scheduling_policy=otypes.SchedulingPolicy(id=sched_policy.id, )
         if sched_policy else None,
         serial_number=otypes.SerialNumber(
             policy=otypes.SerialNumberPolicy(self.param('serial_policy')),
             value=self.param('serial_policy_value'),
         ) if (self.param('serial_policy') is not None
               or self.param('serial_policy_value') is not None) else None,
         migration=otypes.MigrationOptions(
             auto_converge=otypes.InheritableBoolean(
                 self.param('migration_auto_converge'), )
             if self.param('migration_auto_converge') else None,
             bandwidth=otypes.MigrationBandwidth(
                 assignment_method=otypes.
                 MigrationBandwidthAssignmentMethod(
                     self.param('migration_bandwidth'), )
                 if self.param('migration_bandwidth') else None,
                 custom_value=self.param('migration_bandwidth_limit'),
             ) if (self.param('migration_bandwidth')
                   or self.param('migration_bandwidth_limit')) else None,
             compressed=otypes.InheritableBoolean(
                 self.param('migration_compressed'), )
             if self.param('migration_compressed') else None,
             policy=otypes.MigrationPolicy(id=self._get_policy_id())
             if self.param('migration_policy') else None,
         ) if (self.param('migration_bandwidth') is not None
               or self.param('migration_bandwidth_limit') is not None
               or self.param('migration_auto_converge') is not None
               or self.param('migration_compressed') is not None
               or self.param('migration_policy') is not None) else None,
         error_handling=otypes.ErrorHandling(on_error=otypes.MigrateOnError(
             self.param('resilience_policy')), )
         if self.param('resilience_policy') else None,
         fencing_policy=otypes.FencingPolicy(
             enabled=self.param('fence_enabled'),
             skip_if_gluster_bricks_up=self.param(
                 'fence_skip_if_gluster_bricks_up'),
             skip_if_gluster_quorum_not_met=self.param(
                 'fence_skip_if_gluster_quorum_not_met'),
             skip_if_connectivity_broken=otypes.SkipIfConnectivityBroken(
                 enabled=self.param('fence_skip_if_connectivity_broken'),
                 threshold=self.param('fence_connectivity_threshold'),
             ) if
             (self.param('fence_skip_if_connectivity_broken') is not None
              or self.param('fence_connectivity_threshold') is not None)
             else None,
             skip_if_sd_active=otypes.SkipIfSdActive(
                 enabled=self.param('fence_skip_if_sd_active'), )
             if self.param('fence_skip_if_sd_active') is not None else None,
         ) if
         (self.param('fence_enabled') is not None
          or self.param('fence_skip_if_sd_active') is not None
          or self.param('fence_skip_if_connectivity_broken') is not None
          or self.param('fence_skip_if_gluster_bricks_up') is not None
          or self.param('fence_skip_if_gluster_quorum_not_met') is not None
          or self.param('fence_connectivity_threshold') is not None) else
         None,
         display=otypes.Display(proxy=self.param('spice_proxy'), )
         if self.param('spice_proxy') else None,
         required_rng_sources=[
             otypes.RngSource(rng) for rng in self.param('rng_sources')
         ] if self.param('rng_sources') else None,
         memory_policy=otypes.MemoryPolicy(
             over_commit=otypes.MemoryOverCommit(
                 percent=self._get_memory_policy(), ), )
         if self.param('memory_policy') else None,
         ksm=otypes.Ksm(
             enabled=self.param('ksm'),
             merge_across_nodes=not self.param('ksm_numa'),
         ) if (self.param('ksm_numa') is not None
               or self.param('ksm') is not None) else None,
         data_center=otypes.DataCenter(name=self.param('data_center'), )
         if self.param('data_center') else None,
         management_network=otypes.Network(name=self.param('network'), )
         if self.param('network') else None,
         cpu=otypes.Cpu(
             architecture=otypes.Architecture(self.param('cpu_arch'))
             if self.param('cpu_arch') else None,
             type=self.param('cpu_type'),
         ) if (self.param('cpu_arch') or self.param('cpu_type')) else None,
         version=otypes.Version(
             major=self.__get_major(self.param('compatibility_version')),
             minor=self.__get_minor(self.param('compatibility_version')),
         ) if self.param('compatibility_version') else None,
         switch_type=otypes.SwitchType(self.param('switch_type'))
         if self.param('switch_type') else None,
         mac_pool=otypes.MacPool(id=get_id_by_name(
             self._connection.system_service().mac_pools_service(),
             self.param('mac_pool'))) if self.param('mac_pool') else None,
         external_network_providers=self.
         _get_external_network_providers_entity(),
         custom_scheduling_policy_properties=[
             otypes.Property(
                 name=sp.get('name'),
                 value=str(sp.get('value')),
             ) for sp in self.param('scheduling_policy_properties') if sp
         ] if self.param('scheduling_policy_properties') is not None else
         None,
         firewall_type=otypes.FirewallType(self.param('firewall_type'))
         if self.param('firewall_type') else None,
         gluster_tuned_profile=self.param('gluster_tuned_profile'),
     )
Esempio n. 19
0
import ovirtsdk4.types as types

logging.basicConfig(level=logging.DEBUG, filename='example.log')

# This example will connect to the server and create a new data center:

# Create the connection to the server:
connection = sdk.Connection(
    url='https://engine40.example.com/ovirt-engine/api',
    username='******',
    password='******',
    ca_file='ca.pem',
    debug=True,
    log=logging.getLogger(),
)

# Get the reference to the data centers service:
dcs_service = connection.system_service().data_centers_service()

# Use the "add" method to create a new data center:
dc = dcs_service.add(
    types.DataCenter(
        name='mydc',
        description='My data center',
        local=False,
    ),
)

# Close the connection to the server:
connection.close()
Esempio n. 20
0
logging.basicConfig(level=logging.DEBUG, filename='example.log')

# This example will connect to the server and create new logical network.

# Create the connection to the server:
connection = sdk.Connection(
    url='https://engine40.example.com/ovirt-engine/api',
    username='******',
    password='******',
    ca_file='ca.pem',
    debug=True,
    log=logging.getLogger(),
)

# Get the reference to the networks service:
networks_service = connection.system_service().networks_service()

# Use the "add" method to create new VM logical network in data center
# called "mydc", with VLAN tag 100 and MTU 1500.
network = networks_service.add(network=types.Network(
    name='mynetwork',
    description='My logical network',
    data_center=types.DataCenter(name='mydc'),
    vlan=types.Vlan(id='100'),
    usages=[types.NetworkUsage.VM],
    mtu=1500,
), )

# Close the connection to the server:
connection.close()
Esempio n. 21
0
    ca_file='ca.pem',
    debug=True,
    log=logging.getLogger(),
)

# Get the reference to the data centers service:
dcs_service = connection.system_service().data_centers_service()

# Retrieve the description of the data center:
dc = dcs_service.list(search='name=mydc')[0]

# In order to update the data center we need a reference to the service
# tht manages it, then we can call the "update" method passing the
# update:
dc_service = dcs_service.data_center_service(dc.id)
dc = dc_service.update(types.DataCenter(description='Updated description', ), )

# Print the description of the result of the update:
print('%s: %s' % (dc.name, dc.description))

# Note that an alternative way to do this is to update the
# representation of the data center, and then send it:
#
# dc.description = 'Updated description'
# dc_service.update(dc)
#
# But this isn't good practice, because it will send to the server all
# the attributes of the data center, not just those that we want to
# update.

# Close the connection to the server:
def test_set_dc_quota_audit(engine_api, ost_dc_name):
    dcs_service = engine_api.system_service().data_centers_service()
    dc = dcs_service.list(search='name=%s' % ost_dc_name)[0]
    dc_service = dcs_service.data_center_service(dc.id)
    assert dc_service.update(
        types.DataCenter(quota_mode=types.QuotaModeType.AUDIT, ), )
Esempio n. 23
0
 def create(self, dc_name):
     sdk_type = types.DataCenter(name=dc_name)
     self._create_sdk_entity(sdk_type)