{"id":971,"date":"2015-09-16T13:46:11","date_gmt":"2015-09-16T18:46:11","guid":{"rendered":"https:\/\/www.softwareab.net\/wordpress\/?p=971"},"modified":"2016-03-17T11:50:16","modified_gmt":"2016-03-17T16:50:16","slug":"openstack-one-liners","status":"publish","type":"post","link":"https:\/\/www.softwareab.net\/wordpress\/openstack-one-liners\/","title":{"rendered":"OpenStack One-Liners"},"content":{"rendered":"<p>Hi All. Here are some interesting one-liners I&#8217;ve used. Hope they help!<\/p>\n<p>And by &#8220;one-liner&#8221;, of course, I mean &#8220;a bunch of commands all typed on one line&#8221; \ud83d\ude42<\/p>\n<p>All one-liners assume you have sourced in your RC file so that OS_XXX environment variables are set correctly:<\/p>\n<h3>Show all active VMs<\/h3>\n<p>Here&#8217;s a nice little gnarly expression:<\/p>\n<pre><code>\r\nfor j in $(openstack project list -c ID | tail -n +4 | head -n -1 | awk -F'|' '{print $2}'); do _s=$(openstack --os-project-id $j server list | grep '| \\+ACTIVE \\+|' 2>\/dev\/null | sed -e 's# ##g'); [ ! -z \"$_s\" ] && (_n=$(openstack project show $j -c name | grep -e '| \\+name \\+|' | awk -F'|' '{print $3}' | sed -e 's#^ \\+##' -e 's# \\+$##'); echo \"Project $_n ($j)\"; openstack --os-project-id $j server list | grep '| \\+ACTIVE \\+|'); sleep 1; done\r\n<\/code><\/pre>\n<p>Explanation? Iterate over all projects; for each one do a quick server list looking for ACTIVE VMs. Run the result through a <code>sed<\/code> to eliminate whitespace; if there is anything left, we have active servers \ud83d\ude42 We then do a quick lookup on the project ID to get the name (with appropriate calls to trim spaces) and show the project name, ID, and list of active VMs.<\/p>\n<p>Want some output?<\/p>\n<pre><code>\r\n[root@lvosneutr120 scripts(lvosksclu120-rc-admin)]# for j in $(openstack project list -c ID | tail -n +4 | head -n -1 | awk -F'|' '{print $2}'); do _s=$(openstack --os-project-id $j server list | grep '| \\+ACTIVE \\+|' 2>\/dev\/null | sed -e 's# ##g'); [ ! -z \"$_s\" ] && (_n=$(openstack project show $j -c name | grep -e '| \\+name \\+|' | awk -F'|' '{print $3}' | sed -e 's#^ \\+##' -e 's# \\+$##'); echo \"Project $_n ($j)\"; openstack --os-project-id $j server list | grep '| \\+ACTIVE \\+|'); sleep 1; done\r\nProject lmil-microstrategy (07b2183ca75d438ebdecb620acb5b2b8)\r\n| f9057177-cc01-4041-9c05-f8b324c4d2cf | mstrat-05 | ACTIVE | lmil-microstrategy-net=10.0.0.5, 172.20.142.51 |\r\n| bd5cdd5e-d1f6-40f7-821e-aeaf991705a0 | mstrat-03 | ACTIVE | lmil-microstrategy-net=10.0.0.4, 172.20.132.20 |\r\n| 749f2bdb-c351-4218-b8a5-ccb0b0d039c2 | mstrat-04 | ACTIVE | lmil-microstrategy-net=10.0.0.3, 172.20.132.18 |\r\nProject lmil-sadmin-dev (23a18e23522e4f55a08828da48e2b547)\r\n| dda07689-1953-447e-a101-a87cdb8bb3e9 | lvtgodevx100                                 | ACTIVE  | lmil-sadmin-dev-net=10.0.0.199, 172.20.142.102 |\r\n| 18c7c36a-c069-4fc8-8070-3446f859fe8f | test-cobol-example-ServerConfig-mpeqgmghr6ui | ACTIVE  | lmil-sadmin-dev-net=10.0.0.195, 172.20.142.86  |\r\n<\/code><\/pre>\n<p>I&#8217;ve cut off the rest, but you get the idea.<\/p>\n<h3>List permissions for a given user across all projects<\/h3>\n<p>Here&#8217;s the one from today. I am migrating to OpenStack Kilo from Icehouse and I want to kick some of my old users off of the original Icehouse deployment. Keeps &#8217;em from messing things up!! So to do this here&#8217;s my line-liner:<\/p>\n<pre><code>\r\nfor i in $(openstack user list -c ID -c Name | grep \"| <strong>[USER]<\/strong>\" | awk -F'|' '{print $2}'); do l_printed=0; for j in $(openstack project list -c ID | tail -n +4 | head -n -1 | awk -F'|' '{print $2}'); do l_roles=$(openstack user role list --project $j $i); [ \"x$l_roles\" != \"x\" ] && ( [ \"$l_printed\" -eq 0 ] && l_printed=1 && echo \"Project: $j\" && echo \"User: $i\"; openstack user role list --project $j $i; ) done; done\r\n<\/code><\/pre>\n<p><em>What it does&#8230;<\/em> We start by iterating over all of the users and looking for the name of our user. We then iterate over all projects and do a lookup of user roles assigned to that user within each project. Due to a bug in <code>openstack<\/code>, if a user has no roles then a blank line is printed by <code>openstack user role list --project $j $i<\/code> so we capture it and test for it being non-empty (<code>bash<\/code> gets rid of whitespace for us by default). We then print out the results so we can easily run the <code>openstack role remove<\/code> command using the output.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi All. Here are some interesting one-liners I&#8217;ve used. Hope they help! And by &#8220;one-liner&#8221;, of course, I mean &#8220;a bunch of commands all typed on one line&#8221; \ud83d\ude42 All one-liners assume you have sourced in your RC file so &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.softwareab.net\/wordpress\/openstack-one-liners\/\"> <span class=\"screen-reader-text\">OpenStack One-Liners<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69,1],"tags":[86,22,18,71],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>OpenStack One-Liners - softwareab<\/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:\/\/www.softwareab.net\/wordpress\/openstack-one-liners\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"OpenStack One-Liners - softwareab\" \/>\n<meta property=\"og:description\" content=\"Hi All. Here are some interesting one-liners I&#8217;ve used. Hope they help! And by &#8220;one-liner&#8221;, of course, I mean &#8220;a bunch of commands all typed on one line&#8221; \ud83d\ude42 All one-liners assume you have sourced in your RC file so &hellip; OpenStack One-Liners Read More &raquo;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.softwareab.net\/wordpress\/openstack-one-liners\/\" \/>\n<meta property=\"og:site_name\" content=\"softwareab\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/cloudraticsolutions\/\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/cloudraticsolutions\/\" \/>\n<meta property=\"article:published_time\" content=\"2015-09-16T18:46:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-03-17T16:50:16+00:00\" \/>\n<meta name=\"author\" content=\"Andrew Bruce\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@realcloudratics\" \/>\n<meta name=\"twitter:site\" content=\"@realcloudratics\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Andrew Bruce\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.softwareab.net\/wordpress\/openstack-one-liners\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.softwareab.net\/wordpress\/openstack-one-liners\/\"},\"author\":{\"name\":\"Andrew Bruce\",\"@id\":\"https:\/\/www.softwareab.net\/wordpress\/#\/schema\/person\/1337443eaeb75104e0410b508e67f600\"},\"headline\":\"OpenStack One-Liners\",\"datePublished\":\"2015-09-16T18:46:11+00:00\",\"dateModified\":\"2016-03-17T16:50:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.softwareab.net\/wordpress\/openstack-one-liners\/\"},\"wordCount\":280,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.softwareab.net\/wordpress\/#\/schema\/person\/1337443eaeb75104e0410b508e67f600\"},\"keywords\":[\"OpenStack\",\"scripting\",\"sysadmin\",\"virtualization\"],\"articleSection\":[\"OpenStack\",\"Teknocratica\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.softwareab.net\/wordpress\/openstack-one-liners\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.softwareab.net\/wordpress\/openstack-one-liners\/\",\"url\":\"https:\/\/www.softwareab.net\/wordpress\/openstack-one-liners\/\",\"name\":\"OpenStack One-Liners - softwareab\",\"isPartOf\":{\"@id\":\"https:\/\/www.softwareab.net\/wordpress\/#website\"},\"datePublished\":\"2015-09-16T18:46:11+00:00\",\"dateModified\":\"2016-03-17T16:50:16+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.softwareab.net\/wordpress\/openstack-one-liners\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.softwareab.net\/wordpress\/openstack-one-liners\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.softwareab.net\/wordpress\/openstack-one-liners\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.softwareab.net\/wordpress\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"OpenStack\",\"item\":\"https:\/\/www.softwareab.net\/wordpress\/tag\/openstack\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"OpenStack One-Liners\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.softwareab.net\/wordpress\/#website\",\"url\":\"https:\/\/www.softwareab.net\/wordpress\/\",\"name\":\"softwareab\",\"description\":\"Technocratica, Technopolitik, Technophobia\",\"publisher\":{\"@id\":\"https:\/\/www.softwareab.net\/wordpress\/#\/schema\/person\/1337443eaeb75104e0410b508e67f600\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.softwareab.net\/wordpress\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.softwareab.net\/wordpress\/#\/schema\/person\/1337443eaeb75104e0410b508e67f600\",\"name\":\"Andrew Bruce\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.softwareab.net\/wordpress\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/www.softwareab.net\/wordpress\/wp-content\/uploads\/2024\/03\/andy-cartoon.jpg\",\"contentUrl\":\"https:\/\/www.softwareab.net\/wordpress\/wp-content\/uploads\/2024\/03\/andy-cartoon.jpg\",\"width\":400,\"height\":330,\"caption\":\"Andrew Bruce\"},\"logo\":{\"@id\":\"https:\/\/www.softwareab.net\/wordpress\/#\/schema\/person\/image\/\"},\"description\":\"Team-oriented systems mentor with deep knowledge of numerous software methodologies, technologies, languages, and operating systems. Excited about turning emerging technology into working production-ready systems. Focused on moving software teams to a higher level of world-class application development. Specialties:Software analysis and development...Product management through the entire lifecycle...Discrete product integration specialist!\",\"sameAs\":[\"http:\/\/cloudraticsolutions.net\/\",\"https:\/\/www.facebook.com\/cloudraticsolutions\/\",\"https:\/\/twitter.com\/realcloudratics\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"OpenStack One-Liners - softwareab","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:\/\/www.softwareab.net\/wordpress\/openstack-one-liners\/","og_locale":"en_US","og_type":"article","og_title":"OpenStack One-Liners - softwareab","og_description":"Hi All. Here are some interesting one-liners I&#8217;ve used. Hope they help! And by &#8220;one-liner&#8221;, of course, I mean &#8220;a bunch of commands all typed on one line&#8221; \ud83d\ude42 All one-liners assume you have sourced in your RC file so &hellip; OpenStack One-Liners Read More &raquo;","og_url":"https:\/\/www.softwareab.net\/wordpress\/openstack-one-liners\/","og_site_name":"softwareab","article_publisher":"https:\/\/www.facebook.com\/cloudraticsolutions\/","article_author":"https:\/\/www.facebook.com\/cloudraticsolutions\/","article_published_time":"2015-09-16T18:46:11+00:00","article_modified_time":"2016-03-17T16:50:16+00:00","author":"Andrew Bruce","twitter_card":"summary_large_image","twitter_creator":"@realcloudratics","twitter_site":"@realcloudratics","twitter_misc":{"Written by":"Andrew Bruce","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.softwareab.net\/wordpress\/openstack-one-liners\/#article","isPartOf":{"@id":"https:\/\/www.softwareab.net\/wordpress\/openstack-one-liners\/"},"author":{"name":"Andrew Bruce","@id":"https:\/\/www.softwareab.net\/wordpress\/#\/schema\/person\/1337443eaeb75104e0410b508e67f600"},"headline":"OpenStack One-Liners","datePublished":"2015-09-16T18:46:11+00:00","dateModified":"2016-03-17T16:50:16+00:00","mainEntityOfPage":{"@id":"https:\/\/www.softwareab.net\/wordpress\/openstack-one-liners\/"},"wordCount":280,"commentCount":0,"publisher":{"@id":"https:\/\/www.softwareab.net\/wordpress\/#\/schema\/person\/1337443eaeb75104e0410b508e67f600"},"keywords":["OpenStack","scripting","sysadmin","virtualization"],"articleSection":["OpenStack","Teknocratica"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.softwareab.net\/wordpress\/openstack-one-liners\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.softwareab.net\/wordpress\/openstack-one-liners\/","url":"https:\/\/www.softwareab.net\/wordpress\/openstack-one-liners\/","name":"OpenStack One-Liners - softwareab","isPartOf":{"@id":"https:\/\/www.softwareab.net\/wordpress\/#website"},"datePublished":"2015-09-16T18:46:11+00:00","dateModified":"2016-03-17T16:50:16+00:00","breadcrumb":{"@id":"https:\/\/www.softwareab.net\/wordpress\/openstack-one-liners\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.softwareab.net\/wordpress\/openstack-one-liners\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.softwareab.net\/wordpress\/openstack-one-liners\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.softwareab.net\/wordpress\/"},{"@type":"ListItem","position":2,"name":"OpenStack","item":"https:\/\/www.softwareab.net\/wordpress\/tag\/openstack\/"},{"@type":"ListItem","position":3,"name":"OpenStack One-Liners"}]},{"@type":"WebSite","@id":"https:\/\/www.softwareab.net\/wordpress\/#website","url":"https:\/\/www.softwareab.net\/wordpress\/","name":"softwareab","description":"Technocratica, Technopolitik, Technophobia","publisher":{"@id":"https:\/\/www.softwareab.net\/wordpress\/#\/schema\/person\/1337443eaeb75104e0410b508e67f600"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.softwareab.net\/wordpress\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.softwareab.net\/wordpress\/#\/schema\/person\/1337443eaeb75104e0410b508e67f600","name":"Andrew Bruce","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.softwareab.net\/wordpress\/#\/schema\/person\/image\/","url":"https:\/\/www.softwareab.net\/wordpress\/wp-content\/uploads\/2024\/03\/andy-cartoon.jpg","contentUrl":"https:\/\/www.softwareab.net\/wordpress\/wp-content\/uploads\/2024\/03\/andy-cartoon.jpg","width":400,"height":330,"caption":"Andrew Bruce"},"logo":{"@id":"https:\/\/www.softwareab.net\/wordpress\/#\/schema\/person\/image\/"},"description":"Team-oriented systems mentor with deep knowledge of numerous software methodologies, technologies, languages, and operating systems. Excited about turning emerging technology into working production-ready systems. Focused on moving software teams to a higher level of world-class application development. Specialties:Software analysis and development...Product management through the entire lifecycle...Discrete product integration specialist!","sameAs":["http:\/\/cloudraticsolutions.net\/","https:\/\/www.facebook.com\/cloudraticsolutions\/","https:\/\/twitter.com\/realcloudratics"]}]}},"_links":{"self":[{"href":"https:\/\/www.softwareab.net\/wordpress\/wp-json\/wp\/v2\/posts\/971"}],"collection":[{"href":"https:\/\/www.softwareab.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.softwareab.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.softwareab.net\/wordpress\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.softwareab.net\/wordpress\/wp-json\/wp\/v2\/comments?post=971"}],"version-history":[{"count":4,"href":"https:\/\/www.softwareab.net\/wordpress\/wp-json\/wp\/v2\/posts\/971\/revisions"}],"predecessor-version":[{"id":988,"href":"https:\/\/www.softwareab.net\/wordpress\/wp-json\/wp\/v2\/posts\/971\/revisions\/988"}],"wp:attachment":[{"href":"https:\/\/www.softwareab.net\/wordpress\/wp-json\/wp\/v2\/media?parent=971"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.softwareab.net\/wordpress\/wp-json\/wp\/v2\/categories?post=971"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.softwareab.net\/wordpress\/wp-json\/wp\/v2\/tags?post=971"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}