Git Product home page Git Product logo

airbnb_clone_v2's Introduction

HBNB - The Console

This repository contains the initial stage of a student project to build a clone of the AirBnB website. This stage implements a backend interface, or console, to manage program data. Console commands allow the user to create, update, and destroy objects, as well as manage file storage. Using a system of JSON serialization/deserialization, storage is persistent between sessions.


Repository Contents by Project Task

Tasks Files Description
0: Authors/README File AUTHORS Project authors
1: Pep8 N/A All code is pep8 compliant
2: Unit Testing /tests All class-defining modules are unittested
3. Make BaseModel /models/base_model.py Defines a parent class to be inherited by all model classes
4. Update BaseModel w/ kwargs /models/base_model.py Add functionality to recreate an instance of a class from a dictionary representation
5. Create FileStorage class /models/engine/file_storage.py /models/_ init _.py /models/base_model.py Defines a class to manage persistent file storage system
6. Console 0.0.1 console.py Add basic functionality to console program, allowing it to quit, handle empty lines and ^D
7. Console 0.1 console.py Update the console with methods allowing the user to create, destroy, show, and update stored data
8. Create User class console.py /models/engine/file_storage.py /models/user.py Dynamically implements a user class
9. More Classes /models/user.py /models/place.py /models/city.py /models/amenity.py /models/state.py /models/review.py Dynamically implements more classes
10. Console 1.0 console.py /models/engine/file_storage.py Update the console and file storage system to work dynamically with all classes update file storage


General Use

  1. First clone this repository.

  2. Once the repository is cloned locate the "console.py" file and run it as follows:

/AirBnB_clone$ ./console.py
  1. When this command is run the following prompt should appear:
(hbnb)
  1. This prompt designates you are in the "HBnB" console. There are a variety of commands available within the console program.
Commands
* create - Creates an instance based on given class

* destroy - Destroys an object based on class and UUID

* show - Shows an object based on class and UUID

* all - Shows all objects the program has access to, or all objects of a given class

* update - Updates existing attributes an object based on class name and UUID

* quit - Exits the program (EOF will as well)
Alternative Syntax

Users are able to issue a number of console command using an alternative syntax:

Usage: <class_name>.<command>([<id>[name_arg value_arg]|[kwargs]])

Advanced syntax is implemented for the following commands:

* all - Shows all objects the program has access to, or all objects of a given class

* count - Return number of object instances by class

* show - Shows an object based on class and UUID

* destroy - Destroys an object based on class and UUID

* update - Updates existing attributes an object based on class name and UUID


Examples

Primary Command Syntax

Example 0: Create an object

Usage: create <class_name>

(hbnb) create BaseModel
(hbnb) create BaseModel
3aa5babc-efb6-4041-bfe9-3cc9727588f8
(hbnb)                   
Example 1: Show an object

Usage: show <class_name> <_id>

(hbnb) show BaseModel 3aa5babc-efb6-4041-bfe9-3cc9727588f8
[BaseModel] (3aa5babc-efb6-4041-bfe9-3cc9727588f8) {'id': '3aa5babc-efb6-4041-bfe9-3cc9727588f8', 'created_at': datetime.datetime(2020, 2, 18, 14, 21, 12, 96959), 
'updated_at': datetime.datetime(2020, 2, 18, 14, 21, 12, 96971)}
(hbnb)  
Example 2: Destroy an object

Usage: destroy <class_name> <_id>

(hbnb) destroy BaseModel 3aa5babc-efb6-4041-bfe9-3cc9727588f8
(hbnb) show BaseModel 3aa5babc-efb6-4041-bfe9-3cc9727588f8
** no instance found **
(hbnb)   
Example 3: Update an object

Usage: update <class_name> <_id>

(hbnb) update BaseModel b405fc64-9724-498f-b405-e4071c3d857f first_name "person"
(hbnb) show BaseModel b405fc64-9724-498f-b405-e4071c3d857f
[BaseModel] (b405fc64-9724-498f-b405-e4071c3d857f) {'id': 'b405fc64-9724-498f-b405-e4071c3d857f', 'created_at': datetime.datetime(2020, 2, 18, 14, 33, 45, 729889), 
'updated_at': datetime.datetime(2020, 2, 18, 14, 33, 45, 729907), 'first_name': 'person'}
(hbnb)

Alternative Syntax

Example 0: Show all User objects

Usage: <class_name>.all()

(hbnb) User.all()
["[User] (99f45908-1d17-46d1-9dd2-b7571128115b) {'updated_at': datetime.datetime(2020, 2, 19, 21, 47, 34, 92071), 'id': '99f45908-1d17-46d1-9dd2-b7571128115b', 'created_at': datetime.datetime(2020, 2, 19, 21, 47, 34, 92056)}", "[User] (98bea5de-9cb0-4d78-8a9d-c4de03521c30) {'updated_at': datetime.datetime(2020, 2, 19, 21, 47, 29, 134362), 'id': '98bea5de-9cb0-4d78-8a9d-c4de03521c30', 'created_at': datetime.datetime(2020, 2, 19, 21, 47, 29, 134343)}"]
Example 1: Destroy a User

Usage: <class_name>.destroy(<_id>)

(hbnb) User.destroy("99f45908-1d17-46d1-9dd2-b7571128115b")
(hbnb)
(hbnb) User.all()
(hbnb) ["[User] (98bea5de-9cb0-4d78-8a9d-c4de03521c30) {'updated_at': datetime.datetime(2020, 2, 19, 21, 47, 29, 134362), 'id': '98bea5de-9cb0-4d78-8a9d-c4de03521c30', 'created_at': datetime.datetime(2020, 2, 19, 21, 47, 29, 134343)}"]
Example 2: Update User (by attribute)

Usage: <class_name>.update(<_id>, <attribute_name>, <attribute_value>)

(hbnb) User.update("98bea5de-9cb0-4d78-8a9d-c4de03521c30", name "Todd the Toad")
(hbnb)
(hbnb) User.all()
(hbnb) ["[User] (98bea5de-9cb0-4d78-8a9d-c4de03521c30) {'updated_at': datetime.datetime(2020, 2, 19, 21, 47, 29, 134362), 'id': '98bea5de-9cb0-4d78-8a9d-c4de03521c30', 'name': 'Todd the Toad', 'created_at': datetime.datetime(2020, 2, 19, 21, 47, 29, 134343)}"]
Example 3: Update User (by dictionary)

Usage: <class_name>.update(<_id>, )

(hbnb) User.update("98bea5de-9cb0-4d78-8a9d-c4de03521c30", {'name': 'Fred the Frog', 'age': 9})
(hbnb)
(hbnb) User.all()
(hbnb) ["[User] (98bea5de-9cb0-4d78-8a9d-c4de03521c30) {'updated_at': datetime.datetime(2020, 2, 19, 21, 47, 29, 134362), 'name': 'Fred the Frog', 'age': 9, 'id': '98bea5de-9cb0-4d78-8a9d-c4de03521c30', 'created_at': datetime.datetime(2020, 2, 19, 21, 47, 29, 134343)}"]

# 0x03. AirBnB clone - Deploy static

Learning Objectives

  • What is Fabric
  • How to deploy code to a server easily
  • What is a tgz archive
  • How to execute Fabric command locally
  • How to execute Fabric command remotely
  • How to transfer files with Fabric
  • How to manage Nginx configuration
  • What is the difference between root and alias in a Nginx configuration

