forked from SA-AWS-DevOps-July24/Training_Documents
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClass_Notes.txt
More file actions
621 lines (361 loc) · 9.44 KB
/
Class_Notes.txt
File metadata and controls
621 lines (361 loc) · 9.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
#######################
Day 46: 10th Oct. 2024
#######################
Fundamentals of Python :::
1. Overview of Python
2. Features, Benefits, Uses of Python
3. Installation and Setup of Python Environment
4. Various Types of Sequencesin Python
5. File Operations
6. Python Functions
7. OOPs Concepts
8. Modules
9. Errors and Exception Handling
10. Python Console based application and Web Application using Flask
11. Deploying and Consuming Python Applications
Shell Scripting ??
Programming Languages ==> Used to Develop Business Applications
(vs)
Scripting Languages ==> Used to perform any process automation
Use-Cases :::
Scripting Languages :::
Common Features or Concepts ???
Integrated Development Environment for Python - IDLE
Pycharm
Visual Studio Code
Validation Program :
The User Credentials -- for login_page
- Involves Database validation
- Programming Languages - Java/C#
Validation Program :
Client Side Scripting
- Scripting Languages
xxxx@yyyy.com
xxxx
xxx#asdf.com
xxx@adfs
Tools -->
Logical Thinking!
Programming/Scripting Logic ????
Python -- Tools
Problem Statement ::
-
What are all the steps involved to Create the program / source code?
Analyze the Requirement
Design the solution
-> Algorithms
- Step-by-Step process to achieve any task
- Written in high-level language. It is independent of any Programming/Scripting Languages
- Algorithms should always be an optimized one
- It should be reusable and easily maintainable
-> PsudoCode
- Step-by-Step process to achieve any task
- It is based on the programming/Scripting Language
-> Program workflow - Flowcharts -- graphical views
Create a program/source code using actual programming/Scripting Language
1.
a = 60
b = 30
c = 87
Which is greatest number ? result is ' c '
Algorithm to find the greatest of these three numbers :
2.
a = 70
b = 40
Swap the number :
==> Output : a = 40 & b = 70
a,b = b,a # Is this valid ?
use new variable c ?
c = a
a = b
b = c
3.
a = *
b = $
Swap a and b :
==> Output : a = $ & b = *
4.
a = *
Print :
*
5. a = *
Print output :
*
* *
* * *
* * * *
* * * * *
6. a = *
Print output :
* * * * *
* * *
*
* * *
* * * * *
7. a = 1
Print output :
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
Working with Python :::
- Install Python # https://www.python.org/downloads/
- Install IDE - Visual Studio Code
Data ::
variable a = 5
variable b = "Hello"
Functions :::
- Function is a collection of variables and commands used to perform any task.
>>>print("Hello") 1000 times ?
Hello
Varibles
==> Local Varibles that are defined within the functions
==> Global Variables that are defined outside the functions
Scope of the Variable is based on the declaration.
z = 100;
print(z) # will work ==> 100
def sum() # Function Definition
{
a = 5
b = 10
print(a) # will work
c = a + b # 15!
global z
print(z) # 100
z = 300
print(z) # 300
}
print(a) # will not work | Function call
print(z) # 300 # Updated data
#######################
Day 47: 14th Oct. 2024
#######################
Python Fundamentals :::
ansible_facts{
os_family : "Debian";
os_Type : "Linux"
}
Email_ID = "asdfasdfa@asdf.com"
Comm_Address = """asdfasdfasdfasd
asdfasdfasdfasdf
adfsdfasdfasdfasdf"""
Var1 = ansible_facts
x = 5
print str1 ==> # Print entire value
Array # Is a group of variables with same name and datatype.
# Each Element in array is identified by an index
# Index are used to uniquely identify the elment in array.
Eg.: a[5] a = {1,2,3,4,5}
a[0] = 1
a[1] = 2
a[4] = 5
In python, we have list that is similar to array
List can have different types of data.
list1 = [1,2,3,"hi","Hello"]
sum(int a, int b)
{
c = a + b
}
List ===> [1,2,"hello"] # Updatable
Set ===> {1,2,3,4} # Unique, Updatable
Tuple ===> (1,2,3,4) # Non-Updatable
Dictionary ===> {key1:value1,key2:value2} # Json file handling
if
{
if
{
if
{
}
}
}
sa-instance1[5] =
resource "aws_instance" "sa-instance1" {
ami = "ami-0dee22c13ea7a9a67"
instance_type = "t2.micro"
key_name = "ali-key"
count = 5
tags = {
Name = "Terrfaorm-TestInstance1"
}
}
resource "aws_instance" "sa-instance2" {
ami = "ami-0dee22c13ea7a9a67"
instance_type = "t2.medium"
key_name = "ali-key"
tags = {
Name = "Terrfaorm-TestInstance1"
}
}
sir in the above resource "aws_instance" "sa-instance1"
can you explain this line?
this is from terraform module
#######################
Day 48: 16th Oct. 2024
#######################
On Visual Studio Code
Install Python extension for Visual Studio Code
x = 5
y = 6
print("Value of x:", x)
print("Value of y:", y)
print(8)
print(x)
x = input("Number: ")
if x < 0 or x > 10:
print("Invalid number")
else:
print("Good choice")
year 2024
months 12
weeks 4
days 7
numbers = [2,3,4,5,6] # index start from 0. i.e., -> i[0]=2,i[1]=3,i[2]=4.....i[4]=6
n=len(numbers) # 5
for(i=0;i<n;i++) # i = 0; 0 < 5 ==> True, print
print(i) # 0,
print(numbers[i]) # 2,
# Add 1 to i ==>
# i = 1; 1 < 5 ==> True, print
# 1,
# 3,
# Add 1 to i ==>
# i = 2; 2 < 5 ==> True, print
# 2,
# 4,
# Add 1 to i ==>
# i = 3; 3 < 5 ==> True, print
# 3,
# 5,
# Add 1 to i ==>
# i = 4; 4 < 5 ==> True, print
# 4,
# 6,
# Add 1 to i ==>
# i = 5; 5 < 5 ==> False, EXIT from loop
list1 = [1,2,3,4,5,6,7,8,9,10]
n=len(list1)
for(i=0;i<n;i++)
print(i)
print(list1[i])
s=list[i] 1
r=s%2
if r = 0
print s
output: {1,2,3,4,5,6,7,8,9,10}
Even Numbers : {2,4,6,8,10}
Object Oriented Programming :
- Class -> Collection of Functions and Variables
- Object -> Instance of Class
Class devOps {
aws() # Modules - Functions
azure()
}
Class devOps1 {
aws()
azure()
}
devOps d;
d.aws()
d.azure()
devOps1 d1;
d1.aws()
d1.azure()
Inheritance ==>
Class1
{
function1()
function2()
}
Class2 : Class1
{
function3()
function4()
}
Class1 obj1
obj1.function1()
obj1.function2()
Class2 obj2
obj2.function1()
obj2.function3()
obj2.function4()
def sum(list):
sum = 0
for e in list:
sum = sum + e
return sum
mylist = [1,2,3,4,5]
print(sum(mylist))
How to develop Web Applications using Python.
s1.json
{
"name" : "XYZ",
"Dept" : "IT"
}
pyconsoleapp1.py
filename = "s1.json"
with open(filename) as f:
lines = f.readlines()
print(lines)
i = 1
for line in lines:
print(str(i) + " " + line),
i = i + 1
py ./pyconsoleapp1.py
Next ::::
Web Application Server -> flask & Django Web Application Framework to develop web apps.
flask WAS
localhost web application
Core Projects ::::
#######################
Day 49: 17th Oct. 2024
#######################
Python Web Application using flask Web Application Server.
Prepare the python project to create web application
Flask WAS
Demo using Python Web Application
Capstone Project Discussion:
1. Python web application :
Open Visual Studio Code
Create Project Folder :
##################################
Folder Structure :
My-WebApp-Project
app.py
templates
sample.html
##################################
Open New Terminal :
Install : Web Application Framework
pip install flask
Create app.py
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def sample():
return render_template("sample.html")
if "__name__" == "__main__":
app.run(debug=True)
Create "templates" folder at root level :::
Create Html files :: eg. sample.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>www.loksaieta.com</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
</head>
<body>
<div class="jumbotron" style="background-color:white">
<img src="https://octodex.github.com/images/spidertocat.png" alt="Spidertocat"
class="img-responsive center-block" style="width:250px"/>
<h2 class="text-center">Hello Everyone</h2>
<p class="text-center"> Python Demo...</p>
</div>
</body>
</html>
set FLASK_APP=sample
python -m flask run
#python boto3 / terraform / cloudformation
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~