Tuesday 20 October 2015

Windows 10 Python Django Tutorial - Writing your first app

1)
Create a project


>django-admin startproject mysite

>dir mysite

>dir mysite\mysite

2)
Create default database and tables


>cd mysite

>python manage.py migrate

3)
Check default sqllite3 database "db.sqllite3"


>dir

4)
Verify your Django project.


a)
Run development server
>python manage.py runserver

b)
Goto http://127.0.0.1:8000/



How To Install Python and Virtualenv In Windows 10

1)
INSTALL PYTHON
---------------------------
a)
Goto https://www.python.org/downloads/

b)
Download and Install Python

c)
Open command prompt and type python to verify the installation

2)
INSTALL VIRTUALENV
-------------------------------------
a)
Goto https://pypi.python.org/pypi/virtualenv

b)
download virtualenv-13.1.2.tar.gz (md5, pgp)

c)
Extract "virtualenv-13.1.2.tar.gz"

d)
Open command prompt then cd to following path
>cd C:\Users\anusree\Downloads\dist\virtualenv-13.1.2

e)
Install virtualenv
>python setup.py install


3)
CREATE AND ACTIVATE VIRTUALENVIRONMENT
-----------------------------------------------------------------------------
a)
Create virtualenv named "myenv"
>python -m virtualenv myenv
>dir

b)

Activate virtualenvironment "myenv"
>C:\Users\anusree>.\myenv\Scripts\activate
(myenv) C:\Users\anusree>

Monday 19 October 2015

How to Install Python and Django on Windows 10

1)
INSTALL PYTHON
---------------------------
a)
Goto https://www.python.org/downloads/

b)
Download and Install Python

c)
Open command prompt and type python to verify the installation

2)
INSTALL VIRTUALENV
-------------------------------------
a)
Goto https://pypi.python.org/pypi/virtualenv

b)
download virtualenv-13.1.2.tar.gz (md5, pgp)

c)
Extract "virtualenv-13.1.2.tar.gz"

d)
Open command prompt then cd to following path
>cd C:\Users\anusree\Downloads\dist\virtualenv-13.1.2

e)
Install virtualenv
>python setup.py install


3)
CREATE AND ACTIVATE VIRTUALENVIRONMENT
-----------------------------------------------------------------------------
a)
Create virtualenv named "myenv"
>python -m virtualenv myenv
>dir

b)

Activate virtualenvironment "myenv"
>C:\Users\anusree>.\myenv\Scripts\activate
(myenv) C:\Users\anusree>


4)
INSTALL DJANGO
-----------------------------
a)
Install Django
(myenv) C:\Users\anusree>pip install django
Collecting django
  Downloading Django-1.8.5-py2.py3-none-any.whl (6.2MB)
    100% |################################| 6.2MB 48kB/s
Installing collected packages: django
Successfully installed django-1.8.5
(myenv) C:\Users\anusree>

b)
Verify the installation of Django
(myenv) C:\Users\anusree>python
Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import django
>>>


Sunday 18 October 2015

How to Install Django on Windows 10

1)INSTALL VIRTUALENV
-------------------------------------
a)
goto https://pypi.python.org/pypi/virtualenv

b)
download virtualenv-13.1.2.tar.gz (md5, pgp)

c)
Extract "virtualenv-13.1.2.tar.gz"

d)
Open command prompt then cd to following path
>cd C:\Users\anusree\Downloads\dist\virtualenv-13.1.2

e)
install virtualenv
>python setup.py install





2)CREATE AND ACTIVATE VIRTUALENVIRONMENT
-----------------------------------------------------------------------------

a)
create virtualenv named "myenv"
>python -m virtualenv myenv
>dir

b)
activate virtualenvironment "myenv"
>C:\Users\anusree>.\myenv\Scripts\activate
(myenv) C:\Users\anusree>


3)INSTALL DJANGO
-----------------------------

a)
install Django
(myenv) C:\Users\anusree>pip install django
Collecting django
  Downloading Django-1.8.5-py2.py3-none-any.whl (6.2MB)
    100% |################################| 6.2MB 48kB/s
Installing collected packages: django
Successfully installed django-1.8.5
(myenv) C:\Users\anusree>

b)
verify
(myenv) C:\Users\anusree>python
Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import django
>>>

Saturday 19 September 2015

How to Manage Users and Groups in Linux via Terminal



      How to Manage Users and Groups in Linux via Terminal

 
1)
Add new group named "school"

            anusree@anusree-VirtualBox:~$ sudo groupadd school


2)
List the group that created in above step.

           anusree@anusree-VirtualBox:~$ cat /etc/group


3)
Add two users named "students" and "staffs"

             anusree@anusree-VirtualBox:~$ sudo useradd -m students
             anusree@anusree-VirtualBox:~$ sudo useradd -m staffs
  

-m option is used for crate the home directory at the time of user is created.

4)
List the users that created in the above step.

             anusree@anusree-VirtualBox:~$ cat /etc/passwd


5)
Then, add the existing users "students" and "staffs" to the group "school".

               anusree@anusree-VirtualBox:~$ sudo adduser students school
               Adding user `students' to group `school' ...
               Adding user students to group school
               Done.
               anusree@anusree-VirtualBox:~$ sudo adduser staffs school
               Adding user `staffs' to group `school' ...
               Adding user staffs to group school
               Done.
                anusree@anusree-VirtualBox:~$


After adding users to the group then list the name of groups then we can see the changes..


6)
Delete the user.

              anusree@anusree-VirtualBox:~$ sudo userdel -r students         
              anusree@anusree-VirtualBox:~$ sudo userdel -r staffs

 -r option is used for delete the user with its home directory 

7)
Delete the group.

             anusree@anusree-VirtualBox:~$ sudo groupdel school

Sunday 7 June 2015

How to create a virtual machine using openstack nova python client


1) First create python nova client object

from novaclient.v2 import client
USER = "admin"
PASS = "cloud"
TENANT = "admin"
AUTH_URL = "http://192.168.56.101:5000/v2.0/"
nova_conn = client.Client(USER, PASS, TENANT, AUTH_URL, service_type="compute")

Explanation:

#import client from novaclient.v2, since the class "Client" defined in client.py.
#https://github.com/openstack/python-novaclient/blob/master/novaclient/v2/client.py#L52
from novaclient.v2 import client

#Declare username, password, tenant/project and auth_url
#AUTH_URL tells where the authentication service (keystone) is running.
USER = "admin"
PASS = "cloud"
TENANT = "admin"
AUTH_URL = "http://192.168.56.101:5000/v2.0/"


#Create a object of class Client (create a connection to nova).
nova_conn = client.Client(USER, PASS, TENANT, AUTH_URL, service_type="compute")

 2) Create a vm

a) Find image id:

 >>> [(x.name, x.id) for x in nova_conn.images.list()]

b) Find flavor id:

>>> [(x.name, x.id) for x in nova_conn.flavors.list()]

c) Create a vm named "myvm2"

>>> nova_conn.servers.create("myvm2", "b935b518-8bed-4947-91ae-a2ed78f591e6", "1")
  • b935b518-8bed-4947-91ae-a2ed78f591e6  --->  id of image "newimage"
  • 1 --->  id of flavor "m1.tiny"
d) List all vms

>>> [(x.name,x.id) for x in nova_conn.servers.list()]


3) How to find methods and attributes:

a) Find methods and attribute of "nova_conn".

>>> dir(nova_conn)

 b) Find methods and attribute of "nova_conn.servers".

>>> dir(nova_conn.servers)




 4) How to get help page.

a)find help of "nova_conn.servers.create".

>>> help(nova_conn.servers.create)




Saturday 6 June 2015

Python How to Install and activate Virtualenv



How to Install and activate Virtualenv

1) Install virtualenv


           $ sudo apt-get install python-virualenv


2) Create virtual environment for our project

          $ virtualenv myenv


virtualenv venv will create a folder in the current directory which will contain the Python executable files. The name of virtualenv is "myenv".

3) To begin using the virtual environment, it needs to be activated

           $ source myenv/bin/activate





The name of the current virtual environment will now appear on the left of the prompt.Like this ,

(myenv)anusree@anusree-Inspiron-5547:~/my_project_folder$


If you want to install any python packages inside the virtual environment then do not use the command: "$ sudo apt-get install packagename".

I am going to show you install python package "django" inside the virtual environment "myenv" using command "$ pip install django" and don't  use     "$ sudo" command before "$ pip" command:

            $ pip install django


4) If you are done working in the virtual environment for the moment, you can deactivate it:

$ deactivate


The packages which i am installing into virtual environment "myenv" are stored in "myenv/lib/python2.7/site-packages"

In this screenshot you can see the package "django" i installed.

Wednesday 3 June 2015

OpenStack Keystone Operations Using CLI



Keystone Operations using CLI

1) Create a project

anusreee@anusreee-VirtualBox:~/devstack$ keystone tenant-create --name accounting




Then list of all project using the command:

anusreee@anusreee-VirtualBox:~/devstack$ keystone tenant-list


2) Create a user

 anusreee@anusreee-VirtualBox:~/devstack$ keystone user-create --name mily --pass mily123 --enabled true



Then list all the users using the command :

anusreee@anusreee-VirtualBox:~/devstack$ keystone user-list



3) Add the user "mily" to the project "accounting" with "member" role.

anusreee@anusreee-VirtualBox:~/devstack$ keystone user-role-add --user 4a64febe98c8458990dd1c30914092c8 --role 705cd9b1bd494d83848b8252d3609ddc --tenant 1233d68292f94f8e9f422c47fe7270c


ie: keystone user-role-add --user <user-id> --role <role-id> --tenant <tenant-id>



4)
After add the user "mily" to the project "accounting" with role "member" we have to go to browser and login as the user "mily"




After login:


Monday 1 June 2015

OpenStack CLI Examples



1)
Goto devstack folder
$ cd devstack

2)
Run rejoin_stack.sh to run all services
$ ./rejion_stack.sh

 
* Press "Ctrl" + "A", then press "D" to exit from "rejion_stack.sh" window.

3)
Export OpenStack admin user credentials
$ source openrc admin


 4)
Run some keystone commands
$ keystone tenant-list


$ keystone user-list


$ keystone role-list

 
$ keystone tenant-get <id>


$ keystone user-get <id>


$ keystone role-get <id>


* To see all tenant, user and role related commands
$ keystone --help | grep tenant


$ keystone --help | grep user


$ keystone --help | grep role


* To see all keystone commands
$ keystone --help


5)
Run some nova commands
$ nova list


$ nova show <id>


 $ nova flavor-list


 $ nova flavor-show <id>


* To see all flavor related commands
$ nova --help | grep flavor


* To see all nova commands
$ nova --help


6)
Run some glance commands
$ glance image-list


 $ glance image-show <id>


* To see all glance commands
$ glance --help


7)
Run some cinder commands
$ cinder list


$ cinder show <id>


* To see all cinder commands
$ cinder --help


8)
Run some nova network commands
 $ nova net-list


$ nova net <id>


9)
Goto horizon dashboad
#http://ip-of-machine-where-openstack-is-installed





* Compare outpot of all above commands with what you are seeing in horizon dashboad.