setup.rst 24 KB

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