Skip to content

Instantly share code, notes, and snippets.

View Millnert's full-sized avatar

Martin Millnert Millnert

  • BrainMill AB
  • Sweden
View GitHub Profile
@Millnert
Millnert / convert.py
Last active February 19, 2023 08:34
simple glance qcow2->raw conversion
#!/usr/bin/python
""" Glance client to convert QCOW2 images in Glance to RAW """
# from pprint import pprint
from os import environ as env
import collections
import subprocess
# import sys
from glanceclient.v2 import client as glclient
@Millnert
Millnert / _get_endpoint_version-debug.py
Last active September 12, 2016 20:09
debug of openstacksdks 0.9.5 _get_endpoint_version
endpoint = 'https://nova.api.cloud.ipnett.se/v2/<some_tenant_uuid>'
parts = parse.urlparse(endpoint)
if ':' in parts.netloc:
root_endpoint = "://".join([parts.scheme, parts.netloc])
else:
root_endpoint = endpoint
print root_endpoint
# Example
@Millnert
Millnert / test1.py
Created March 5, 2017 10:24
python-rados writes to ec-pool
def put_object(ioctx, diskpath, objprefix):
""" Puts an object from disk, using (objprefix + filename) as key.
Naive code which reads entire object to memory before writing.
"""
bufsize = 2**20 ## 1 MiB
key = objprefix + os.path.basename(diskpath)
offset = 0
sha = hashlib.sha512()
fhd = open(diskpath, 'rb')
@Millnert
Millnert / get_resource.sql
Created May 24, 2017 18:41
Ceilometer (newton) GET /v2/resource/<resource_id> PostgreSQL query optimization
-- A ceilometer (newton) resource query can look like the following:
--SQL: 'SELECT sample.meter_id AS sample_meter_id, meter.name AS meter_name, meter.type AS meter_type, meter.unit AS meter_unit, resource.resource_id AS resource_resource_id, resource.project_id AS resource_project_id, resource.source_id -- AS resource_source_id, resource.user_id AS resource_user_id
-- FROM sample JOIN (SELECT max(sample.id) AS id
-- FROM sample JOIN resource ON resource.internal_id = sample.resource_id
-- WHERE resource.resource_id = %(resource_id_1)s GROUP BY sample.meter_id, resource.resource_id) AS anon_1 ON anon_1.id = sample.id JOIN meter ON meter.id = sample.meter_id JOIN resource ON resource.internal_id = sample.resource_id
-- WHERE resource.resource_id = %(resource_id_2)s']
-- [parameters: {'resource_id_1': u'02c92f6c-6596-489e-a710-0321f3501256', 'resource_id_2': u'02c92f6c-6596-489e-a710-0321f3501256'}
-- In the ceilometer database in question, the sample table has 141M rows and the resource table has 1.2M r
@Millnert
Millnert / test.sql
Created May 24, 2017 20:43
Ceilometer (newton) GET /v2/resource/<resource_id> PostgreSQL query optimization -- debugging original query
ceilometer=# SELECT
ceilometer-# sample.meter_id AS sample_meter_id,
ceilometer-# meter.name AS meter_name,
ceilometer-# meter.type AS meter_type,
ceilometer-# meter.unit AS meter_unit,
ceilometer-# resource.resource_id AS resource_resource_id,
ceilometer-# resource.project_id AS resource_project_id,
ceilometer-# resource.source_id AS resource_source_id,
ceilometer-# resource.user_id AS resource_user_id
ceilometer-# FROM sample
@Millnert
Millnert / recovery.txt
Created May 5, 2018 12:42
ceph recovery when FUBAR (mem / cpu looping crashing OSDs with OOM)
## Stop all OSDs
## Set OSD nodown
ceph osd set nodown
##Set OSD nobackfill
ceph osd set nobackfill
@Millnert
Millnert / recurring_maintenance_windows.py
Last active September 29, 2022 13:55 — forked from lfepp/recurring_maintenance_windows.py
Script to create a number of recurring maintenance windows in PagerDuty
#!/usr/bin/env python3
"""Script to create reoccuring maintenance windows for PagerDuty"""
#
# Copyright (c) 2016, PagerDuty, Inc. <info@pagerduty.com>
# Copyright (c) 2022, BrainMill AB, <info@brainmill.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright