Advertisement
Guest User

Untitled

a guest
Mar 15th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. #
  5. # Copyright (c) 2016 Red Hat, Inc.
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License");
  8. # you may not use this file except in compliance with the License.
  9. # You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. #
  19.  
  20. import logging
  21.  
  22. import ovirtsdk4 as sdk
  23. import ovirtsdk4.types as types
  24.  
  25. logging.basicConfig(level=logging.DEBUG, filename='example.log')
  26.  
  27. # This example will connect to the server and add a network interface
  28. # card to an existing virtual machine.
  29.  
  30. # Create the connection to the server:
  31. connection = sdk.Connection(
  32. url='ovirtengine.example.com'
  33. username='username',
  34. password='password',
  35. # ca_file='ca.pem',
  36. debug=True,
  37. insecure=True,
  38. log=logging.getLogger(),
  39. )
  40.  
  41. # Locate the virtual machines service and use it to find the virtual
  42. # machine:
  43. vms_service = connection.system_service().vms_service()
  44. vm = vms_service.list(search='name=HA1-poc')[0]
  45.  
  46. # In order to specify the network that the new interface will be
  47. # connected to we need to specify the identifier of the virtual network
  48. # interface profile, so we need to find it:
  49. profiles_service = connection.system_service().vnic_profiles_service()
  50. profile_id = None
  51. for profile in profiles_service.list():
  52. if profile.name == 'devops':
  53. profile_id = profile.id
  54. break
  55.  
  56. # Locate the service that manages the network interface cards of the
  57. # virtual machine:
  58. nics_service = vms_service.vm_service(vm.id).nics_service()
  59.  
  60. # Use the "add" method of the network interface cards service to add the
  61. # new network interface card:
  62. nics_service.add(
  63. types.Nic(
  64. name='nic6',
  65. description='My network interface card',
  66. vnic_profile=types.VnicProfile(
  67. id=profile_id,
  68. ),
  69. ),
  70. )
  71.  
  72. # Close the connection to the server:
  73. connection.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement