Then use Pthon to write a springboard machine.

Source: Internet
Author: User

1. Demand

Program One:
1. Backstage Management
-Create user and password on Fortress machine (Fortress machine root Package class, UserProfile table)
-. BASHRC
/usr/bin/python3/data/bastion.py
Exit

2. Backstage Management
-Create user and password or public key uploads on the server
-Server account-to-person correlation

Program Two:
3. User Login

-SSH Bastion Machine user name @ Fortress Machine IP
-Get current user os.environ[' users '
-Get the list of hosts for the current user
-Get all users under the selected host
-Select any one user

2. Realization of Ideas

Bastion Machine Execution Flow:

    1. Administrator creates an account for the user on the server (place the public key on the server, or use the username password)
    2. User Login Fortress Machine, enter the Fort machine user name password, the actual current user Management Server list
    3. The user chooses the server and automatically logs in
    4. Perform actions and record user actions at the same time

Note: Configure the. BRASHRC to implement the script automatically after SSH login, such as:/usr/bin/python/home/wupeiqi/menu.py

So the point you need to use:

    1. 1. Use Orm/schema type/sql Expression language/engine/connectionpooling/dialect All components to manipulate the data. Objects are created from the class, objects are converted to SQL, and SQL is executed.
    2. 2, Paramiko module, based on SSH used to connect remote server and perform related operations.

Specific implementation process:

    1. Design Table mechanism
    2. CREATE TABLE structure
    3. Use the Paramiko module to implement SSH connection to the bottom of the springboard machine and perform related operations
    4. Encapsulates the underlying connection as a springboard user's actions on the specified host group and user and logs

3. Table structure Design

1 #!/usr/bin/env python2 #-*-coding:utf-8-*-3 4  fromSQLAlchemyImportCreate_engine, And_, Or_, func, Table5  fromSqlalchemy.ext.declarativeImportDeclarative_base6  fromSQLAlchemyImportColumn, Integer, String, ForeignKey, UniqueConstraint, DateTime7  fromSqlalchemy.ormImportSessionmaker, Relationship8 9Base = Declarative_base ()#generates a Sqlorm base classTen  One  A classHost (Base): -     __tablename__='Host' -id = Column (Integer, Primary_key=true, autoincrement=True) thehostname = Column (String (unique=true), nullable=False) -IP_ADDR = Column (String (+), Unique=true, nullable=False) -Port = Column (Integer, default=22) -  +  - classHostuser (Base): +     __tablename__='Host_user' Aid = Column (Integer, Primary_key=true, autoincrement=True) atUsername = Column (String (unique=true), nullable=False) -Authtypes = [ -('P','Ssh/password'), -('R','Ssh/key'), -     ] -Auth_type = Column (String (16)) inCert = Column (String (255)) -  tohost_id = Column (Integer, ForeignKey ('host.id')) +  -     __table_args__= ( theUniqueConstraint ('host_id','username', name='_host_username_uc'), *     ) $ Panax Notoginseng  - classGroup (Base): the     __tablename__='Group' +id = Column (Integer, Primary_key=true, autoincrement=True) AName = Column (String (), Unique=true, nullable=False) the  +  - classuserprofile (Base): $     __tablename__='User_profile' $id = Column (Integer, Primary_key=true, autoincrement=True) -Username = Column (String (unique=true), nullable=False) -Password = Column (String (255), nullable=False) the  - Wuyi classGroup2userprofile (Base): the     __tablename__='Group_2_user_profile' -id = Column (Integer, Primary_key=true, autoincrement=True) Wuuser_profile_id = Column (Integer, ForeignKey ('user_profile.id')) -group_id = Column (Integer, ForeignKey ('group.id')) About     __table_args__= ( $UniqueConstraint ('user_profile_id','group_id', name='Ux_user_group'), -     ) -  -  A classGroup2hostuser (Base): +     __tablename__='Group_2_host_user' theid = Column (Integer, Primary_key=true, autoincrement=True) -host_user_id = Column (Integer, ForeignKey ('host_user.id')) $group_id = Column (Integer, ForeignKey ('group.id')) the     __table_args__= ( theUniqueConstraint ('group_id','host_user_id', name='Ux_group_host_user'), the     ) the  -  in classUserprofile2hostuser (Base): the     __tablename__='User_profile_2_host_user' theid = Column (Integer, Primary_key=true, autoincrement=True) Abouthost_user_id = Column (Integer, ForeignKey ('host_user.id')) theuser_profile_id = Column (Integer, ForeignKey ('user_profile.id')) the     __table_args__= ( theUniqueConstraint ('user_profile_id','host_user_id', name='Ux_user_host_user'), +     ) -  the Bayi classAuditlog (Base): the     __tablename__='Audit_log' theid = Column (Integer, Primary_key=true, autoincrement=True) -  -Action_choices2 = [ the(U'cmd', u'CMD'), the(U'Login', u'Login'), the(U'Logout', u'Logout'), the     ] -Action_type = Column (String (16)) thecmd = Column (String (255)) theDate =Column (DateTime) theuser_profile_id = Column (Integer, ForeignKey ('user_profile.id'))94host_user_id = Column (Integer, ForeignKey ('host_user.id')) the  theTable Structure Example
Table Structure Design

Then use Pthon to write a springboard machine.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.