cloud:recipe:coding
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
cloud:recipe:coding [2020/05/14 08:26] – chudler | cloud:recipe:coding [2020/05/14 14:09] – [Sample Configuration File] chudler | ||
---|---|---|---|
Line 2: | Line 2: | ||
This document gives a quick introduction to using the Openstack Python client to discover and consume compute resources. | This document gives a quick introduction to using the Openstack Python client to discover and consume compute resources. | ||
- | Before beginning, get an account as described in the [[ cloud:intro | Introduction ]] | + | Before beginning, get an account as described in the [[ cloud:intro | Introduction ]]. This is the right place to read about writing python scripts. A companion document shows how to use the [[ cloud:cli | Command Line ]]. |
======Installation====== | ======Installation====== | ||
Line 15: | Line 15: | ||
</ | </ | ||
+ | =====Configuration===== | ||
+ | |||
+ | Obtain your configuration from the [[ https:// | ||
+ | |||
+ | Save the clouds.yaml file to the current working directory, or see the [[ https:// | ||
+ | |||
+ | < | ||
+ | USER_CONFIG_DIR | ||
+ | Linux: ~/ | ||
+ | OSX: ~/ | ||
+ | Windows: C: | ||
+ | SITE_CONFIG_DIR | ||
+ | Linux: / | ||
+ | OSX: / | ||
+ | Windows: C: | ||
+ | </ | ||
+ | |||
+ | ====Sample Configuration File==== | ||
+ | < | ||
+ | clouds: | ||
+ | openstack: | ||
+ | auth: | ||
+ | auth_url: https:// | ||
+ | username: " | ||
+ | password: " | ||
+ | project_id: YOUR PROJECT UUID | ||
+ | project_name: | ||
+ | user_domain_name: | ||
+ | region_name: | ||
+ | interface: " | ||
+ | identity_api_version: | ||
+ | </ | ||
+ | |||
+ | The main flaw here is that you are taking risks by storing your University credentials in a file. Instead, you can use the API or web interface to create an Application Credential. For example, | ||
+ | |||
+ | < | ||
+ | openstack application credential create --secret sekret --role member --expiration 2020-10-10: | ||
+ | </ | ||
+ | =====Testing and Usage===== | ||
+ | Ensure you can load the python module | ||
+ | < | ||
+ | python -m openstack version | ||
+ | </ | ||
+ | |||
+ | Check your configuration | ||
+ | < | ||
+ | python -m openstack.config.loader | ||
+ | </ | ||
+ | Check the exact error if one is displayed. For example, if you see | ||
+ | < | ||
+ | keystoneauth1.exceptions.auth_plugins.MissingRequiredOptions: | ||
+ | </ | ||
+ | You have failed to provide a configuration file. This is different from a syntax error, but not so different from a permission problem, for example. | ||
+ | |||
+ | ======Demo Code====== | ||
+ | |||
+ | The following code shows how to create and destroy a server, and obtain information about Networks, Images, and Flavors. Consult the [[ https:// | ||
+ | |||
+ | < | ||
+ | |||
+ | import openstack | ||
+ | from openstack.config import loader | ||
+ | # openstack.enable_logging(True) | ||
+ | config = loader.OpenStackConfig() | ||
+ | cloud = openstack.connect(cloud=' | ||
+ | flavor = cloud.get_flavor_by_ram(2048) | ||
+ | # print(flavor.name) | ||
+ | image = cloud.get_image(' | ||
+ | # cloud.pprint(image) | ||
+ | # network = cloud.network.find_network(' | ||
+ | network = cloud.get_network(' | ||
+ | # cloud.pprint(network) | ||
+ | try: | ||
+ | server = cloud.create_server(' | ||
+ | # cloud.pprint(server) | ||
+ | # cloud.pprint(cloud.get_server(' | ||
+ | cloud.pprint(cloud.get_server(' | ||
+ | finally: | ||
+ | cloud.delete_server(' | ||
+ | </ |
/var/lib/dokuwiki/data/pages/cloud/recipe/coding.txt · Last modified: 2020/05/14 18:32 by chudler