setup.rst 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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 the `Procuring Access
  6. Credentials <procuring_credentials.html>`_ page. Note that you can selectively
  7. provide the credentials for any provider you want to use and do not have to
  8. provide credentials for all the providers. CloudBridge will consume the
  9. available credentials in one of following ways:
  10. 1. `Providing access credentials through a dictionary`_
  11. 2. `Providing access credentials through environment variables`_
  12. 3. `Providing access credentials in a CloudBridge config file`_
  13. Providing access credentials through a dictionary
  14. -------------------------------------------------
  15. You can initialize a simple config as follows. The key names are the same
  16. as the environment variables, in lower case. Note that the config dictionary
  17. will override environment values.
  18. .. code-block:: python
  19. from cloudbridge.factory import CloudProviderFactory, ProviderList
  20. ## For AWS
  21. config = {'aws_access_key' : '<your_access_key>',
  22. 'aws_secret_key' : '<your_secret_key>'}
  23. provider = CloudProviderFactory().create_provider(ProviderList.AWS, config)
  24. ## For Azure
  25. config = {'azure_subscription_id': '<your_subscription_id>',
  26. 'azure_client_id': '<your_client_id>',
  27. 'azure_secret': '<your_secret>',
  28. 'azure_tenant': '<your_tenant>',
  29. 'azure_resource_group': '<your resource group>'}
  30. provider = CloudProviderFactory().create_provider(ProviderList.AZURE, config)
  31. ## For GCP
  32. config = {'gcp_service_creds_file': '<service_creds_file_name>.json'}
  33. # Alternatively, we can supply a dictionary with the credentials values
  34. # as the following:
  35. gcp_creds = {
  36. "type": "service_account",
  37. "project_id": "<project_name>",
  38. "private_key_id": "<private_key_id>",
  39. "private_key": "<private_key>",
  40. "client_email": "<client_email>",
  41. "client_id": "<client_id>",
  42. "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  43. "token_uri": "https://oauth2.googleapis.com/token",
  44. "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  45. "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/service-name%40my-project.iam.gserviceaccount.com"
  46. }
  47. config = {'gcp_service_creds_dict': gcp_creds}
  48. provider = CloudProviderFactory().create_provider(ProviderList.GCP, config)
  49. ## For OpenStack
  50. config = {'os_username': '<your username>',
  51. 'os_password': '<your password>',
  52. 'os_auth_url': '<auth url>,
  53. 'os_user_domain_name': '<user_domain_name>',
  54. 'os_project_domain_name': '<project_domain_name>',
  55. 'os_project_name': '<project_name>')
  56. provider = CloudProviderFactory().create_provider(ProviderList.OPENSTACK, config)
  57. Some optional configuration values can only be provided through the config
  58. dictionary. These are listed below for each provider.
  59. CloudBridge
  60. ~~~~~~~~~~~
  61. +----------------------+------------------------------------------------------------+
  62. | Variable | Description |
  63. +======================+============================================================+
  64. | default_result_limit | Number of results that a ``.list()`` method should return. |
  65. | | Default is 50. |
  66. +----------------------+------------------------------------------------------------+
  67. AWS
  68. ~~~
  69. +---------------------+--------------------------------------------------------------+
  70. | Variable | Description |
  71. +=====================+==============================================================+
  72. | aws_region_name | Default region name. Default is ``us-east-1``. |
  73. +---------------------+--------------------------------------------------------------+
  74. | aws_zone_name | Default zone name. If not specified, defaults to first zone |
  75. | | in default region. If specified, must match default region. |
  76. +---------------------+--------------------------------------------------------------+
  77. | aws_session_token | Session key for your AWS account (if using temporary |
  78. | | credentials). |
  79. +---------------------+--------------------------------------------------------------+
  80. | ec2_endpoint_url | Endpoint to use. Default is ``ec2.us-east-1.amazonaws.com``. |
  81. +---------------------+--------------------------------------------------------------+
  82. | ec2_is_secure | True to use an SSL connection. Default is ``True``. |
  83. +---------------------+--------------------------------------------------------------+
  84. | ec2_validate_certs | Whether to use SSL certificate verification. Default is |
  85. | | ``False``. |
  86. +---------------------+--------------------------------------------------------------+
  87. | s3_endpoint_url | Host connection endpoint. Default is ``s3.amazonaws.com``. |
  88. +---------------------+--------------------------------------------------------------+
  89. | s3_is_secure | True to use an SSL connection. Default is ``True``. |
  90. +---------------------+--------------------------------------------------------------+
  91. | s3_validate_certs | Whether to use SSL certificate verification. Default is |
  92. | | ``False``. |
  93. +---------------------+--------------------------------------------------------------+
  94. Azure
  95. ~~~~~
  96. +-------------------------------------+----------------------------------------------------------+
  97. | Variable | Description |
  98. +=====================================+==========================================================+
  99. | azure_access_token | To sign requests to APIs protected by Azure. |
  100. +-------------------------------------+----------------------------------------------------------+
  101. | azure_public_key_storage_table_name | Storage table name where the key pairs are stored. |
  102. | | Default is ``cbcerts``. |
  103. +-------------------------------------+----------------------------------------------------------+
  104. | azure_region_name | Default region to use for the current |
  105. | | session. Default is ``eastus``. |
  106. +-------------------------------------+----------------------------------------------------------+
  107. | aws_zone_name | Default zone name. If not specified, defaults to first |
  108. | | zone in default region. If specified, must match default |
  109. | | region. |
  110. +-------------------------------------+--------------------------------------------------------------+
  111. | azure_resource_group | Azure resource group to use. Default is ``cloudbridge``. |
  112. +-------------------------------------+----------------------------------------------------------+
  113. | azure_storage_account | Azure storage account to use. Note that this value must |
  114. | | be unique across Azure and all data in a given session |
  115. | | is stored within the supplied storage account. Default |
  116. | | ``storacc`` + first 6 chars of subscription id + first 6 |
  117. | | chars of the supplied resource group. |
  118. +-------------------------------------+----------------------------------------------------------+
  119. | azure_vm_default_username | System user name for which supplied key pair will be |
  120. | | placed. |
  121. +-------------------------------------+----------------------------------------------------------+
  122. GCP
  123. ~~~
  124. +-------------------------+----------------------------------------------------------+
  125. | Variable | Description |
  126. +=========================+==========================================================+
  127. | gcp_region_name | Default region to use for the current session. Default |
  128. | | is ``us-central1``. |
  129. +-------------------------+----------------------------------------------------------+
  130. | gcp_zone_name | Default zone name. If not specified, defaults to first |
  131. | | zone in default region. If specified, must match default |
  132. | | region. |
  133. +-------------------------+----------------------------------------------------------+
  134. | gcp_vm_default_username | System user name for which supplied key pair will be |
  135. | | placed. |
  136. +-------------------------+----------------------------------------------------------+
  137. Providing access credentials through environment variables
  138. ----------------------------------------------------------
  139. The following environment variables must be set, depending on the provider in
  140. use. For the meaning of the variables and default values, see the descriptions
  141. above.
  142. AWS
  143. ~~~
  144. +---------------------+------------+
  145. | Variable | Required? |
  146. +=====================+============+
  147. | AWS_ACCESS_KEY | ✔ |
  148. +---------------------+------------+
  149. | AWS_SECRET_KEY | ✔ |
  150. +---------------------+------------+
  151. Azure
  152. ~~~~~
  153. Note that managing resources in Azure requires a Resource Group. If a
  154. Resource Group is not provided as part of the configuration, CloudBridge will
  155. attempt to create a Resource Group using the given credentials. This
  156. operation will happen with the client initialization, and requires a
  157. "contributor" or "owner" role.
  158. Similarly, a Storage Account is required when managing some resources, such
  159. as key pairs and buckets. If a Storage Account name is not provided as part
  160. of the configuration, CloudBridge will attempt to create the Storage Account
  161. when initializing the relevant services. This operation similarly requires a
  162. "contributor" or "owner" role.
  163. For more information on roles, see
  164. https://docs.microsoft.com/en-us/azure/role-based-access-control/overview.
  165. +-------------------------------------+-----------+
  166. | Variable | Required? |
  167. +=====================================+===========+
  168. | AZURE_CLIENT_ID | ✔ |
  169. +-------------------------------------+-----------+
  170. | AZURE_SECRET | ✔ |
  171. +-------------------------------------+-----------+
  172. | AZURE_SUBSCRIPTION_ID | ✔ |
  173. +-------------------------------------+-----------+
  174. | AZURE_TENANT | ✔ |
  175. +-------------------------------------+-----------+
  176. | AZURE_PUBLIC_KEY_STORAGE_TABLE_NAME | |
  177. +-------------------------------------+-----------+
  178. | AZURE_REGION_NAME | |
  179. +-------------------------------------+-----------+
  180. | AZURE_ZONE_NAME | |
  181. +-------------------------------------+-----------+
  182. | AZURE_RESOURCE_GROUP | |
  183. +-------------------------------------+-----------+
  184. | AZURE_STORAGE_ACCOUNT | |
  185. +-------------------------------------+-----------+
  186. | AZURE_VM_DEFAULT_USER_NAME | |
  187. +-------------------------------------+-----------+
  188. GCP
  189. ~~~
  190. +------------------------+-----------+
  191. | Variable | Required? |
  192. +========================+===========+
  193. | GCP_SERVICE_CREDS_DICT | ✔ |
  194. | or | |
  195. | GCP_SERVICE_CREDS_FILE | |
  196. +------------------------+-----------+
  197. | GCP_ZONE_NAME | |
  198. +------------------------+-----------+
  199. | GCP_PROJECT_NAME | |
  200. +------------------------+-----------+
  201. | GCP_REGION_NAME | |
  202. +------------------------+-----------+
  203. OpenStack
  204. ~~~~~~~~~
  205. +------------------------+-----------+
  206. | Variable | Required? |
  207. +========================+===========+
  208. | OS_AUTH_URL | ✔ |
  209. +------------------------+-----------+
  210. | OS_USERNAME | ✔ |
  211. +------------------------+-----------+
  212. | OS_PASSWORD | ✔ |
  213. +------------------------+-----------+
  214. | OS_PROJECT_NAME | ✔ |
  215. +------------------------+-----------+
  216. | OS_REGION_NAME | ✔ |
  217. +------------------------+-----------+
  218. | OS_ZONE_NAME | |
  219. +------------------------+-----------+
  220. | NOVA_SERVICE_NAME | |
  221. +------------------------+-----------+
  222. | OS_AUTH_TOKEN | |
  223. +------------------------+-----------+
  224. | OS_COMPUTE_API_VERSION | |
  225. +------------------------+-----------+
  226. | OS_VOLUME_API_VERSION | |
  227. +------------------------+-----------+
  228. | OS_STORAGE_URL | |
  229. +------------------------+-----------+
  230. Once the environment variables are set, you can create a connection as follows,
  231. replacing ``ProviderList.AWS`` with the desired provider (AZURE, GCP, or
  232. OPENSTACK):
  233. .. code-block:: python
  234. from cloudbridge.factory import CloudProviderFactory, ProviderList
  235. provider = CloudProviderFactory().create_provider(ProviderList.AWS, {})
  236. Providing access credentials in a CloudBridge config file
  237. ---------------------------------------------------------
  238. CloudBridge can also read credentials from a file on your local file system.
  239. The file should be placed in one of two locations: ``/etc/cloudbridge.ini`` or
  240. ``~/.cloudbridge``. Each set of credentials should be delineated with the
  241. provider ID (e.g., ``openstack``, ``aws``, ``azure``, ``gcp``) with the
  242. necessary credentials being supplied in YAML format. Note that only one set
  243. of credentials per cloud provider type can be supplied (i.e., via this
  244. method, it is not possible to provide credentials for two different
  245. OpenStack clouds).
  246. .. code-block:: bash
  247. [aws]
  248. aws_access_key: access key
  249. aws_secret_key: secret key
  250. [azure]
  251. azure_subscription_id: subscription id
  252. azure_tenant: tenant
  253. azure_client_id: client id
  254. azure_secret: secret
  255. azure_resource_group: resource group
  256. [gcp]
  257. gcp_service_creds_file: absolute path to credentials file
  258. [openstack]
  259. os_username: username
  260. os_password: password
  261. os_auth_url: auth url
  262. os_user_domain_name: user domain name
  263. os_project_domain_name: project domain name
  264. os_project_name: project name
  265. Once the file is created, you can create a connection as follows, replacing
  266. ``ProviderList.AWS`` with the desired provider (AZURE, GCP, or OPENSTACK):
  267. .. code-block:: python
  268. from cloudbridge.factory import CloudProviderFactory, ProviderList
  269. provider = CloudProviderFactory().create_provider(ProviderList.AWS, {})
  270. General configuration variables
  271. -------------------------------
  272. In addition to the provider specific configuration variables above, there are
  273. some general configuration environment variables that apply to CloudBridge as
  274. a whole.
  275. +-----------------------------+------------------------------------------------------+
  276. | Variable | Description |
  277. +=============================+======================================================+
  278. | CB_DEBUG | Setting ``CB_DEBUG=True`` will cause detailed |
  279. | | debug output to be printed for each provider |
  280. | | (including HTTP traces). |
  281. +-----------------------------+------------------------------------------------------+
  282. | CB_TEST_PROVIDER | Set this value to a valid :class:`.ProviderList` |
  283. | | value such as ``aws``, to limit tests to that |
  284. | | provider only. |
  285. +-----------------------------+------------------------------------------------------+
  286. | CB_DEFAULT_SUBNET_LABEL | Name to be used for a subnet that will be |
  287. | | considered the 'default' by the library. This |
  288. | | default will be used only in cases there is no |
  289. | | subnet marked as the default by the provider. |
  290. +-----------------------------+------------------------------------------------------+
  291. | CB_DEFAULT_NETWORK_LABEL | Name to be used for a network that will be |
  292. | | considered the 'default' by the library. This |
  293. | | default will be used only in cases there is no |
  294. | | network marked as the default by the provider. |
  295. +-----------------------------+------------------------------------------------------+
  296. | CB_DEFAULT_IPV4RANGE | The default IPv4 range when creating networks if |
  297. | | one is not provided. This value is also used in |
  298. | | tests. |
  299. +-----------------------------+------------------------------------------------------+
  300. | CB_DEFAULT_SUBNET_IPV4RANGE | The default subnet IPv4 range used by CloudBridge |
  301. | | if one is not specified by the user. Tests do not |
  302. | | respect this variable. |
  303. +-----------------------------+------------------------------------------------------+