{"id":8197,"date":"2015-06-01T10:29:03","date_gmt":"2015-06-01T08:29:03","guid":{"rendered":"http:\/\/blog.zhaw.ch\/icclab\/?p=8197"},"modified":"2015-08-27T13:47:25","modified_gmt":"2015-08-27T11:47:25","slug":"quota-management-in-openstack","status":"publish","type":"post","link":"https:\/\/blog.zhaw.ch\/icclab\/quota-management-in-openstack\/","title":{"rendered":"Quota Management in Openstack"},"content":{"rendered":"<p><em>[Note: This blog post was originally published on the XiFi blog <a href=\"https:\/\/blog.fi-xifi.eu\/quota-management-in-openstack\/\">here<\/a>.]<\/em><\/p>\n<p>One of the main jobs performed by\u00a0the Infrastructures in XiFi is to manage quotas: the resources available are not infinite and consequently resource management is necessary. In <a href=\"http:\/\/www.openstack.org\/\">Openstack<\/a> this is done through quotas. Here we discuss how we work with them\u00a0in Openstack.<\/p>\n<p><!--more--><\/p>\n<p>The main modus operandi of the Infrastructures is via command line &#8211; the attractive browser based tools developed within XiFi are primarily for the end users: the Infrastuctures typically spend their time in the trenches working with command line tools. Hence, quota management is done via command line tools.<\/p>\n<p><a href=\"https:\/\/access.redhat.com\/documentation\/en-US\/Red_Hat_Enterprise_Linux_OpenStack_Platform\/4\/html\/Administration_User_Guide\/cli_set_quotas.html\">Quotas<\/a> naturally arise in many areas within Openstack; indeed, each of the major components has its own quotas and quota management. For example, <a href=\"https:\/\/wiki.openstack.org\/wiki\/Nova\">Nova<\/a> has its own quotas, <a href=\"https:\/\/wiki.openstack.org\/wiki\/Neutron\">Neutron<\/a> has its own quotas, <a href=\"https:\/\/wiki.openstack.org\/wiki\/Cinder\">Cinder<\/a> has its own quotas etc. Further, as each of these projects has evolved separately, the quota management mechanisms have slightly different syntax and worse, there is some overlap between the quotas in some cases which can lead to confusion: for example, Nova quotas contain floating IPs (for the older Nova network solution) as does Neutron.<\/p>\n<p>In XiFi, the main resources we deal with are instances, cores, RAM and floating IPs. Also, most of the nodes have Neutron deployed. In this context, then, the quota management can be done simply using the following Nova and Neutron commands:<\/p>\n<pre>nova quota-update --instances &lt;INSTANCES&gt; --cores &lt;CORES&gt; --ram &lt;RAM&gt; \u00a0--floating-ips &lt;FIPs&gt; &lt;PROJECTID&gt;\u00a0\r\nneutron quota-update --floatingip &lt;FIPs&gt; \u00a0--tenant-id\u00a0&lt;PROJECTID&gt;<\/pre>\n<p>Being dynamic\u00a0administrators who strongly embrace the DevOps approach, we decided to write some basic scripts to support modification of quotas (this was emphatically not because we could not remember the syntax of the above commands!).<\/p>\n<p>This proved less trivial than we thought as the documentation for the python libraries for quota management in Openstack is limited at best. Here we highlight some of the points relating to using quotas programmatically in Openstack.<\/p>\n<p>Quotas are managed through the Nova and Neutron clients. Consequently, these must be initialized using the standard approaches.<\/p>\n<pre>from neutronclient.neutron import client as neutronc\r\nfrom novaclient import client as novac\r\n\r\nneutron = neutronc.Client('2.0',\r\n    auth_url=os.environ['OS_AUTH_URL'],\r\n    tenant_name=os.environ['OS_TENANT_NAME'],\r\n    username=os.environ['OS_USERNAME'],\r\n    password=os.environ['OS_PASSWORD'],\r\n    region_name=os.environ['OS_REGION_NAME'])\r\nnova = novac.Client('2', auth_url=os.environ['OS_AUTH_URL'],\r\n    tenant_id=os.environ['OS_TENANT_ID'],\r\n    username=os.environ['OS_USERNAME'],\r\n    api_key=os.environ['OS_PASSWORD'],\r\n    region_name=os.environ['OS_REGION_NAME'])<\/pre>\n<p>Nova quotas can be obtained for a specific project as follows (they are returned as a QuerySet object) &#8211; note that this assumes administrator access in the openrc:<\/p>\n<pre>nova_qs = nova.quotas.get(project_id)\r\n#print nova_qs<\/pre>\n<p>Neutron is slightly different:<\/p>\n<pre>neutron_qs = neutron.show_quota(project_id)\r\n#print neutron_qs<\/pre>\n<p>and the return value is a <a href=\"https:\/\/docs.python.org\/2\/library\/stdtypes.html#dict\">dict<\/a> which contains one entry called &#8216;quota&#8217; which itself is a dict containing the quota elements.<\/p>\n<p>Printing this is straightforward in python &#8211; one thing to note is that the QuerySet object for Nova supports a to_dict transformation, so printing the quota info can be done as follows:<\/p>\n<pre>nova_qs = nova.quotas.get(project_id).to_dict()\r\nprint 'Nova quota for project '+project_id\r\nfor k,v in nova_qs.iteritems():\r\n    print ' '+str(k)+': '+str(v)<\/pre>\n<p>Nova and Neutron have slightly different mechanisms to support update of quotas. In Nova, named parameters are passed to the update() function, such that the names match exactly the names in the quota. In Neutron, a dict is passed similar to the dict which is returned from the show_quotas() function. Here is how it looks:<\/p>\n<pre>nova_qs = nova.quotas.update(project_id,\r\n    instances=q_info['instances'], cores=q_info['cores'],\r\n    floating_ips=q_info['public_ips'])\r\n#print 'neutron - floatingips()'\r\nneutron_qs = neutron.update_quota(project_id, {'quota'\r\n    {'floatingip': q_info['public_ips'] }})<\/pre>\n<p>We put these basic building blocks into a script which we use to modify the quotas on our systems. More on <a href=\"http:\/\/pastebin.com\/Y2YLFpVg\">pastebin<\/a> if you&#8217;re interested.<\/p>\n<div class=\"pt-sm\">Schlagw\u00f6rter: <a href=\"https:\/\/blog.zhaw.ch\/icclab\/tag\/openstack\/\">openstack<\/a>, <a href=\"https:\/\/blog.zhaw.ch\/icclab\/tag\/quota-management\/\">quota management<\/a>, <a href=\"https:\/\/blog.zhaw.ch\/icclab\/tag\/quotas\/\">quotas<\/a><br><\/div>","protected":false},"excerpt":{"rendered":"<p>[Note: This blog post was originally published on the XiFi blog here.] One of the main jobs performed by\u00a0the Infrastructures in XiFi is to manage quotas: the resources available are not infinite and consequently resource management is necessary. In Openstack this is done through quotas. Here we discuss how we work with them\u00a0in Openstack. Schlagw\u00f6rter: [&hellip;]<\/p>\n","protected":false},"author":92,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[5,15,21],"tags":[240,612,611],"features":[],"class_list":["post-8197","post","type-post","status-publish","format-standard","hentry","category-articles","category-howtos","category-openstack-2","tag-openstack","tag-quota-management","tag-quotas"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Quota Management in Openstack - Service Engineering (ICCLab &amp; SPLab)<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blog.zhaw.ch\/icclab\/quota-management-in-openstack\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Quota Management in Openstack\" \/>\n<meta property=\"og:description\" content=\"[Note: This blog post was originally published on the XiFi blog here.] One of the main jobs performed by\u00a0the Infrastructures in XiFi is to manage quotas: the resources available are not infinite and consequently resource management is necessary. In Openstack this is done through quotas. Here we discuss how we work with them\u00a0in Openstack. Schlagw\u00f6rter: [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blog.zhaw.ch\/icclab\/quota-management-in-openstack\/\" \/>\n<meta property=\"og:site_name\" content=\"Service Engineering (ICCLab &amp; SPLab)\" \/>\n<meta property=\"article:published_time\" content=\"2015-06-01T08:29:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2015-08-27T11:47:25+00:00\" \/>\n<meta name=\"author\" content=\"Sean Murphy\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sean Murphy\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/blog.zhaw.ch\/icclab\/quota-management-in-openstack\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/blog.zhaw.ch\/icclab\/quota-management-in-openstack\/\"},\"author\":{\"name\":\"Sean Murphy\",\"@id\":\"https:\/\/blog.zhaw.ch\/icclab\/#\/schema\/person\/c87a6eef7e1f4a152aeec5f8b9527b8d\"},\"headline\":\"Quota Management in Openstack\",\"datePublished\":\"2015-06-01T08:29:03+00:00\",\"dateModified\":\"2015-08-27T11:47:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/blog.zhaw.ch\/icclab\/quota-management-in-openstack\/\"},\"wordCount\":499,\"commentCount\":0,\"keywords\":[\"openstack\",\"quota management\",\"quotas\"],\"articleSection\":[\"Articles\",\"HowTos\",\"OpenStack\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/blog.zhaw.ch\/icclab\/quota-management-in-openstack\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/blog.zhaw.ch\/icclab\/quota-management-in-openstack\/\",\"url\":\"https:\/\/blog.zhaw.ch\/icclab\/quota-management-in-openstack\/\",\"name\":\"Quota Management in Openstack - Service Engineering (ICCLab &amp; SPLab)\",\"isPartOf\":{\"@id\":\"https:\/\/blog.zhaw.ch\/icclab\/#website\"},\"datePublished\":\"2015-06-01T08:29:03+00:00\",\"dateModified\":\"2015-08-27T11:47:25+00:00\",\"author\":{\"@id\":\"https:\/\/blog.zhaw.ch\/icclab\/#\/schema\/person\/c87a6eef7e1f4a152aeec5f8b9527b8d\"},\"breadcrumb\":{\"@id\":\"https:\/\/blog.zhaw.ch\/icclab\/quota-management-in-openstack\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blog.zhaw.ch\/icclab\/quota-management-in-openstack\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/blog.zhaw.ch\/icclab\/quota-management-in-openstack\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Startseite\",\"item\":\"https:\/\/blog.zhaw.ch\/icclab\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Quota Management in Openstack\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/blog.zhaw.ch\/icclab\/#website\",\"url\":\"https:\/\/blog.zhaw.ch\/icclab\/\",\"name\":\"Service Engineering (ICCLab &amp; SPLab)\",\"description\":\"A Blog of the ZHAW Zurich University of Applied Sciences\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/blog.zhaw.ch\/icclab\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/blog.zhaw.ch\/icclab\/#\/schema\/person\/c87a6eef7e1f4a152aeec5f8b9527b8d\",\"name\":\"Sean Murphy\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/4514cb0ddfe236fd05d5ddb715bc19e1e1e35dafa16bb1b911e6094d278211d6?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4514cb0ddfe236fd05d5ddb715bc19e1e1e35dafa16bb1b911e6094d278211d6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4514cb0ddfe236fd05d5ddb715bc19e1e1e35dafa16bb1b911e6094d278211d6?s=96&d=mm&r=g\",\"caption\":\"Sean Murphy\"},\"url\":\"https:\/\/blog.zhaw.ch\/icclab\/author\/murp\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Quota Management in Openstack - Service Engineering (ICCLab &amp; SPLab)","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blog.zhaw.ch\/icclab\/quota-management-in-openstack\/","og_locale":"en_US","og_type":"article","og_title":"Quota Management in Openstack","og_description":"[Note: This blog post was originally published on the XiFi blog here.] One of the main jobs performed by\u00a0the Infrastructures in XiFi is to manage quotas: the resources available are not infinite and consequently resource management is necessary. In Openstack this is done through quotas. Here we discuss how we work with them\u00a0in Openstack. Schlagw\u00f6rter: [&hellip;]","og_url":"https:\/\/blog.zhaw.ch\/icclab\/quota-management-in-openstack\/","og_site_name":"Service Engineering (ICCLab &amp; SPLab)","article_published_time":"2015-06-01T08:29:03+00:00","article_modified_time":"2015-08-27T11:47:25+00:00","author":"Sean Murphy","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Sean Murphy","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blog.zhaw.ch\/icclab\/quota-management-in-openstack\/#article","isPartOf":{"@id":"https:\/\/blog.zhaw.ch\/icclab\/quota-management-in-openstack\/"},"author":{"name":"Sean Murphy","@id":"https:\/\/blog.zhaw.ch\/icclab\/#\/schema\/person\/c87a6eef7e1f4a152aeec5f8b9527b8d"},"headline":"Quota Management in Openstack","datePublished":"2015-06-01T08:29:03+00:00","dateModified":"2015-08-27T11:47:25+00:00","mainEntityOfPage":{"@id":"https:\/\/blog.zhaw.ch\/icclab\/quota-management-in-openstack\/"},"wordCount":499,"commentCount":0,"keywords":["openstack","quota management","quotas"],"articleSection":["Articles","HowTos","OpenStack"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/blog.zhaw.ch\/icclab\/quota-management-in-openstack\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/blog.zhaw.ch\/icclab\/quota-management-in-openstack\/","url":"https:\/\/blog.zhaw.ch\/icclab\/quota-management-in-openstack\/","name":"Quota Management in Openstack - Service Engineering (ICCLab &amp; SPLab)","isPartOf":{"@id":"https:\/\/blog.zhaw.ch\/icclab\/#website"},"datePublished":"2015-06-01T08:29:03+00:00","dateModified":"2015-08-27T11:47:25+00:00","author":{"@id":"https:\/\/blog.zhaw.ch\/icclab\/#\/schema\/person\/c87a6eef7e1f4a152aeec5f8b9527b8d"},"breadcrumb":{"@id":"https:\/\/blog.zhaw.ch\/icclab\/quota-management-in-openstack\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.zhaw.ch\/icclab\/quota-management-in-openstack\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/blog.zhaw.ch\/icclab\/quota-management-in-openstack\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Startseite","item":"https:\/\/blog.zhaw.ch\/icclab\/"},{"@type":"ListItem","position":2,"name":"Quota Management in Openstack"}]},{"@type":"WebSite","@id":"https:\/\/blog.zhaw.ch\/icclab\/#website","url":"https:\/\/blog.zhaw.ch\/icclab\/","name":"Service Engineering (ICCLab &amp; SPLab)","description":"A Blog of the ZHAW Zurich University of Applied Sciences","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog.zhaw.ch\/icclab\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blog.zhaw.ch\/icclab\/#\/schema\/person\/c87a6eef7e1f4a152aeec5f8b9527b8d","name":"Sean Murphy","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4514cb0ddfe236fd05d5ddb715bc19e1e1e35dafa16bb1b911e6094d278211d6?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4514cb0ddfe236fd05d5ddb715bc19e1e1e35dafa16bb1b911e6094d278211d6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4514cb0ddfe236fd05d5ddb715bc19e1e1e35dafa16bb1b911e6094d278211d6?s=96&d=mm&r=g","caption":"Sean Murphy"},"url":"https:\/\/blog.zhaw.ch\/icclab\/author\/murp\/"}]}},"_links":{"self":[{"href":"https:\/\/blog.zhaw.ch\/icclab\/wp-json\/wp\/v2\/posts\/8197","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.zhaw.ch\/icclab\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.zhaw.ch\/icclab\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.zhaw.ch\/icclab\/wp-json\/wp\/v2\/users\/92"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.zhaw.ch\/icclab\/wp-json\/wp\/v2\/comments?post=8197"}],"version-history":[{"count":2,"href":"https:\/\/blog.zhaw.ch\/icclab\/wp-json\/wp\/v2\/posts\/8197\/revisions"}],"predecessor-version":[{"id":8199,"href":"https:\/\/blog.zhaw.ch\/icclab\/wp-json\/wp\/v2\/posts\/8197\/revisions\/8199"}],"wp:attachment":[{"href":"https:\/\/blog.zhaw.ch\/icclab\/wp-json\/wp\/v2\/media?parent=8197"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.zhaw.ch\/icclab\/wp-json\/wp\/v2\/categories?post=8197"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.zhaw.ch\/icclab\/wp-json\/wp\/v2\/tags?post=8197"},{"taxonomy":"features","embeddable":true,"href":"https:\/\/blog.zhaw.ch\/icclab\/wp-json\/wp\/v2\/features?post=8197"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}