setup.rst 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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. A value is looked up in the
  17. config dictionary first, then in the `CloudBridge config file`_, and only
  18. then in the environment; ``None`` and the empty string count as not set, so
  19. ``False`` and ``0`` are honored as configured.
  20. .. _CloudBridge config file: #providing-access-credentials-in-a-cloudbridge-config-file
  21. .. code-block:: python
  22. from cloudbridge.factory import CloudProviderFactory, ProviderList
  23. ## For AWS
  24. config = {'aws_access_key' : '<your_access_key>',
  25. 'aws_secret_key' : '<your_secret_key>'}
  26. provider = CloudProviderFactory().create_provider(ProviderList.AWS, config)
  27. ## For Azure
  28. config = {'azure_subscription_id': '<your_subscription_id>',
  29. 'azure_client_id': '<your_client_id>',
  30. 'azure_secret': '<your_secret>',
  31. 'azure_tenant': '<your_tenant>',
  32. 'azure_resource_group': '<your resource group>'}
  33. provider = CloudProviderFactory().create_provider(ProviderList.AZURE, config)
  34. ## For GCP
  35. config = {'gcp_service_creds_file': '<service_creds_file_name>.json'}
  36. # Alternatively, we can supply a dictionary with the credentials values
  37. # as the following:
  38. gcp_creds = {
  39. "type": "service_account",
  40. "project_id": "<project_name>",
  41. "private_key_id": "<private_key_id>",
  42. "private_key": "<private_key>",
  43. "client_email": "<client_email>",
  44. "client_id": "<client_id>",
  45. "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  46. "token_uri": "https://oauth2.googleapis.com/token",
  47. "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  48. "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/service-name%40my-project.iam.gserviceaccount.com"
  49. }
  50. config = {'gcp_service_creds_dict': gcp_creds}
  51. # A third alternative is to use a GCP credentials object provided by the GCP python
  52. # sdk. This is for advanced usage scenarios.
  53. # e.g. credentials = AccessTokenCredentials(access_token, "MyAgent/1.0", None)
  54. config = {'gcp_credentials_obj': credentials}
  55. provider = CloudProviderFactory().create_provider(ProviderList.GCP, config)
  56. ## For OpenStack
  57. config = {'os_username': '<your username>',
  58. 'os_password': '<your password>',
  59. 'os_auth_url': '<auth url>,
  60. 'os_user_domain_name': '<user_domain_name>',
  61. 'os_project_domain_id': '<project_domain_id>',
  62. 'os_project_domain_name': '<project_domain_name>',
  63. 'os_project_name': '<project_name>')
  64. provider = CloudProviderFactory().create_provider(ProviderList.OPENSTACK, config)
  65. Some optional configuration values can only be provided through the config
  66. dictionary. These are listed below for each provider.
  67. CloudBridge
  68. ~~~~~~~~~~~
  69. +----------------------+------------------------------------------------------------+
  70. | Variable | Description |
  71. +======================+============================================================+
  72. | default_result_limit | Number of results that a ``.list()`` method should return. |
  73. | | Default is 50. |
  74. +----------------------+------------------------------------------------------------+
  75. AWS
  76. ~~~
  77. +---------------------+--------------------------------------------------------------+
  78. | Variable | Description |
  79. +=====================+==============================================================+
  80. | aws_region_name | Default region name. Default is ``us-east-1``. |
  81. +---------------------+--------------------------------------------------------------+
  82. | aws_zone_name | Default zone name. If not specified, defaults to first zone |
  83. | | in default region. If specified, must match default region. |
  84. +---------------------+--------------------------------------------------------------+
  85. | aws_session_token | Session key for your AWS account (if using temporary |
  86. | | credentials). |
  87. +---------------------+--------------------------------------------------------------+
  88. | ec2_endpoint_url | Endpoint to use. Default is ``ec2.us-east-1.amazonaws.com``. |
  89. +---------------------+--------------------------------------------------------------+
  90. | ec2_is_secure | True to use an SSL connection. Default is ``True``. |
  91. +---------------------+--------------------------------------------------------------+
  92. | ec2_validate_certs | Whether to use SSL certificate verification. Default is |
  93. | | ``False``. |
  94. +---------------------+--------------------------------------------------------------+
  95. | ec2_retries_value | The number of retries to configure boto ec2 client with |
  96. | | Default is ``4``. |
  97. +---------------------+--------------------------------------------------------------+
  98. | s3_endpoint_url | Host connection endpoint. Default is ``s3.amazonaws.com``. |
  99. +---------------------+--------------------------------------------------------------+
  100. | s3_is_secure | True to use an SSL connection. Default is ``True``. |
  101. +---------------------+--------------------------------------------------------------+
  102. | s3_validate_certs | Whether to use SSL certificate verification. Default is |
  103. | | ``False``. |
  104. +---------------------+--------------------------------------------------------------+
  105. Azure
  106. ~~~~~
  107. +-------------------------------------+----------------------------------------------------------+
  108. | Variable | Description |
  109. +=====================================+==========================================================+
  110. | azure_access_token | To sign requests to APIs protected by Azure. |
  111. +-------------------------------------+----------------------------------------------------------+
  112. | azure_public_key_storage_table_name | Storage table name where the key pairs are stored. |
  113. | | Default is ``cbcerts``. |
  114. +-------------------------------------+----------------------------------------------------------+
  115. | azure_region_name | Default region to use for the current |
  116. | | session. Default is ``eastus``. |
  117. +-------------------------------------+----------------------------------------------------------+
  118. | aws_zone_name | Default zone name. If not specified, defaults to first |
  119. | | zone in default region. If specified, must match default |
  120. | | region. |
  121. +-------------------------------------+----------------------------------------------------------+
  122. | azure_resource_group | Azure resource group to use. Default is ``cloudbridge``. |
  123. +-------------------------------------+----------------------------------------------------------+
  124. | azure_storage_account | Azure storage account to use. Note that this value must |
  125. | | be unique across Azure and all data in a given session |
  126. | | is stored within the supplied storage account. Default |
  127. | | ``storacc`` + first 6 chars of subscription id + first 6 |
  128. | | chars of the supplied resource group. |
  129. +-------------------------------------+----------------------------------------------------------+
  130. | azure_vm_default_username | System user name for which supplied key pair will be |
  131. | | placed. |
  132. +-------------------------------------+----------------------------------------------------------+
  133. GCP
  134. ~~~
  135. +-------------------------+------------------------------------------------------------------------+
  136. | Variable | Description |
  137. +=========================+========================================================================+
  138. | gcp_region_name | Default region to use for the current session. Default is |
  139. | | ``us-central1``. |
  140. +-------------------------+------------------------------------------------------------------------+
  141. | gcp_zone_name | Default zone name. If not specified, defaults to first zone in |
  142. | | default region. If specified, must match default region. |
  143. +-------------------------+------------------------------------------------------------------------+
  144. | gcp_vm_default_username | System user name for which supplied key pair will be placed. |
  145. +-------------------------+------------------------------------------------------------------------+
  146. | gcp_credentials_obj | Provided to support advanced usage scenarios where an alternative |
  147. | | authentication mechanism is required for GCP. This object replaces |
  148. | | `GCP_SERVICE_CREDS_DICT` and is directly passed to the underlying |
  149. | | python sdk's build method as |
  150. | | ``discovery.build('storage', 'v1', credentials=gcp_credentials_obj)``. |
  151. | | You can pass in a manually constructed credentials object such as |
  152. | | ``creds = AccessTokenCredentials(access_token, "MyAgent/1.0", None)``. |
  153. | | Refer to the GCP python sdk for available options. |
  154. +-------------------------+------------------------------------------------------------------------+
  155. OpenStack
  156. ~~~~~~~~~
  157. +----------------------------------+--------------------------------------------------------------+
  158. | Variable | Description |
  159. +==================================+==============================================================+
  160. | os_auth_url | Required. OpenStack authentication endpoint. |
  161. | | eg: https://my-openstack.com:5000/v3 |
  162. +----------------------------------+--------------------------------------------------------------+
  163. | os_username | Username for password authentication. Required unless an |
  164. | | application credential is given. |
  165. +----------------------------------+--------------------------------------------------------------+
  166. | os_password | Password for password authentication. Required unless an |
  167. | | application credential is given. |
  168. +----------------------------------+--------------------------------------------------------------+
  169. | os_application_credential_id | Keystone application credential ID. Together with the secret,|
  170. | | an alternative to a username and password. |
  171. +----------------------------------+--------------------------------------------------------------+
  172. | os_application_credential_secret | Keystone application credential secret. |
  173. +----------------------------------+--------------------------------------------------------------+
  174. | os_project_name | Required. The project in which to manage resources. |
  175. +----------------------------------+--------------------------------------------------------------+
  176. | os_region_name | Required. Region in which to manage resources. |
  177. +----------------------------------+--------------------------------------------------------------+
  178. | os_zone_name | Default Availability Zone in which to manage resources. |
  179. | | If not provided, will default to the first available zone |
  180. | | in the region. This zone will be the default for all services|
  181. | | unless overwritten by service-specific zone configs |
  182. +----------------------------------+--------------------------------------------------------------+
  183. | os_compute_zone_name | Default Availability Zone for Compute servies. |
  184. | | If not provided, will default to `os_zone_name` |
  185. +----------------------------------+--------------------------------------------------------------+
  186. | os_networking_zone_nam e | Default Availability Zone for Networking servies. |
  187. | | If not provided, will default to `os_zone_name` |
  188. +----------------------------------+--------------------------------------------------------------+
  189. | os_security_zone_name | Default Availability Zone for Security servies. |
  190. | | If not provided, will default to `os_zone_name` |
  191. +----------------------------------+--------------------------------------------------------------+
  192. | os_storage_zone_name | Default Availability Zone for Storage servies. |
  193. | | If not provided, will default to `os_zone_name` |
  194. +----------------------------------+--------------------------------------------------------------+
  195. | nova_service_name | Service name for the NOVA client. |
  196. +----------------------------------+--------------------------------------------------------------+
  197. | os_auth_token | Authentication token, if applicable. |
  198. +----------------------------------+--------------------------------------------------------------+
  199. | os_compute_api_version | Compute API version, if applicable. |
  200. +----------------------------------+--------------------------------------------------------------+
  201. | os_volume_api_version | Volume API version, if applicable. |
  202. +----------------------------------+--------------------------------------------------------------+
  203. | os_storage_url | Storage endpoint URL, if applicable |
  204. +----------------------------------+--------------------------------------------------------------+
  205. | os_project_domain_id | Project domain id for authentication. |
  206. +----------------------------------+--------------------------------------------------------------+
  207. | os_project_domain_name | Project domain name for authentication. |
  208. +----------------------------------+--------------------------------------------------------------+
  209. | os_user_domain_name | User domain name for authentication. |
  210. +----------------------------------+--------------------------------------------------------------+
  211. Providing access credentials through environment variables
  212. ----------------------------------------------------------
  213. The following environment variables must be set, depending on the provider in
  214. use. For the meaning of the variables and default values, see the descriptions
  215. above.
  216. AWS
  217. ~~~
  218. +---------------------+------------+
  219. | Variable | Required? |
  220. +=====================+============+
  221. | AWS_ACCESS_KEY | ✔ |
  222. +---------------------+------------+
  223. | AWS_SECRET_KEY | ✔ |
  224. +---------------------+------------+
  225. Azure
  226. ~~~~~
  227. Note that managing resources in Azure requires a Resource Group. If a
  228. Resource Group is not provided as part of the configuration, CloudBridge will
  229. attempt to create a Resource Group using the given credentials. This
  230. operation will happen with the client initialization, and requires a
  231. "contributor" or "owner" role.
  232. Similarly, a Storage Account is required when managing some resources, such
  233. as key pairs and buckets. If a Storage Account name is not provided as part
  234. of the configuration, CloudBridge will attempt to create the Storage Account
  235. when initializing the relevant services. This operation similarly requires a
  236. "contributor" or "owner" role.
  237. For more information on roles, see
  238. https://docs.microsoft.com/en-us/azure/role-based-access-control/overview.
  239. +-------------------------------------+-----------+
  240. | Variable | Required? |
  241. +=====================================+===========+
  242. | AZURE_CLIENT_ID | ✔ |
  243. +-------------------------------------+-----------+
  244. | AZURE_SECRET | ✔ |
  245. +-------------------------------------+-----------+
  246. | AZURE_SUBSCRIPTION_ID | ✔ |
  247. +-------------------------------------+-----------+
  248. | AZURE_TENANT | ✔ |
  249. +-------------------------------------+-----------+
  250. | AZURE_PUBLIC_KEY_STORAGE_TABLE_NAME | |
  251. +-------------------------------------+-----------+
  252. | AZURE_REGION_NAME | |
  253. +-------------------------------------+-----------+
  254. | AZURE_ZONE_NAME | |
  255. +-------------------------------------+-----------+
  256. | AZURE_RESOURCE_GROUP | |
  257. +-------------------------------------+-----------+
  258. | AZURE_STORAGE_ACCOUNT | |
  259. +-------------------------------------+-----------+
  260. | AZURE_VM_DEFAULT_USERNAME | |
  261. +-------------------------------------+-----------+
  262. GCP
  263. ~~~
  264. +------------------------+-----------+
  265. | Variable | Required? |
  266. +========================+===========+
  267. | GCP_SERVICE_CREDS_DICT | ✔ |
  268. | or | |
  269. | GCP_SERVICE_CREDS_FILE | |
  270. +------------------------+-----------+
  271. | GCP_ZONE_NAME | |
  272. +------------------------+-----------+
  273. | GCP_PROJECT_NAME | |
  274. +------------------------+-----------+
  275. | GCP_REGION_NAME | |
  276. +------------------------+-----------+
  277. OpenStack
  278. ~~~~~~~~~
  279. +----------------------------------+-----------+
  280. | Variable | Required? |
  281. +==================================+===========+
  282. | OS_AUTH_URL | ✔ |
  283. +----------------------------------+-----------+
  284. | OS_USERNAME | ✔? |
  285. +----------------------------------+-----------+
  286. | OS_PASSWORD | ✔? |
  287. +----------------------------------+-----------+
  288. | OS_APPLICATION_CREDENTIAL_ID | ✔? |
  289. +----------------------------------+-----------+
  290. | OS_APPLICATION_CREDENTIAL_SECRET | ✔? |
  291. +----------------------------------+-----------+
  292. | OS_PROJECT_NAME | ✔ |
  293. +----------------------------------+-----------+
  294. | OS_REGION_NAME | ✔ |
  295. +----------------------------------+-----------+
  296. | OS_ZONE_NAME | ✔ |
  297. +----------------------------------+-----------+
  298. | OS_COMPUTE_ZONE_NAME | |
  299. +----------------------------------+-----------+
  300. | OS_NETWORKING_ZONE_NAME | |
  301. +----------------------------------+-----------+
  302. | OS_SECURITY_ZONE_NAME | |
  303. +----------------------------------+-----------+
  304. | OS_STORAGE_ZONE_NAME | |
  305. +----------------------------------+-----------+
  306. | NOVA_SERVICE_NAME | |
  307. +----------------------------------+-----------+
  308. | OS_AUTH_TOKEN | |
  309. +----------------------------------+-----------+
  310. | OS_COMPUTE_API_VERSION | |
  311. +----------------------------------+-----------+
  312. | OS_VOLUME_API_VERSION | |
  313. +----------------------------------+-----------+
  314. | OS_STORAGE_URL | |
  315. +----------------------------------+-----------+
  316. | OS_PROJECT_DOMAIN_ID | |
  317. +----------------------------------+-----------+
  318. | OS_PROJECT_DOMAIN_NAME | |
  319. +----------------------------------+-----------+
  320. | OS_USER_DOMAIN_NAME | |
  321. +----------------------------------+-----------+
  322. ``OS_USERNAME``/``OS_PASSWORD`` and ``OS_APPLICATION_CREDENTIAL_ID``/
  323. ``OS_APPLICATION_CREDENTIAL_SECRET`` are alternatives. When a config
  324. dictionary names either set, the environment only completes that set: a
  325. provider configured with an application credential does not pick up an
  326. ``OS_USERNAME`` and ``OS_PASSWORD`` that happen to be in its environment.
  327. Once the environment variables are set, you can create a connection as follows,
  328. replacing ``ProviderList.AWS`` with the desired provider (AZURE, GCP, or
  329. OPENSTACK):
  330. .. code-block:: python
  331. from cloudbridge.factory import CloudProviderFactory, ProviderList
  332. provider = CloudProviderFactory().create_provider(ProviderList.AWS, {})
  333. Providing access credentials in a CloudBridge config file
  334. ---------------------------------------------------------
  335. CloudBridge can also read credentials from a file on your local file system.
  336. The file should be placed in one of two locations: ``/etc/cloudbridge.ini`` or
  337. ``~/.cloudbridge``. Each set of credentials should be delineated with the
  338. provider ID (e.g., ``openstack``, ``aws``, ``azure``, ``gcp``) with the
  339. necessary credentials being supplied in YAML format. Note that only one set
  340. of credentials per cloud provider type can be supplied (i.e., via this
  341. method, it is not possible to provide credentials for two different
  342. OpenStack clouds).
  343. .. code-block:: bash
  344. [aws]
  345. aws_access_key: access key
  346. aws_secret_key: secret key
  347. [azure]
  348. azure_subscription_id: subscription id
  349. azure_tenant: tenant
  350. azure_client_id: client id
  351. azure_secret: secret
  352. azure_resource_group: resource group
  353. [gcp]
  354. gcp_service_creds_file: absolute path to credentials file
  355. [openstack]
  356. os_username: username
  357. os_password: password
  358. os_auth_url: auth url
  359. os_user_domain_name: user domain name
  360. os_project_domain_id: project domain id
  361. os_project_domain_name: project domain name
  362. os_project_name: project name
  363. Once the file is created, you can create a connection as follows, replacing
  364. ``ProviderList.AWS`` with the desired provider (AZURE, GCP, or OPENSTACK):
  365. .. code-block:: python
  366. from cloudbridge.factory import CloudProviderFactory, ProviderList
  367. provider = CloudProviderFactory().create_provider(ProviderList.AWS, {})
  368. General configuration variables
  369. -------------------------------
  370. In addition to the provider specific configuration variables above, there are
  371. some general configuration environment variables that apply to CloudBridge as
  372. a whole.
  373. +-----------------------------+------------------------------------------------------+
  374. | Variable | Description |
  375. +=============================+======================================================+
  376. | CB_DEBUG | Setting ``CB_DEBUG=True`` will cause detailed |
  377. | | debug output to be printed for each provider |
  378. | | (including HTTP traces). |
  379. +-----------------------------+------------------------------------------------------+
  380. | CB_TEST_PROVIDER | Set this value to a valid :class:`.ProviderList` |
  381. | | value such as ``aws``, to limit tests to that |
  382. | | provider only. |
  383. +-----------------------------+------------------------------------------------------+
  384. | CB_DEFAULT_SUBNET_LABEL | Name to be used for a subnet that will be |
  385. | | considered the 'default' by the library. This |
  386. | | default will be used only in cases there is no |
  387. | | subnet marked as the default by the provider. |
  388. +-----------------------------+------------------------------------------------------+
  389. | CB_DEFAULT_NETWORK_LABEL | Name to be used for a network that will be |
  390. | | considered the 'default' by the library. This |
  391. | | default will be used only in cases there is no |
  392. | | network marked as the default by the provider. |
  393. +-----------------------------+------------------------------------------------------+
  394. | CB_DEFAULT_IPV4RANGE | The default IPv4 range when creating networks if |
  395. | | one is not provided. This value is also used in |
  396. | | tests. |
  397. +-----------------------------+------------------------------------------------------+
  398. | CB_DEFAULT_SUBNET_IPV4RANGE | The default subnet IPv4 range used by CloudBridge |
  399. | | if one is not specified by the user. Tests do not |
  400. | | respect this variable. |
  401. +-----------------------------+------------------------------------------------------+