Last active
April 25, 2016 17:48
-
-
Save jd/4c9e89f81c8deb10021311a4cbb8d4ca to your computer and use it in GitHub Desktop.
Hands-on Gnocchi + CK @ OpenStack Summit Newton
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import uuid | |
import logging | |
import os | |
import random | |
import sys | |
from keystoneauth1.identity import v3 | |
from keystoneauth1 import session | |
from keystoneclient.v3 import client as ks | |
from gnocchiclient import client | |
from gnocchiclient import noauth | |
from gnocchiclient import exceptions | |
LOG = logging.getLogger('') | |
LOG.setLevel(logging.DEBUG) | |
requests_log = logging.getLogger("requests") | |
requests_log.setLevel(logging.DEBUG) | |
console = logging.StreamHandler(sys.stderr) | |
LOG.addHandler(console) | |
auth = v3.Password(auth_url='http://localhost:5000/v3', | |
username='gnocchi', | |
password='password', | |
project_name='service', | |
user_domain_id='default', | |
project_domain_id='default') | |
# auth = noauth.GnocchiNoAuthPlugin( | |
# user_id=os.getenv("GNOCCHI_USER_ID"), | |
# project_id=os.getenv("GNOCCHI_PROJECT_ID"), | |
# roles="admin", | |
# endpoint=os.getenv("GNOCCHI_ENDPOINT"), | |
# ) | |
session = session.Session(auth=auth) | |
ks_client = ks.Client(session=session) | |
for user in ks_client.users.get(): | |
if user.name == "summit_user": | |
user_id = user.id | |
break | |
for project in ks_client.projects.get(): | |
if project.name == "summit": | |
project_id = project.id | |
break | |
c = client.Client('1', session=session) | |
try: | |
c.archive_policy.create({ | |
"name": "medium", | |
"definition": | |
[ | |
# 1 minute over 1 hour | |
{"granularity": 60, "points": 60}, | |
# 1 hour over 1 month | |
{"granularity": 3600, "points": 30 * 24}, | |
# 1 day over a year | |
{"granularity": 3600 * 24, "points": 365}, | |
] | |
}) | |
except exceptions.ArchivePolicyAlreadyExists: | |
pass | |
images = [ | |
"foo", | |
"bar", | |
] | |
flavors = [ | |
"fooflavor", | |
"barflavor", | |
] | |
instances = [ | |
c.resource.create("instance", | |
{ | |
"id": str(uuid.uuid4()), | |
"user_id": user_id, | |
"project_id": project_id, | |
"started_at": "2016-04-%02dT12:%02d:00+00:00" % (i, random.randint(0, 29)), | |
"ended_at": "2016-04-%02dT12:%02d:00+00:00" % (i + 1, random.randint(30, 59)), | |
"flavor_id": random.choice(flavors), | |
"host": "compute1", | |
"image_ref": random.choice(images), | |
"display_name": "instance%d" % i, | |
"metrics": | |
{ | |
"memory": {"archive_policy_name": "medium"}, | |
"vcpus": {"archive_policy_name": "medium"}, | |
"cpu": {"archive_policy_name": "medium"}, | |
}, | |
}) | |
for i in range(1, 21) | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment