setup.rst 8.3 KB

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