diff --git a/developing/README.md b/developing/README.md index 2784eb8..ec30e61 100644 --- a/developing/README.md +++ b/developing/README.md @@ -30,7 +30,7 @@ pip install -r requirements.txt pip install click==7.1.2 pip install python-dotenv ``` -Fill out the required fields in your config_local.py file. Some of this you might have to come back to after you run the docker compose. +Fill out the required fields in your config_local.py file. You might have to come back to this after you run the docker compose. ``` cp config.py config_local.py vim config_local.py @@ -164,8 +164,6 @@ vim config_local.py TIMEOUT = environ.get('PROXSTAR_TIMEOUT', 120) ``` -I'd recommend putting the secrets (such as your login credentials and ssh key) in a `.env` file so you don't have to have it on your screen as you tear your hair out about why this isn't working. Before running the server, insert it into your environment with `source .env` - ``` source .env ``` @@ -176,22 +174,6 @@ Now, go ahead and run the Docker Compose file to set up your Postgres and Redis docker-compose up -d ``` -Restore the databse in your new podman container. This might throw a TON of errors, but don't worry about it. -``` -echo 'CREATE DATABASE proxstar; CREATE DATABASE starrs; CREATE ROLE proxstar; CREATE ROLE starrs;' | psql postgresql://postgres:********@10.69.69.69 - -cat developing/schema/starrs/restore.sql | psql postgresql://postgres:********@10.69.69.69 -cat developing/schema/proxstar/restore.sql | psql postgresql://postgres:********@10.69.69.69 -``` - -Get a shell in your postgres real quick and install a perl thing. - -``` -docker exec -it developing_proxstar-postgres_1 bash -cpan -install Data::Validate::Domain -``` - Now, you should be ready to run your dev instance. I like to use `tmux` for this to run proxstar and the `rq worker` in separate panes. ``` @@ -204,4 +186,4 @@ If you're trying to run this all on a VM without a graphical web browser, you ca ssh example@dev-server.csh.rit.edu -L 8000:localhost:8000 ``` -Open a web browser and navigate to http://localhost:8000. You should see Proxstar running. \ No newline at end of file +Open a web browser and navigate to http://localhost:8000. You should see Proxstar running. diff --git a/developing/proxstar-postgres/Dockerfile b/developing/proxstar-postgres/Dockerfile index c0d8f4a..86cae6d 100644 --- a/developing/proxstar-postgres/Dockerfile +++ b/developing/proxstar-postgres/Dockerfile @@ -1,8 +1,12 @@ FROM postgres:12 RUN apt-get update \ - && apt-get install -y postgresql-plperl-12 \ - && apt-get install -y postgresql-plpython3-12 \ - && apt-get install -y libnet-ip-perl perl-net libnet-ldap-perl libnet-dns-perl libnet-snmp-perl libnet-server-mail-perl libcrypt-des-perl \ - && apt-get install -y libperl-dev build-essential \ + && apt-get install -y postgresql-plperl-12 postgresql-plpython3-12 libnet-ip-perl libnet-ldap-perl libnet-dns-perl libnet-snmp-perl libnet-server-mail-perl libcrypt-des-perl build-essential cpanminus \ && rm -rf /var/lib/apt/lists/* + +RUN cpanm Data::Validate::Domain + +RUN apt-get remove -y build-essential + +COPY ./schema/large.sql /docker-entrypoint-initdb.d/ + diff --git a/developing/schema/starrs/restore.sql b/developing/proxstar-postgres/schema/large.sql similarity index 98% rename from developing/schema/starrs/restore.sql rename to developing/proxstar-postgres/schema/large.sql index e229e55..bd18353 100644 --- a/developing/schema/starrs/restore.sql +++ b/developing/proxstar-postgres/schema/large.sql @@ -1,3 +1,282 @@ +CREATE DATABASE proxstar; CREATE DATABASE starrs; CREATE ROLE proxstar; CREATE ROLE starrs; + +-- +-- NOTE: +-- +-- File paths need to be edited. Search for $$PATH$$ and +-- replace it with the path to the directory containing +-- the extracted data files. +-- +-- +-- PostgreSQL database dump +-- + +-- Dumped from database version 12.6 +-- Dumped by pg_dump version 12.6 + +SET statement_timeout = 0; +SET lock_timeout = 0; +SET idle_in_transaction_session_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = on; +SELECT pg_catalog.set_config('search_path', '', false); +SET check_function_bodies = false; +SET xmloption = content; +SET client_min_messages = warning; +SET row_security = off; + +DROP DATABASE proxstar; +-- +-- Name: proxstar; Type: DATABASE; Schema: -; Owner: postgres +-- + +CREATE DATABASE proxstar WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'en_US.UTF-8' LC_CTYPE = 'en_US.UTF-8'; + + +ALTER DATABASE proxstar OWNER TO postgres; + +\connect proxstar + +SET statement_timeout = 0; +SET lock_timeout = 0; +SET idle_in_transaction_session_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = on; +SELECT pg_catalog.set_config('search_path', '', false); +SET check_function_bodies = false; +SET xmloption = content; +SET client_min_messages = warning; +SET row_security = off; + +-- +-- Name: plperl; Type: PROCEDURAL LANGUAGE; Schema: -; Owner: postgres +-- + +CREATE OR REPLACE PROCEDURAL LANGUAGE plperl; + + +ALTER PROCEDURAL LANGUAGE plperl OWNER TO postgres; + +-- +-- Name: plperl_call_handler(); Type: FUNCTION; Schema: public; Owner: postgres +-- + +CREATE FUNCTION public.plperl_call_handler() RETURNS language_handler + LANGUAGE c + AS '$libdir/plperl', 'plperl_call_handler'; + + +ALTER FUNCTION public.plperl_call_handler() OWNER TO postgres; + +-- +-- Name: plpgsql_call_handler(); Type: FUNCTION; Schema: public; Owner: postgres +-- + +CREATE FUNCTION public.plpgsql_call_handler() RETURNS language_handler + LANGUAGE c + AS '$libdir/plpgsql', 'plpgsql_call_handler'; + + +ALTER FUNCTION public.plpgsql_call_handler() OWNER TO postgres; + +SET default_tablespace = ''; + +SET default_table_access_method = heap; + +-- +-- Name: allowed_users; Type: TABLE; Schema: public; Owner: proxstar +-- + +CREATE TABLE public.allowed_users ( + id character varying(32) NOT NULL +); + + +ALTER TABLE public.allowed_users OWNER TO proxstar; + +-- +-- Name: ignored_pools; Type: TABLE; Schema: public; Owner: proxstar +-- + +CREATE TABLE public.ignored_pools ( + id character varying(32) NOT NULL +); + + +ALTER TABLE public.ignored_pools OWNER TO proxstar; + +-- +-- Name: pool_cache; Type: TABLE; Schema: public; Owner: proxstar +-- + +CREATE TABLE public.pool_cache ( + pool character varying(32) NOT NULL, + vms text[] NOT NULL, + num_vms integer NOT NULL, + usage json NOT NULL, + limits json NOT NULL, + percents json NOT NULL +); + + +ALTER TABLE public.pool_cache OWNER TO proxstar; + +-- +-- Name: template; Type: TABLE; Schema: public; Owner: proxstar +-- + +CREATE TABLE public.template ( + id integer NOT NULL, + name character varying(32) NOT NULL, + username text NOT NULL, + password text NOT NULL, + disk integer NOT NULL +); + + +ALTER TABLE public.template OWNER TO proxstar; + +-- +-- Name: template_id_seq; Type: SEQUENCE; Schema: public; Owner: proxstar +-- + +CREATE SEQUENCE public.template_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.template_id_seq OWNER TO proxstar; + +-- +-- Name: template_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: proxstar +-- + +ALTER SEQUENCE public.template_id_seq OWNED BY public.template.id; + + +-- +-- Name: usage_limit; Type: TABLE; Schema: public; Owner: proxstar +-- + +CREATE TABLE public.usage_limit ( + id character varying(32) NOT NULL, + cpu integer NOT NULL, + mem integer NOT NULL, + disk integer NOT NULL +); + + +ALTER TABLE public.usage_limit OWNER TO proxstar; + +-- +-- Name: vm_expiration; Type: TABLE; Schema: public; Owner: proxstar +-- + +CREATE TABLE public.vm_expiration ( + id integer NOT NULL, + expire_date date NOT NULL +); + + +ALTER TABLE public.vm_expiration OWNER TO proxstar; + +-- +-- Name: vm_expiration_id_seq; Type: SEQUENCE; Schema: public; Owner: proxstar +-- + +CREATE SEQUENCE public.vm_expiration_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +ALTER TABLE public.vm_expiration_id_seq OWNER TO proxstar; + +-- +-- Name: vm_expiration_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: proxstar +-- + +ALTER SEQUENCE public.vm_expiration_id_seq OWNED BY public.vm_expiration.id; + + +-- +-- Name: template id; Type: DEFAULT; Schema: public; Owner: proxstar +-- + +ALTER TABLE ONLY public.template ALTER COLUMN id SET DEFAULT nextval('public.template_id_seq'::regclass); + + +-- +-- Name: vm_expiration id; Type: DEFAULT; Schema: public; Owner: proxstar +-- + +ALTER TABLE ONLY public.vm_expiration ALTER COLUMN id SET DEFAULT nextval('public.vm_expiration_id_seq'::regclass); + + +-- +-- Name: allowed_users allowed_users_pkey; Type: CONSTRAINT; Schema: public; Owner: proxstar +-- + +ALTER TABLE ONLY public.allowed_users + ADD CONSTRAINT allowed_users_pkey PRIMARY KEY (id); + + +-- +-- Name: ignored_pools ignored_pools_pkey; Type: CONSTRAINT; Schema: public; Owner: proxstar +-- + +ALTER TABLE ONLY public.ignored_pools + ADD CONSTRAINT ignored_pools_pkey PRIMARY KEY (id); + + +-- +-- Name: pool_cache pool_cache_pkey; Type: CONSTRAINT; Schema: public; Owner: proxstar +-- + +ALTER TABLE ONLY public.pool_cache + ADD CONSTRAINT pool_cache_pkey PRIMARY KEY (pool); + + +-- +-- Name: template template_pkey; Type: CONSTRAINT; Schema: public; Owner: proxstar +-- + +ALTER TABLE ONLY public.template + ADD CONSTRAINT template_pkey PRIMARY KEY (id); + + +-- +-- Name: usage_limit usage_limit_pkey; Type: CONSTRAINT; Schema: public; Owner: proxstar +-- + +ALTER TABLE ONLY public.usage_limit + ADD CONSTRAINT usage_limit_pkey PRIMARY KEY (id); + + +-- +-- Name: vm_expiration vm_expiration_pkey; Type: CONSTRAINT; Schema: public; Owner: proxstar +-- + +ALTER TABLE ONLY public.vm_expiration + ADD CONSTRAINT vm_expiration_pkey PRIMARY KEY (id); + + +-- +-- Name: DATABASE proxstar; Type: ACL; Schema: -; Owner: postgres +-- + +GRANT ALL ON DATABASE proxstar TO proxstar; + + +-- +-- PostgreSQL database dump complete +-- + -- -- NOTE: -- diff --git a/developing/schema/proxstar/restore.sql b/developing/schema/proxstar/restore.sql deleted file mode 100644 index 84581fd..0000000 --- a/developing/schema/proxstar/restore.sql +++ /dev/null @@ -1,277 +0,0 @@ --- --- NOTE: --- --- File paths need to be edited. Search for $$PATH$$ and --- replace it with the path to the directory containing --- the extracted data files. --- --- --- PostgreSQL database dump --- - --- Dumped from database version 12.6 --- Dumped by pg_dump version 12.6 - -SET statement_timeout = 0; -SET lock_timeout = 0; -SET idle_in_transaction_session_timeout = 0; -SET client_encoding = 'UTF8'; -SET standard_conforming_strings = on; -SELECT pg_catalog.set_config('search_path', '', false); -SET check_function_bodies = false; -SET xmloption = content; -SET client_min_messages = warning; -SET row_security = off; - -DROP DATABASE proxstar; --- --- Name: proxstar; Type: DATABASE; Schema: -; Owner: postgres --- - -CREATE DATABASE proxstar WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'en_US.UTF-8' LC_CTYPE = 'en_US.UTF-8'; - - -ALTER DATABASE proxstar OWNER TO postgres; - -\connect proxstar - -SET statement_timeout = 0; -SET lock_timeout = 0; -SET idle_in_transaction_session_timeout = 0; -SET client_encoding = 'UTF8'; -SET standard_conforming_strings = on; -SELECT pg_catalog.set_config('search_path', '', false); -SET check_function_bodies = false; -SET xmloption = content; -SET client_min_messages = warning; -SET row_security = off; - --- --- Name: plperl; Type: PROCEDURAL LANGUAGE; Schema: -; Owner: postgres --- - -CREATE OR REPLACE PROCEDURAL LANGUAGE plperl; - - -ALTER PROCEDURAL LANGUAGE plperl OWNER TO postgres; - --- --- Name: plperl_call_handler(); Type: FUNCTION; Schema: public; Owner: postgres --- - -CREATE FUNCTION public.plperl_call_handler() RETURNS language_handler - LANGUAGE c - AS '$libdir/plperl', 'plperl_call_handler'; - - -ALTER FUNCTION public.plperl_call_handler() OWNER TO postgres; - --- --- Name: plpgsql_call_handler(); Type: FUNCTION; Schema: public; Owner: postgres --- - -CREATE FUNCTION public.plpgsql_call_handler() RETURNS language_handler - LANGUAGE c - AS '$libdir/plpgsql', 'plpgsql_call_handler'; - - -ALTER FUNCTION public.plpgsql_call_handler() OWNER TO postgres; - -SET default_tablespace = ''; - -SET default_table_access_method = heap; - --- --- Name: allowed_users; Type: TABLE; Schema: public; Owner: proxstar --- - -CREATE TABLE public.allowed_users ( - id character varying(32) NOT NULL -); - - -ALTER TABLE public.allowed_users OWNER TO proxstar; - --- --- Name: ignored_pools; Type: TABLE; Schema: public; Owner: proxstar --- - -CREATE TABLE public.ignored_pools ( - id character varying(32) NOT NULL -); - - -ALTER TABLE public.ignored_pools OWNER TO proxstar; - --- --- Name: pool_cache; Type: TABLE; Schema: public; Owner: proxstar --- - -CREATE TABLE public.pool_cache ( - pool character varying(32) NOT NULL, - vms text[] NOT NULL, - num_vms integer NOT NULL, - usage json NOT NULL, - limits json NOT NULL, - percents json NOT NULL -); - - -ALTER TABLE public.pool_cache OWNER TO proxstar; - --- --- Name: template; Type: TABLE; Schema: public; Owner: proxstar --- - -CREATE TABLE public.template ( - id integer NOT NULL, - name character varying(32) NOT NULL, - username text NOT NULL, - password text NOT NULL, - disk integer NOT NULL -); - - -ALTER TABLE public.template OWNER TO proxstar; - --- --- Name: template_id_seq; Type: SEQUENCE; Schema: public; Owner: proxstar --- - -CREATE SEQUENCE public.template_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE public.template_id_seq OWNER TO proxstar; - --- --- Name: template_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: proxstar --- - -ALTER SEQUENCE public.template_id_seq OWNED BY public.template.id; - - --- --- Name: usage_limit; Type: TABLE; Schema: public; Owner: proxstar --- - -CREATE TABLE public.usage_limit ( - id character varying(32) NOT NULL, - cpu integer NOT NULL, - mem integer NOT NULL, - disk integer NOT NULL -); - - -ALTER TABLE public.usage_limit OWNER TO proxstar; - --- --- Name: vm_expiration; Type: TABLE; Schema: public; Owner: proxstar --- - -CREATE TABLE public.vm_expiration ( - id integer NOT NULL, - expire_date date NOT NULL -); - - -ALTER TABLE public.vm_expiration OWNER TO proxstar; - --- --- Name: vm_expiration_id_seq; Type: SEQUENCE; Schema: public; Owner: proxstar --- - -CREATE SEQUENCE public.vm_expiration_id_seq - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -ALTER TABLE public.vm_expiration_id_seq OWNER TO proxstar; - --- --- Name: vm_expiration_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: proxstar --- - -ALTER SEQUENCE public.vm_expiration_id_seq OWNED BY public.vm_expiration.id; - - --- --- Name: template id; Type: DEFAULT; Schema: public; Owner: proxstar --- - -ALTER TABLE ONLY public.template ALTER COLUMN id SET DEFAULT nextval('public.template_id_seq'::regclass); - - --- --- Name: vm_expiration id; Type: DEFAULT; Schema: public; Owner: proxstar --- - -ALTER TABLE ONLY public.vm_expiration ALTER COLUMN id SET DEFAULT nextval('public.vm_expiration_id_seq'::regclass); - - --- --- Name: allowed_users allowed_users_pkey; Type: CONSTRAINT; Schema: public; Owner: proxstar --- - -ALTER TABLE ONLY public.allowed_users - ADD CONSTRAINT allowed_users_pkey PRIMARY KEY (id); - - --- --- Name: ignored_pools ignored_pools_pkey; Type: CONSTRAINT; Schema: public; Owner: proxstar --- - -ALTER TABLE ONLY public.ignored_pools - ADD CONSTRAINT ignored_pools_pkey PRIMARY KEY (id); - - --- --- Name: pool_cache pool_cache_pkey; Type: CONSTRAINT; Schema: public; Owner: proxstar --- - -ALTER TABLE ONLY public.pool_cache - ADD CONSTRAINT pool_cache_pkey PRIMARY KEY (pool); - - --- --- Name: template template_pkey; Type: CONSTRAINT; Schema: public; Owner: proxstar --- - -ALTER TABLE ONLY public.template - ADD CONSTRAINT template_pkey PRIMARY KEY (id); - - --- --- Name: usage_limit usage_limit_pkey; Type: CONSTRAINT; Schema: public; Owner: proxstar --- - -ALTER TABLE ONLY public.usage_limit - ADD CONSTRAINT usage_limit_pkey PRIMARY KEY (id); - - --- --- Name: vm_expiration vm_expiration_pkey; Type: CONSTRAINT; Schema: public; Owner: proxstar --- - -ALTER TABLE ONLY public.vm_expiration - ADD CONSTRAINT vm_expiration_pkey PRIMARY KEY (id); - - --- --- Name: DATABASE proxstar; Type: ACL; Schema: -; Owner: postgres --- - -GRANT ALL ON DATABASE proxstar TO proxstar; - - --- --- PostgreSQL database dump complete --- - diff --git a/proxstar/__init__.py b/proxstar/__init__.py index eb8dfee..88c3931 100644 --- a/proxstar/__init__.py +++ b/proxstar/__init__.py @@ -158,7 +158,7 @@ def list_vms(user_view=None): user = User(session['userinfo']['preferred_username']) rtp_view = False connect_proxmox() - if eval(app.config['FORCE_STANDARD_USER']): + if app.config['FORCE_STANDARD_USER']: user.rtp = False if user_view and not user.rtp: abort(403) diff --git a/proxstar/proxmox.py b/proxstar/proxmox.py index 7f9d207..867af28 100644 --- a/proxstar/proxmox.py +++ b/proxstar/proxmox.py @@ -60,7 +60,7 @@ def get_vm_node(proxmox, vmid): def get_isos(proxmox, storage): isos = [] - first_node = app.config['PROXMOX_HOSTS'][0].split('.')[0] # Get the name of the first node. + first_node = app.config['PROXMOX_HOSTS'][0].split('.')[0] # Get the name of the first node. for iso in proxmox.nodes(first_node).storage(storage).content.get(): isos.append(iso['volid'].split('/')[1]) return isos diff --git a/proxstar/tasks.py b/proxstar/tasks.py index c24bfb8..14a9afb 100644 --- a/proxstar/tasks.py +++ b/proxstar/tasks.py @@ -84,7 +84,7 @@ def create_vm_task(user, name, cores, memory, disk, iso): delete_vm_task(vmid) return vm = VM(vmid) - if (eval(app.config['USE_STARRS'])): + if app.config['USE_STARRS']: logging.info('[{}] Registering in STARRS.'.format(name)) set_job_status(job, 'registering in STARRS') ip = get_next_ip(starrs, app.config['STARRS_IP_RANGE'])