setup.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. Setup
  2. -----
  3. To initialize a connection to a cloud and get a provider object, you will
  4. need to provide the cloud's access credentials to CloudBridge. For more
  5. details on how to create and find these credentials, see `Procuring Access
  6. Credentials <procuring_credentials.html>`_. Once available, these may be
  7. provided in one of following ways:
  8. 1. Environment variables
  9. 2. A dictionary
  10. 3. Configuration file
  11. Providing access credentials through environment variables
  12. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  13. The following environment variables must be set, depending on the provider in use.
  14. **Amazon**
  15. +---------------------+
  16. | Mandatory variables |
  17. +=====================+
  18. | AWS_ACCESS_KEY |
  19. +---------------------+
  20. | AWS_SECRET_KEY |
  21. +---------------------+
  22. **Openstack**
  23. +---------------------+
  24. | Mandatory variables |
  25. +=====================+
  26. | OS_AUTH_URL |
  27. +---------------------+
  28. | OS_USERNAME |
  29. +---------------------+
  30. | OS_PASSWORD |
  31. +---------------------+
  32. | OS_PROJECT_NAME |
  33. +---------------------+
  34. | OS_REGION_NAME |
  35. +---------------------+
  36. +------------------------+
  37. | Optional Variables |
  38. +========================+
  39. | NOVA_SERVICE_NAME |
  40. +------------------------+
  41. | OS_COMPUTE_API_VERSION |
  42. +------------------------+
  43. | OS_VOLUME_API_VERSION |
  44. +------------------------+
  45. | OS_STORAGE_URL |
  46. +------------------------+
  47. | OS_AUTH_TOKEN |
  48. +------------------------+
  49. **Microsoft Azure**
  50. Note that managing resources in Azure requires a Resource Group. If a
  51. Resource Group is not provided as part of the configuration, cloudbridge will
  52. attempt to create a Resource Group using the given credentials. This
  53. operation will happen with the client initialization, and requires a
  54. "contributor" or "owner" role.
  55. Similarly, a Storage Account is required when managing some resources, such
  56. as KeyPairs and Buckets. If a Storage Account name is not provided as part
  57. of the configuration, cloudbridge will attempt to create the Storage Account
  58. when initializing the relevant services. This operation similarly requires a
  59. "contributor" or "owner" role.
  60. For more information on roles, see: https://docs.microsoft.com/en-us/azure/role-based-access-control/overview
  61. +-----------------------+
  62. | Mandatory variables |
  63. +=======================+
  64. | AZURE_SUBSCRIPTION_ID |
  65. +-----------------------+
  66. | AZURE_CLIENT_ID |
  67. +-----------------------+
  68. | AZURE_SECRET |
  69. +-----------------------+
  70. | AZURE_TENANT |
  71. +-----------------------+
  72. +-------------------------------------+
  73. | Optional Variables |
  74. +=====================================+
  75. | AZURE_REGION_NAME |
  76. +-------------------------------------+
  77. | AZURE_RESOURCE_GROUP |
  78. +-------------------------------------+
  79. | AZURE_STORAGE_ACCOUNT |
  80. +-------------------------------------+
  81. | AZURE_VM_DEFAULT_USER_NAME |
  82. +-------------------------------------+
  83. | AZURE_PUBLIC_KEY_STORAGE_TABLE_NAME |
  84. +-------------------------------------+
  85. **Google**
  86. +------------------------+
  87. | Mandatory variables |
  88. +========================+
  89. | GCE_SERVICE_CREDS_FILE |
  90. | or |
  91. | GCE_SERVICE_CREDS_DICT |
  92. +------------------------+
  93. +--------------------+
  94. | Optional Variables |
  95. +====================+
  96. | GCE_PROJECT_NAME |
  97. +--------------------+
  98. | GCE_DEFAULT_ZONE |
  99. +--------------------+
  100. | GCE_REGION_NAME |
  101. +--------------------+
  102. Once the environment variables are set, you can create a connection as follows:
  103. .. code-block:: python
  104. from cloudbridge.cloud.factory import CloudProviderFactory, ProviderList
  105. provider = CloudProviderFactory().create_provider(ProviderList.OPENSTACK, {})
  106. Providing access credentials through a dictionary
  107. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  108. You can initialize a simple config as follows. The key names are the same
  109. as the environment variables, in lower case. Note that the config dictionary
  110. will override environment values.
  111. .. code-block:: python
  112. from cloudbridge.cloud.factory import CloudProviderFactory, ProviderList
  113. config = {'aws_access_key' : '<your_access_key>',
  114. 'aws_secret_key' : '<your_secret_key>'}
  115. provider = CloudProviderFactory().create_provider(ProviderList.AWS, config)
  116. ## For Azure
  117. config = {'azure_subscription_id': '<your_subscription_id>',
  118. 'azure_client_id': '<your_client_id>',
  119. 'azure_secret': '<your_secret>',
  120. 'azure_tenant': '<your_tenant>',
  121. 'azure_resource_group': '<your resource group>'}
  122. provider = CloudProviderFactory().create_provider(ProviderList.AZURE, config)
  123. Some optional configuration values can only be provided through the config
  124. dictionary. These are listed below for each provider.
  125. **CloudBridge**
  126. +----------------------+------------------------------------------------------------+
  127. | Variable | Description |
  128. +======================+============================================================+
  129. | default_result_limit | Number of results that a ``.list()`` method should return. |
  130. | | Defaults to 50. |
  131. +----------------------+------------------------------------------------------------+
  132. **Amazon**
  133. +---------------------+--------------------------------------------------------------+
  134. | Variable | Description |
  135. +=====================+==============================================================+
  136. | aws_session_token | Session key for your AWS account (if using temporary |
  137. | | credentials). |
  138. +---------------------+--------------------------------------------------------------+
  139. | ec2_is_secure | True to use an SSL connection. Default is ``True``. |
  140. +---------------------+--------------------------------------------------------------+
  141. | ec2_region_name | Default region name. Defaults to ``us-east-1``. |
  142. +---------------------+--------------------------------------------------------------+
  143. | ec2_region_endpoint | Endpoint to use. Default is ``ec2.us-east-1.amazonaws.com``. |
  144. +---------------------+--------------------------------------------------------------+
  145. | ec2_port | EC2 connection port. Does not need to be specified unless |
  146. | | EC2 service is running on an alternative port. |
  147. +---------------------+--------------------------------------------------------------+
  148. | ec2_conn_path | Connection path. Defaults to ``/``. |
  149. +---------------------+--------------------------------------------------------------+
  150. | ec2_validate_certs | Whether to use SSL certificate verification. Default is |
  151. | | ``False``. |
  152. +---------------------+--------------------------------------------------------------+
  153. | s3_is_secure | True to use an SSL connection. Default is ``True``. |
  154. +---------------------+--------------------------------------------------------------+
  155. | s3_host | Host connection endpoint. Default is ``s3.amazonaws.com``. |
  156. +---------------------+--------------------------------------------------------------+
  157. | s3_port | Host connection port. Does not need to be specified unless |
  158. | | S3 service is running on an alternative port. |
  159. +---------------------+--------------------------------------------------------------+
  160. | s3_conn_path | Connection path. Defaults to ``/``. |
  161. +---------------------+--------------------------------------------------------------+
  162. | s3_validate_certs | Whether to use SSL certificate verification. Default is |
  163. | | ``False``. |
  164. +---------------------+--------------------------------------------------------------+
  165. Providing access credentials in a file
  166. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  167. CloudBridge can also read credentials from a file on your local file system.
  168. The file should be placed in one of two locations: ``/etc/cloudbridge.ini`` or
  169. ``~/.cloudbridge``. Each set of credentials should be delineated with the
  170. provider ID (e.g., ``openstack``, ``aws``, ``azure``, ``gce``) with the
  171. necessary credentials being supplied in YAML format. Note that only one set
  172. of credentials per cloud provider type can be supplied (i.e., via this
  173. method, it is not possible to provide credentials for two different
  174. OpenStack clouds).
  175. .. code-block:: bash
  176. [openstack]
  177. os_username: username
  178. os_password: password
  179. os_auth_url: auth url
  180. os_user_domain_name: user domain name
  181. os_project_domain_name: project domain name
  182. os_project_name: project name
  183. [aws]
  184. aws_access_key: access key
  185. aws_secret_key: secret key
  186. Other configuration variables
  187. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  188. In addition to the provider specific configuration variables above, there are
  189. some general configuration environment variables that apply to CloudBridge as
  190. a whole
  191. +-----------------------------+------------------------------------------------------+
  192. | Variable | Description |
  193. +=============================+======================================================+
  194. | CB_DEBUG | Setting ``CB_DEBUG=True`` will cause detailed |
  195. | | debugoutput to be printed for each provider |
  196. | | (including HTTP traces). |
  197. +-----------------------------+------------------------------------------------------+
  198. | CB_USE_MOCK_PROVIDERS | Setting this to ``True`` will cause the CloudBridge |
  199. | | test suite to use mock drivers when available. |
  200. +-----------------------------+------------------------------------------------------+
  201. | CB_TEST_PROVIDER | Set this value to a valid :class:`.ProviderList` |
  202. | | value such as ``aws``, to limit tests to that |
  203. | | provider only. |
  204. +-----------------------------+------------------------------------------------------+
  205. | CB_DEFAULT_SUBNET_LABEL | Name to be used for a subnet that will be |
  206. | | considered the 'default' by the library. This |
  207. | | default will be used only in cases there is no |
  208. | | subnet marked as the default by the provider. |
  209. +-----------------------------+------------------------------------------------------+
  210. | CB_DEFAULT_NETWORK_LABEL | Name to be used for a network that will be |
  211. | | considered the 'default' by the library. This |
  212. | | default will be used only in cases there is no |
  213. | | network marked as the default by the provider. |
  214. +-----------------------------+------------------------------------------------------+
  215. | CB_DEFAULT_IPV4RANGE | The default IPv4 range when creating networks if |
  216. | | one is not provided. This value is also used in |
  217. | | tests. |
  218. +-----------------------------+------------------------------------------------------+
  219. | CB_DEFAULT_SUBNET_IPV4RANGE | The default subnet IPv4 range used by CloudBridge |
  220. | | if one is not specified by the user. Tests do not |
  221. | | respect this variable. |
  222. +-----------------------------+------------------------------------------------------+