Task Descriptions

  • 0-setup_web_static.sh : Write a Bash script that sets up your web servers for the deployment of web_static. It must:
    • Install Nginx if it not already installed
    • Create the folder /data/ if it doesn’t already exist
    • Create the folder /data/web_static/ if it doesn’t already exist
    • Create the folder /data/web_static/releases/ if it doesn’t already exist
    • Create the folder /data/web_static/shared/ if it doesn’t already exist
    • Create the folder /data/web_static/releases/test/ if it doesn’t already exist
    • Create a fake HTML file /data/web_static/releases/test/index.html (with simple content, to test your Nginx configuration)
    • Create a symbolic link /data/web_static/current linked to the /data/web_static/releases/test/ folder. If the symbolic link already exists, it should be deleted and recreated every time the script is ran.
    • Give ownership of the /data/ folder to the ubuntu user AND group (you can assume this user and group exist). This should be recursive; everything inside should be created/owned by this user/group.
    • Update the Nginx configuration to serve the content of /data/web_static/current/ to hbnb_static (ex: https://mydomainname.tech/hbnb_static). Don’t forget to restart Nginx after updating the configuration:
      • Use alias inside your Nginx configuration
    • Your program should always exit successfully. Don’t forget to run your script on both of your web servers.
  • 1-pack_web_static.py : Write a Fabric script that generates a .tgz archive from the contents of the web_static folder of your AirBnB Clone repo, using the function do_pack.
    • Prototype: def do_pack():
    • All files in the folder web_static must be added to the final archive
    • All archives must be stored in the folder versions (your function should create this folder if it doesn’t exist)
    • The name of the archive created must be web_static_.tgz
    • The function do_pack must return the archive path if the archive has been correctly generated. Otherwise, it should return None
  • 2-do_deploy_web_static.py : Write a Fabric script (based on the file 1-pack_web_static.py) that distributes an archive to your web servers, using the function do_deploy:
    • Prototype: def do_deploy(archive_path):
    • Returns False if the file at the path archive_path doesn’t exist
    • The script should take the following steps:
      • Upload the archive to the /tmp/ directory of the web server
      • Uncompress the archive to the folder /data/web_static/releases/ on the web server
      • Delete the archive from the web server
      • Delete the symbolic link /data/web_static/current from the web server
      • Create a new the symbolic link /data/web_static/current on the web server, linked to the new version of your code (/data/web_static/releases/)
    • All remote commands must be executed on your both web servers (using env.hosts = ['', 'IP web-02'] variable in your script)
    • Returns True if all operations have been done correctly, otherwise returns False
    • You must use this script to deploy it on your servers: xx-web-01 and xx-web-02
    • In the following example, the SSH key and the username used for accessing to the server are passed in the command line. Of course, you could define them as Fabric environment variables (ex: env.user =...)
    • Disclaimer: commands execute by Fabric displayed below are linked to the way we implemented the archive function do_pack - like the mv command - depending of your implementation of it, you may don’t need it
  • 3-deploy_web_static.py : Write a Fabric script (based on the file 2-do_deploy_web_static.py) that creates and distributes an archive to your web servers, using the function deploy:
    • Prototype: def deploy():
    • The script should take the following steps:
      • Call the do_pack() function and store the path of the created archive
      • Return False if no archive has been created
      • Call the do_deploy(archive_path) function, using the new path of the new archive
      • Return the return value of do_deploy
    • All remote commands must be executed on both of web your servers (using env.hosts = ['', 'IP web-02'] variable in your script)
    • You must use this script to deploy it on your servers: xx-web-01 and xx-web-02
  • 100-clean_web_static.py : Write a Fabric script (based on the file 3-deploy_web_static.py) that deletes out-of-date archives, using the function do_clean:
    • Prototype: def do_clean(number=0):
    • number is the number of the archives, including the most recent, to keep
      • If number is 0 or 1, keep only the most recent version of your archive.
      • if number is 2, keep the most recent, and second most recent versions of your archive.
      • etc.
    • Your script should:
      • Delete all unnecessary archives (all archives minus the number to keep) in the versions folder
      • Delete all unnecessary archives (all archives minus the number to keep) in the /data/web_static/releases folder of both of your web servers
    • All remote commands must be executed on both of your web servers (using the env.hosts = ['', 'IP web-02'] variable in your script)
  • 101-setup_web_static.pp : Redo the task #0 but by using Puppet.

airbnb_clone_v2's People

Contributors

justinmajetich avatar kwhit2 avatar enobreg avatar peytonbrsmith avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.