setup.rst 18 KB

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