setup.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. These may
  5. be provided in one of following ways:
  6. 1. Environment variables
  7. 2. A dictionary
  8. 3. Configuration file
  9. Procuring access credentials
  10. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  11. **Microsoft Azure**
  12. For Microsoft Azure, create service principle credentials following
  13. instructions from the link below:
  14. https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal#check-azure-subscription-permissions
  15. **Google**
  16. For Google Compute Engine, create a service account following instructions
  17. from the link below:
  18. https://cloud.google.com/iam/docs/creating-managing-service-accounts#creating_a_service_account
  19. Once created, grant the account appropriate permissions for your use through
  20. roles, and create a key, choosing JSON format, when prompted. These
  21. credentials can then be used with CloudBridge through the variables shown
  22. in the sections below.
  23. The JSON credentials file will have a similar form to the example shown
  24. below, and can either be passed through an absolute path to the file, or
  25. through a variable containing the JSON dictionary itself.
  26. .. code-block:: json
  27. {
  28. "type": "service_account",
  29. "project_id": "my-project",
  30. "private_key_id": "b12321312441245gerg245245g42c245g254t425",
  31. "private_key": "-----BEGIN PRIVATE KEY-----\nMIICWgIBAAKBgE1EJDPKM/2wck/CZYCS7F2cXoHXDBhXYtdeV+h70Nk+ABs6scAV\nApYoobJAVpDeL+lutYAwtbscNz5K915DiNEkBf48LhfBWc5ea07OnClOGC9zASja\nif6ujIdhbITaNat9rdG939gQWqyaDW4wzYfvurhfmxICNgZA1YpWco1HAgMBAAEC\ngYAc+vLtLelEPNsTSWGS0Qiwr8bOwl75/kTHbM5iF5ak9NlLXT9wQTEgKwtC9VjC\nq2OjFXAkLaDsFlAuICYaCBCXn1nUqNoYhaSEQNwGnWIz376letXg/mX+BALSPMFR\nhE6mbdmaL4OV1X8j8uf2VcrLfVFCCZfhPu/TM5D6bVFYoQJBAJRHNKYU/csAB/NE\nzScJBv7PltOAoYpxbyFZb1rWcV9mAn34382b0YBXbp3Giqvifs/teudUbRpAzzLm\n5gr8tzECQQCFZh4tNIzeZZYUqkQxrxgqnnONey1hX7K+BlGyC6n2o26sE+I7cLij\n2kbuWoSFMAIdM2Hextv9k+ZrwUas4V33AkAfi9Korvib0sLeP7oB3wrM9W9aShiU\nMrP4/WUSh2MRb8uB74v123vD+VYAXTgtf3+JTzYBt1WK61TpuHQizEdRAkBjt8hL\nBoNfJBUicXz0nuyzvyql0jREG+NjhRnAvFNbGSR74Yk14bdEVMC9IFD7tr190pEQ\nlRqR3eNbHWmVhgpVAkBgveeM73R1tFXS6UosBtfDI1zut44Ce0RoADOIxjXqgjOi\nXSrevYvoKCl09yhLNAnKD+QvT/YbshW/jibYXwdj\n-----END PRIVATE KEY-----",
  32. "client_email": "service-name@my-project.iam.gserviceaccount.com",
  33. "client_id": "13451345134513451345",
  34. "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  35. "token_uri": "https://oauth2.googleapis.com/token",
  36. "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  37. "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/service-name%40my-project.iam.gserviceaccount.com"
  38. }
  39. Providing access credentials through environment variables
  40. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  41. The following environment variables must be set, depending on the provider in use.
  42. **Amazon**
  43. =================== ==================
  44. Mandatory variables Optional Variables
  45. =================== ==================
  46. AWS_ACCESS_KEY
  47. AWS_SECRET_KEY
  48. =================== ==================
  49. **Openstack**
  50. =================== ==================
  51. Mandatory variables Optional Variables
  52. =================== ==================
  53. OS_AUTH_URL NOVA_SERVICE_NAME
  54. OS_USERNAME OS_COMPUTE_API_VERSION
  55. OS_PASSWORD OS_VOLUME_API_VERSION
  56. OS_PROJECT_NAME OS_STORAGE_URL
  57. OS_REGION_NAME OS_AUTH_TOKEN
  58. =================== ==================
  59. **Microsoft Azure**
  60. Note that managing resources in Azure requires a Resource Group. If a
  61. Resource Group is not provided as part of the configuration, cloudbridge will
  62. attempt to create a Resource Group using the given credentials. This
  63. operation will happen with the client initialization, and requires a
  64. "contributor" or "owner" role.
  65. Similarly, a Storage Account is required when managing some resources, such
  66. as KeyPairs and Buckets. If a Storage Account name is not provided as part
  67. of the configuration, cloudbridge will attempt to create the Storage Account
  68. when initializing the relevant services. This operation similarly requires a
  69. "contributor" or "owner" role.
  70. For more information on roles, see: https://docs.microsoft.com/en-us/azure/role-based-access-control/overview
  71. ====================== ==================
  72. Mandatory variables Optional Variables
  73. ====================== ==================
  74. AZURE_SUBSCRIPTION_ID AZURE_REGION_NAME
  75. AZURE_CLIENT_ID AZURE_RESOURCE_GROUP
  76. AZURE_SECRET AZURE_STORAGE_ACCOUNT
  77. AZURE_TENANT AZURE_VM_DEFAULT_USER_NAME
  78. AZURE_PUBLIC_KEY_STORAGE_TABLE_NAME
  79. ====================== ==================
  80. **Google**
  81. ======================= ==================
  82. Mandatory variables Optional Variables
  83. ======================= ==================
  84. GCE_SERVICE_CREDS_FILE GCE_PROJECT_NAME
  85. or GCE_DEFAULT_ZONE
  86. GCE_SERVICE_CREDS_DICT GCE_REGION_NAME
  87. ======================= ==================
  88. Once the environment variables are set, you can create a connection as follows:
  89. .. code-block:: python
  90. from cloudbridge.cloud.factory import CloudProviderFactory, ProviderList
  91. provider = CloudProviderFactory().create_provider(ProviderList.OPENSTACK, {})
  92. Providing access credentials through a dictionary
  93. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  94. You can initialize a simple config as follows. The key names are the same
  95. as the environment variables, in lower case. Note that the config dictionary
  96. will override environment values.
  97. .. code-block:: python
  98. from cloudbridge.cloud.factory import CloudProviderFactory, ProviderList
  99. config = {'aws_access_key' : '<your_access_key>',
  100. 'aws_secret_key' : '<your_secret_key>'}
  101. provider = CloudProviderFactory().create_provider(ProviderList.AWS, config)
  102. ## For Azure
  103. config = {'azure_subscription_id': '<your_subscription_id>',
  104. 'azure_client_id': '<your_client_id>',
  105. 'azure_secret': '<your_secret>',
  106. 'azure_tenant': '<your_tenant>',
  107. 'azure_resource_group': '<your resource group>'}
  108. provider = CloudProviderFactory().create_provider(ProviderList.AZURE, config)
  109. Some optional configuration values can only be provided through the config
  110. dictionary. These are listed below for each provider.
  111. **CloudBridge**
  112. ==================== ==================
  113. Variable Description
  114. ==================== ==================
  115. default_result_limit Number of results that a ``.list()`` method should return.
  116. Defaults to 50.
  117. ==================== ==================
  118. **Amazon**
  119. ==================== ==================
  120. Variable Description
  121. ==================== ==================
  122. aws_session_token Session key for your AWS account (if using temporary
  123. credentials).
  124. ec2_is_secure True to use an SSL connection. Default is ``True``.
  125. ec2_region_name Default region name. Defaults to ``us-east-1``.
  126. ec2_region_endpoint Endpoint to use. Default is ``ec2.us-east-1.amazonaws.com``.
  127. ec2_port EC2 connection port. Does not need to be specified unless
  128. EC2 service is running on an alternative port.
  129. ec2_conn_path Connection path. Defaults to ``/``.
  130. ec2_validate_certs Whether to use SSL certificate verification. Default is
  131. ``False``.
  132. s3_is_secure True to use an SSL connection. Default is ``True``.
  133. s3_host Host connection endpoint. Default is ``s3.amazonaws.com``.
  134. s3_port Host connection port. Does not need to be specified unless
  135. S3 service is running on an alternative port.
  136. s3_conn_path Connection path. Defaults to ``/``.
  137. s3_validate_certs Whether to use SSL certificate verification. Default is
  138. ``False``.
  139. ==================== ==================
  140. Providing access credentials in a file
  141. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  142. CloudBridge can also read credentials from a file on your local file system.
  143. The file should be placed in one of two locations: ``/etc/cloudbridge.ini`` or
  144. ``~/.cloudbridge``. Each set of credentials should be delineated with the
  145. provider ID (e.g., ``openstack``, ``aws``, ``azure``, ``gce``) with the
  146. necessary credentials being supplied in YAML format. Note that only one set
  147. of credentials per cloud provider type can be supplied (i.e., via this
  148. method, it is not possible to provide credentials for two different
  149. OpenStack clouds).
  150. .. code-block:: bash
  151. [openstack]
  152. os_username: username
  153. os_password: password
  154. os_auth_url: auth url
  155. os_user_domain_name: user domain name
  156. os_project_domain_name: project domain name
  157. os_project_name: project name
  158. [aws]
  159. aws_access_key: access key
  160. aws_secret_key: secret key
  161. Other configuration variables
  162. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  163. In addition to the provider specific configuration variables above, there are
  164. some general configuration environment variables that apply to CloudBridge as
  165. a whole
  166. =========================== ===================================================
  167. Variable Description
  168. =========================== ===================================================
  169. CB_DEBUG Setting ``CB_DEBUG=True`` will cause detailed debug
  170. output to be printed for each provider (including
  171. HTTP traces).
  172. CB_USE_MOCK_PROVIDERS Setting this to ``True`` will cause the CloudBridge
  173. test suite to use mock drivers when available.
  174. CB_TEST_PROVIDER Set this value to a valid :class:`.ProviderList`
  175. value such as ``aws``, to limit tests to that
  176. provider only.
  177. CB_DEFAULT_SUBNET_LABEL Name to be used for a subnet that will be
  178. considered the 'default' by the library. This
  179. default will be used only in cases there is no
  180. subnet marked as the default by the provider.
  181. CB_DEFAULT_NETWORK_LABEL Name to be used for a network that will be
  182. considered the 'default' by the library. This
  183. default will be used only in cases there is no
  184. network marked as the default by the provider.
  185. CB_DEFAULT_IPV4RANGE The default IPv4 range when creating networks if
  186. one is not provided. This value is also used in
  187. tests.
  188. CB_DEFAULT_SUBNET_IPV4RANGE The default subnet IPv4 range used by CloudBridge
  189. if one is not specified by the user. Tests do not
  190. respect this variable.
  191. =========================== ===================================================