
On 12/20/2016 02:19 PM, TranceWorldLogic . wrote:
Hi,
I am trying to setup OVS network using ovirt and found guide as shown below: https://www.ovirt.org/networking/ovs/
Then, I tried to explore "vNic Profile" in sdk but not found any ovs profile in types.py. Can anyone help me how to setup ovs using python sdk ? I am using ovirtsdk4 (4.0 version).
Should be something like this: ---8<--- #!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright (c) 2016 Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # import logging import ovirtsdk4 as sdk import ovirtsdk4.types as types logging.basicConfig(level=logging.DEBUG, filename='example.log') # This example will connect to the server and create a logical network # that using Open vSwitch. Note that in order for this to work the # engine has to be configured to use Open vSwitch, as described here: # # https://www.ovirt.org/networking/ovs # # Specifcally you need to run the following commands in the machine # where the engine is running: # # engine-config -s CustomDeviceProperties="{type=interface;prop={ovs=.*}}" # engine-config -s 'UserDefinedNetworkCustomProperties=ovs=.*;ovs_aa_sid=.*' # systemctl restart ovirt-engine # Create the connection to the server: connection = sdk.Connection( url='https://engine41.example.com/ovirt-engine/api', username='admin@internal', password='redhat123', ca_file='ca.pem', debug=True, log=logging.getLogger(), ) # Get the reference to the root of the tree of services: system_service = connection.system_service() # Get the reference to the service that manages the logical networks: nets_service = system_service.networks_service() # Create a logical network, which will automatically create a virtual # NIC profile: net = nets_service.add( network=types.Network( name='myovsnetwork', data_center=types.DataCenter( name='mydc' ) ) ) # Retrieve the details of the virtual NIC profile that was created for # the network (assuming that there is only one): profile = connection.follow_link(net.vnic_profiles)[0] # Get the reference to the service that manages the virtual NIC profile: profiles_service = system_service.vnic_profiles_service() profile_service = profiles_service.profile_service(profile.id) # Update the custom properties of the virtual NIC profile in order to # enable Open vSwitch: profile_service.update( profile=types.VnicProfile( custom_properties=[ types.CustomProperty( name='ovs', value='true' ) ] ) ) # Close the connection to the server: connection.close() --->8--- Note that it isn't complete, and that I didn't test if the OVS network does work. But at least the creation of the network and the modification of the VNIC profile does work. I am suggesting to add this to the collection of examples of the SDK: Add example of how to create OVS network https://gerrit.ovirt.org/68825 You may want to review it.