{"id":1060,"date":"2022-11-13T21:24:27","date_gmt":"2022-11-13T21:24:27","guid":{"rendered":"https:\/\/blog.thomarite.uk\/?p=1060"},"modified":"2022-11-13T21:27:25","modified_gmt":"2022-11-13T21:27:25","slug":"ccna-devnet-notes","status":"publish","type":"post","link":"https:\/\/blog.thomarite.uk\/index.php\/2022\/11\/13\/ccna-devnet-notes\/","title":{"rendered":"CCNA DevNet Notes"},"content":{"rendered":"\n<p>1) Python Requests status code <a href=\"https:\/\/requests.readthedocs.io\/en\/latest\/user\/quickstart\/#response-status-codes\">checks<\/a>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">r.status_code == requests.codes.ok<\/pre>\n\n\n\n<p>2) Docker publish <a href=\"https:\/\/docs.docker.com\/engine\/reference\/commandline\/run\/#publish-or-expose-port--p---expose\">ports<\/a>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ docker run -p 127.0.0.1:80:8080\/tcp ubuntu bash\n\nThis binds port <strong>8080 of the container<\/strong> to TCP <strong>port 80 on 127.0.0.1 of the host<\/strong> machine. You can also specify udp and sctp ports. The Docker User Guide explains in detail how to manipulate ports in Docker.<\/pre>\n\n\n\n<p>3) HTTP status codes:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1xx informational\n2xx Successful\n 201 created\n 204 no content (post received by server)\n3xx Redirect\n 301 moved permanently - future requests should be directed to the given URI\n 302 found - requested resource resides temporally under a different URI\n 304 not modified\n4xx Client Error\n 400 bad request\n 401 unauthorized (user not authenticated or failed)\n 403 forbidden (need permissions)\n 404 not found\n5xx Server Error\n 500 internal server err - generic error message\n 501 not implemented\n 503 service unavailable<\/pre>\n\n\n\n<p>4) Python dictionary <a href=\"https:\/\/pythonguides.com\/python-dictionary-filter\/\">filters<\/a>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">my_dict = {8:'u',4:'t',9:'z',10:'j',5:'k',3:'s'}\n\n# filter(function,iterables)\nnew_dict = dict(filter(lambda val: val[0] % 3 == 0, my_dict.items()))\n\nprint(\"Filter dictionary:\",new_filt)<\/pre>\n\n\n\n<p>5) HTTP <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Authentication\">Authentication<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Headers\/Authorization#examples\">Basic<\/a>: For\u00a0<code>\"Basic\"<\/code>\u00a0authentication the credentials are constructed by first combining the username and the password with a colon (<code>aladdin:opensesame<\/code>), and then by encoding the resulting string in\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Glossary\/Base64\"><code>base64<\/code><\/a>\u00a0(<code>YWxhZGRpbjpvcGVuc2VzYW1l<\/code>).<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Authorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l\n\n---\nauth_type = 'Basic'\ncreds = '{}:{}'.format(user,pass)\ncreds_b64 = base64.b64encode(creds)\nheader = {'Authorization': '{}{}'.format(auth_type,creds_b64)}<\/pre>\n\n\n\n<p><a href=\"https:\/\/www.rfc-editor.org\/rfc\/rfc6750\">Bearer<\/a>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Authorization: Bearer &lt;TOKEN><\/pre>\n\n\n\n<p>6) &#8220;diff -u file1.txt file2.txt&#8221;. <a href=\"https:\/\/www.geeksforgeeks.org\/diff-command-linux-examples\/\">link1<\/a> <a href=\"https:\/\/phoenixnap.com\/kb\/linux-diff\">link2<\/a><\/p>\n\n\n\n<p>The unified format is an option you can add to display output without any redundant context lines<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ diff -u file1.txt file2.txt                                                                                                            \n--- file1.txt   2018-01-11 10:39:38.237464052 +0000                                                                                              \n+++ file2.txt   2018-01-11 10:40:00.323423021 +0000                                                                                              \n@@ -1,4 +1,4 @@                                                                                                                                  \n cat                                                                                                                                             \n-mv                                                                                                                                              \n-comm                                                                                                                                            \n cp                                                                                                                                              \n+diff                                                                                                                                            \n+comm<\/pre>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<ul class=\"wp-block-list\">\n<li>The first file is indicated by\u00a0&#8212;  <\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The second file is indicated by\u00a0<strong>+++<\/strong>.\u00a0<br><\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The first two lines of this output show us information about\u00a0<strong>file 1<\/strong>\u00a0and\u00a0<strong>file 2<\/strong>. It lists the file name, modification date, and modification time of each of our files, one per line.\u00a0<br><\/li>\n\n\n\n<li><strong>The lines below display the content of the files and how to modify\u00a0<em>file1.txt<\/em>\u00a0to make it identical to\u00a0<em>file2.txt<\/em>.<\/strong><\/li>\n\n\n\n<li><\/li>\n\n\n\n<li><strong><code>-<\/code><\/strong>\u00a0(minus) \u2013 it needs to be deleted from the first file.<br><strong><code>+<\/code><\/strong>\u00a0(plus) \u2013 it needs to be added to the first file.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The next line has two at sign\u00a0<strong>@<\/strong>\u00a0followed by a line range from the first file (in our case lines 1 through 4, separated by a comma) prefixed by<strong> &#8220;-&#8220;<\/strong>\u00a0and then space and then again followed by a line range from the second file prefixed by\u00a0&#8220;<strong>+&#8221;<\/strong>\u00a0and at the end two at sign\u00a0<strong>@<\/strong>. Followed by the file content in output tells us which line remain unchanged and which lines needs to added or deleted(indicated by symbols) in the\u00a0<strong>file 1<\/strong>\u00a0to make it identical to\u00a0<strong>file 2<\/strong>.\u00a0<\/li>\n<\/ul>\n\n\n\n<p>7) Python Testing: <a href=\"https:\/\/realpython.com\/python-testing\/\">Assertions<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">.assertEqual(a, b)\ta == b\n.assertTrue(x)\t        bool(x) is True\n.assertFalse(x)\t        bool(x) is False\n.assertIs(a, b)\t        a is b\n.assertIsNone(x)\tx is None\n.assertIn(a, b)\t        a in b\n.assertIsInstance(a, b)\tisinstance(a, b)\n\n*** .assertIs(), .assertIsNone(), .assertIn(), and .assertIsInstance() all have opposite methods, named .assertIsNot(), and so forth.<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1) Python Requests status code checks: r.status_code == requests.codes.ok 2) Docker publish ports: $ docker run -p 127.0.0.1:80:8080\/tcp ubuntu bash This binds port 8080 of the container to TCP port 80 on 127.0.0.1 of the host machine. You can also specify udp and sctp ports. The Docker User Guide explains in detail how to manipulate &hellip; <a href=\"https:\/\/blog.thomarite.uk\/index.php\/2022\/11\/13\/ccna-devnet-notes\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;CCNA DevNet Notes&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,2,25],"tags":[],"class_list":["post-1060","post","type-post","status-publish","format-standard","hentry","category-automation","category-networks","category-python"],"_links":{"self":[{"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/posts\/1060","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/comments?post=1060"}],"version-history":[{"count":4,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/posts\/1060\/revisions"}],"predecessor-version":[{"id":1064,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/posts\/1060\/revisions\/1064"}],"wp:attachment":[{"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/media?parent=1060"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/categories?post=1060"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.thomarite.uk\/index.php\/wp-json\/wp\/v2\/tags?post=1060"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}