{"id":1624,"date":"2023-03-21T21:17:02","date_gmt":"2023-03-21T21:17:02","guid":{"rendered":"https:\/\/community.5gasp.eu\/?page_id=1624"},"modified":"2023-09-26T14:20:31","modified_gmt":"2023-09-26T14:20:31","slug":"juju-charms-tutorial","status":"publish","type":"page","link":"https:\/\/community.5gasp.eu\/index.php\/juju-charms-tutorial\/","title":{"rendered":"Juju Charms tutorial"},"content":{"rendered":"\n<div style=\"height:2px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Software installation<\/h3>\n\n\n\n<p>Installation of juju and charmcraft:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"887\" height=\"105\" src=\"https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-6.png\" alt=\"\" class=\"wp-image-1626\" srcset=\"https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-6.png 887w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-6-300x36.png 300w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-6-768x91.png 768w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-6-611x72.png 611w\" sizes=\"auto, (max-width: 887px) 100vw, 887px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Creation of the Charm structure<\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"882\" height=\"304\" src=\"https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-7.png\" alt=\"\" class=\"wp-image-1627\" srcset=\"https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-7.png 882w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-7-300x103.png 300w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-7-768x265.png 768w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-7-611x211.png 611w\" sizes=\"auto, (max-width: 882px) 100vw, 882px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>After running these commands, you should have the following structure:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"880\" height=\"285\" src=\"https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-8.png\" alt=\"\" class=\"wp-image-1628\" srcset=\"https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-8.png 880w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-8-300x97.png 300w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-8-768x249.png 768w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-8-611x198.png 611w\" sizes=\"auto, (max-width: 880px) 100vw, 880px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Changing files<\/h3>\n\n\n\n<p>Changing files to create a basic charm<\/p>\n\n\n\n<p><strong>metadata.yaml<\/strong><\/p>\n\n\n\n<p>You should replace the maintainer:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"881\" height=\"291\" src=\"https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-9.png\" alt=\"\" class=\"wp-image-1629\" srcset=\"https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-9.png 881w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-9-300x99.png 300w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-9-768x254.png 768w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-9-611x202.png 611w\" sizes=\"auto, (max-width: 881px) 100vw, 881px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>config.yaml<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"880\" height=\"449\" src=\"https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-10.png\" alt=\"\" class=\"wp-image-1630\" srcset=\"https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-10.png 880w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-10-300x153.png 300w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-10-768x392.png 768w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-10-611x312.png 611w\" sizes=\"auto, (max-width: 880px) 100vw, 880px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>actions.yaml<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"880\" height=\"532\" src=\"https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-11.png\" alt=\"\" class=\"wp-image-1631\" srcset=\"https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-11.png 880w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-11-300x181.png 300w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-11-768x464.png 768w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-11-579x350.png 579w\" sizes=\"auto, (max-width: 880px) 100vw, 880px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>src\/charm.py<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"745\" height=\"1024\" src=\"https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-12-745x1024.png\" alt=\"\" class=\"wp-image-1634\" srcset=\"https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-12-745x1024.png 745w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-12-218x300.png 218w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-12-768x1055.png 768w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-12-255x350.png 255w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-12.png 880w\" sizes=\"auto, (max-width: 745px) 100vw, 745px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>local-config.yaml<\/strong><\/p>\n\n\n\n<p>Keep in mind that you should replace the hostname with your machine, as well as the username and password that you have.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"879\" height=\"143\" src=\"https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-13.png\" alt=\"\" class=\"wp-image-1636\" srcset=\"https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-13.png 879w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-13-300x49.png 300w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-13-768x125.png 768w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-13-611x99.png 611w\" sizes=\"auto, (max-width: 879px) 100vw, 879px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Notes<\/h2>\n\n\n\n<p>Before building the charm you might need to execute the following commands:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ lxd init --auto\n$ lxc network set lxdbr0 ipv6.address none<\/code><\/pre>\n\n\n\n<p>Build the charm:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ charmcraft build<\/code><\/pre>\n\n\n\n<p>Before deploying you might need to choose your controller (In your case should be localhost):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ juju bootstrap<\/code><\/pre>\n\n\n\n<p>Deploying the charm using the configurations in the local-config file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ juju deploy .\/prometheus-node-exporter_ubuntu-20.04-amd64.charm --config local-config.yaml<\/code><\/pre>\n\n\n\n<p>Check status:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ juju status<\/code><\/pre>\n\n\n\n<p>Execute the &#8216;<strong>run<\/strong>&#8216; action to run a command inside the VM\/VNF. You can check your <em>unit_id<\/em> with juju status.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ juju run-action prometheus-node-exporter\/&lt;unit_id&gt; run \"command\"=\"ls -la\" --wait<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Adding the Prometheus Node Metrics Exporter&#8217;s logic<\/h3>\n\n\n\n<p>Update actions.yaml<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"878\" height=\"127\" src=\"https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-14.png\" alt=\"\" class=\"wp-image-1637\" srcset=\"https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-14.png 878w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-14-300x43.png 300w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-14-768x111.png 768w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-14-611x88.png 611w\" sizes=\"auto, (max-width: 878px) 100vw, 878px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Update src\/charm.py<\/p>\n\n\n\n<p><strong>Add needed imports<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"879\" height=\"159\" src=\"https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-15.png\" alt=\"\" class=\"wp-image-1638\" srcset=\"https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-15.png 879w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-15-300x54.png 300w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-15-768x139.png 768w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-15-611x111.png 611w\" sizes=\"auto, (max-width: 879px) 100vw, 879px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Inside the SampleProxyCharm class add the custom actions<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"879\" height=\"207\" src=\"https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-16.png\" alt=\"\" class=\"wp-image-1639\" srcset=\"https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-16.png 879w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-16-300x71.png 300w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-16-768x181.png 768w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-16-611x144.png 611w\" sizes=\"auto, (max-width: 879px) 100vw, 879px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Define the 2 functions inside the class:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"878\" height=\"208\" src=\"https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-17.png\" alt=\"\" class=\"wp-image-1640\" srcset=\"https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-17.png 878w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-17-300x71.png 300w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-17-768x182.png 768w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-17-611x145.png 611w\" sizes=\"auto, (max-width: 878px) 100vw, 878px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Add functions to handle the prometheus:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-18-397x1024.png\" alt=\"\" class=\"wp-image-1641\" style=\"width:544px;height:1403px\" width=\"544\" height=\"1403\" srcset=\"https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-18-397x1024.png 397w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-18-116x300.png 116w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-18-596x1536.png 596w, https:\/\/community.5gasp.eu\/wp-content\/uploads\/2023\/03\/image-18-136x350.png 136w\" sizes=\"auto, (max-width: 544px) 100vw, 544px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Check if charm is working.<\/p>\n\n\n\n<p><strong>Build and deploy the charm again<\/strong>.<\/p>\n\n\n\n<p>First, remove the first charm that we deployed:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ juju remove-application prometheus-node-exporter<\/code><\/pre>\n\n\n\n<p>Using the commands in the first charm, build and deploy.<\/p>\n\n\n\n<p><strong>Run the action for the prometheus that we created<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ juju run-action prometheus-node-exporter\/&lt;unit_id&gt; start-prometheus-exporter --wait<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Useful juju commands<\/h2>\n\n\n\n<p>Delete an application<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ juju remove-application &lt;application_id&gt;<\/code><\/pre>\n\n\n\n<p>Delete a machine<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ juju remove-machine &lt;machine_id&gt;<\/code><\/pre>\n\n\n\n<p>Check deployment logs<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ juju debug-log<\/code><\/pre>\n\n\n\n<p>Continuously observe deployment status<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ juju status \u2013watch 5s<\/code><\/pre>\n\n\n\n<p>Access machine terminal<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ juju ssh &lt;machine_id&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Tutorial materials<\/h2>\n\n\n\n<p>For a better description of the tutorial, you can check our video <a href=\"https:\/\/www.youtube.com\/watch?v=TVNSCDdSj-E\">here<\/a>.<\/p>\n\n\n\n<p>You can also check a PDF version of this tutorial <a href=\"https:\/\/community.5gasp.eu\/wp-content\/uploads\/2022\/02\/Juju_Charms.pdf\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Software installation Installation of juju and charmcraft: Creation of the Charm structure After running these commands, you should have the following structure: Changing files Changing files to create a basic charm metadata.yaml You should replace the maintainer: config.yaml actions.yaml src\/charm.py local-config.yaml Keep in mind that you should replace the hostname [\u2026]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"pg_page_styles":[],"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"ngg_post_thumbnail":0,"footnotes":""},"class_list":["post-1624","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/community.5gasp.eu\/index.php\/wp-json\/wp\/v2\/pages\/1624","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/community.5gasp.eu\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/community.5gasp.eu\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/community.5gasp.eu\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/community.5gasp.eu\/index.php\/wp-json\/wp\/v2\/comments?post=1624"}],"version-history":[{"count":8,"href":"https:\/\/community.5gasp.eu\/index.php\/wp-json\/wp\/v2\/pages\/1624\/revisions"}],"predecessor-version":[{"id":1854,"href":"https:\/\/community.5gasp.eu\/index.php\/wp-json\/wp\/v2\/pages\/1624\/revisions\/1854"}],"wp:attachment":[{"href":"https:\/\/community.5gasp.eu\/index.php\/wp-json\/wp\/v2\/media?parent=1624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}