2 -- PlanetLab Central database schema
3 -- Version 5, PostgreSQL
5 -- Aaron Klingaman <alk@cs.princeton.edu>
6 -- Reid Moran <rmoran@cs.princeton.edu>
7 -- Mark Huang <mlhuang@cs.princeton.edu>
8 -- Tony Mack <tmack@cs.princeton.edu>
9 -- Thierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
11 -- Copyright (C) 2006 The Trustees of Princeton University
16 SET client_encoding = 'UNICODE';
18 --------------------------------------------------------------------------------
20 --------------------------------------------------------------------------------
23 CREATE TABLE plc_db_version (
24 version integer NOT NULL,
25 subversion integer NOT NULL DEFAULT 0
28 INSERT INTO plc_db_version (version, subversion) VALUES (5, 0);
30 --------------------------------------------------------------------------------
31 -- Aggregates and store procedures
32 --------------------------------------------------------------------------------
34 -- Like MySQL GROUP_CONCAT(), this function aggregates values into a
36 CREATE AGGREGATE array_accum (
38 basetype = anyelement,
43 --------------------------------------------------------------------------------
45 --------------------------------------------------------------------------------
48 CREATE TABLE persons (
50 person_id serial PRIMARY KEY, -- Account identifier
51 email text NOT NULL, -- E-mail address
52 first_name text NOT NULL, -- First name
53 last_name text NOT NULL, -- Last name
54 deleted boolean NOT NULL DEFAULT false, -- Has been deleted
55 enabled boolean NOT NULL DEFAULT false, -- Has been disabled
57 password text NOT NULL DEFAULT 'nopass', -- Password (md5crypted)
58 verification_key text, -- Reset password key
59 verification_expires timestamp without time zone,
62 title text, -- Honorific
63 phone text, -- Telephone number
64 url text, -- Home page
65 bio text, -- Biography
68 date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
69 last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
71 CREATE INDEX persons_email_idx ON persons (email);
73 --------------------------------------------------------------------------------
75 --------------------------------------------------------------------------------
80 site_id serial PRIMARY KEY, -- Site identifier
81 login_base text NOT NULL, -- Site slice prefix
82 name text NOT NULL, -- Site name
83 abbreviated_name text NOT NULL, -- Site abbreviated name
84 enabled boolean NOT NULL Default true, -- Is this site enabled
85 deleted boolean NOT NULL DEFAULT false, -- Has been deleted
86 is_public boolean NOT NULL DEFAULT true, -- Shows up in public lists
87 max_slices integer NOT NULL DEFAULT 0, -- Maximum number of slices
88 max_slivers integer NOT NULL DEFAULT 1000, -- Maximum number of instantiated slivers
94 ext_consortium_id integer, -- external consortium id
97 date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
98 last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
100 CREATE INDEX sites_login_base_idx ON sites (login_base);
102 -- Account site membership
103 CREATE TABLE person_site (
104 person_id integer REFERENCES persons NOT NULL, -- Account identifier
105 site_id integer REFERENCES sites NOT NULL, -- Site identifier
106 is_primary boolean NOT NULL DEFAULT false, -- Is the primary site for this account
107 PRIMARY KEY (person_id, site_id)
109 CREATE INDEX person_site_person_id_idx ON person_site (person_id);
110 CREATE INDEX person_site_site_id_idx ON person_site (site_id);
112 -- Ordered by primary site first
113 CREATE OR REPLACE VIEW person_site_ordered AS
114 SELECT person_id, site_id
116 ORDER BY is_primary DESC;
118 -- Sites that each person is a member of
119 CREATE OR REPLACE VIEW person_sites AS
121 array_accum(site_id) AS site_ids
122 FROM person_site_ordered
125 -- Accounts at each site
126 CREATE OR REPLACE VIEW site_persons AS
128 array_accum(person_id) AS person_ids
132 --------------------------------------------------------------------------------
134 --------------------------------------------------------------------------------
136 CREATE TABLE address_types (
137 address_type_id serial PRIMARY KEY, -- Address type identifier
138 name text UNIQUE NOT NULL, -- Address type
139 description text -- Address type description
142 -- Multi-rows insertion "insert .. values (row1), (row2)" is not supported by pgsql-8.1
143 -- 'Billing' Used to be 'Site'
144 INSERT INTO address_types (name) VALUES ('Personal');
145 INSERT INTO address_types (name) VALUES ('Shipping');
146 INSERT INTO address_types (name) VALUES ('Billing');
149 CREATE TABLE addresses (
150 address_id serial PRIMARY KEY, -- Address identifier
151 line1 text NOT NULL, -- Address line 1
152 line2 text, -- Address line 2
153 line3 text, -- Address line 3
154 city text NOT NULL, -- City
155 state text NOT NULL, -- State or province
156 postalcode text NOT NULL, -- Postal code
157 country text NOT NULL -- Country
160 -- Each mailing address can be one of several types
161 CREATE TABLE address_address_type (
162 address_id integer REFERENCES addresses NOT NULL, -- Address identifier
163 address_type_id integer REFERENCES address_types NOT NULL, -- Address type
164 PRIMARY KEY (address_id, address_type_id)
166 CREATE INDEX address_address_type_address_id_idx ON address_address_type (address_id);
167 CREATE INDEX address_address_type_address_type_id_idx ON address_address_type (address_type_id);
169 CREATE OR REPLACE VIEW address_address_types AS
171 array_accum(address_type_id) AS address_type_ids,
172 array_accum(address_types.name) AS address_types
173 FROM address_address_type
174 LEFT JOIN address_types USING (address_type_id)
177 CREATE TABLE site_address (
178 site_id integer REFERENCES sites NOT NULL, -- Site identifier
179 address_id integer REFERENCES addresses NOT NULL, -- Address identifier
180 PRIMARY KEY (site_id, address_id)
182 CREATE INDEX site_address_site_id_idx ON site_address (site_id);
183 CREATE INDEX site_address_address_id_idx ON site_address (address_id);
185 CREATE OR REPLACE VIEW site_addresses AS
187 array_accum(address_id) AS address_ids
191 --------------------------------------------------------------------------------
192 -- Authentication Keys
193 --------------------------------------------------------------------------------
196 CREATE TABLE key_types (
197 key_type text PRIMARY KEY -- Key type
199 INSERT INTO key_types (key_type) VALUES ('ssh');
201 -- Authentication keys
203 key_id serial PRIMARY KEY, -- Key identifier
204 key_type text REFERENCES key_types NOT NULL, -- Key type
205 key text NOT NULL, -- Key material
206 is_blacklisted boolean NOT NULL DEFAULT false -- Has been blacklisted
209 -- Account authentication key(s)
210 CREATE TABLE person_key (
211 key_id integer REFERENCES keys PRIMARY KEY, -- Key identifier
212 person_id integer REFERENCES persons NOT NULL -- Account identifier
214 CREATE INDEX person_key_person_id_idx ON person_key (person_id);
216 CREATE OR REPLACE VIEW person_keys AS
218 array_accum(key_id) AS key_ids
222 --------------------------------------------------------------------------------
224 --------------------------------------------------------------------------------
226 -- Valid account roles
228 role_id integer PRIMARY KEY, -- Role identifier
229 name text UNIQUE NOT NULL -- Role symbolic name
231 INSERT INTO roles (role_id, name) VALUES (10, 'admin');
232 INSERT INTO roles (role_id, name) VALUES (20, 'pi');
233 INSERT INTO roles (role_id, name) VALUES (30, 'user');
234 INSERT INTO roles (role_id, name) VALUES (40, 'tech');
236 CREATE TABLE person_role (
237 person_id integer REFERENCES persons NOT NULL, -- Account identifier
238 role_id integer REFERENCES roles NOT NULL, -- Role identifier
239 PRIMARY KEY (person_id, role_id)
241 CREATE INDEX person_role_person_id_idx ON person_role (person_id);
244 CREATE OR REPLACE VIEW person_roles AS
246 array_accum(role_id) AS role_ids,
247 array_accum(roles.name) AS roles
249 LEFT JOIN roles USING (role_id)
252 --------------------------------------------------------------------------------
254 --------------------------------------------------------------------------------
256 -- Valid node boot states (Nodes.py expect max length to be 20)
257 CREATE TABLE boot_states (
258 boot_state text PRIMARY KEY
260 INSERT INTO boot_states (boot_state) VALUES ('boot');
261 INSERT INTO boot_states (boot_state) VALUES ('safeboot');
262 INSERT INTO boot_states (boot_state) VALUES ('failboot');
263 INSERT INTO boot_states (boot_state) VALUES ('disabled');
264 INSERT INTO boot_states (boot_state) VALUES ('install');
265 INSERT INTO boot_states (boot_state) VALUES ('reinstall');
267 -- Known node types (Nodes.py expect max length to be 20)
268 CREATE TABLE node_types (
269 node_type text PRIMARY KEY
271 INSERT INTO node_types (node_type) VALUES ('regular');
272 INSERT INTO node_types (node_type) VALUES ('dummynet');
277 node_id serial PRIMARY KEY, -- Node identifier
278 node_type text REFERENCES node_types -- node type
281 hostname text NOT NULL, -- Node hostname
282 site_id integer REFERENCES sites NOT NULL, -- At which site
283 boot_state text REFERENCES boot_states NOT NULL -- Node boot state
285 deleted boolean NOT NULL DEFAULT false, -- Is deleted
288 model text, -- Hardware make and model
289 boot_nonce text, -- Random nonce updated by Boot Manager
290 version text, -- Boot CD version string updated by Boot Manager
291 ssh_rsa_key text, -- SSH host key updated by Boot Manager
292 key text, -- Node key generated when boot file is downloaded
295 date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
296 last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
297 last_contact timestamp without time zone
299 CREATE INDEX nodes_hostname_idx ON nodes (hostname);
300 CREATE INDEX nodes_site_id_idx ON nodes (site_id);
302 -- Nodes at each site
303 CREATE OR REPLACE VIEW site_nodes AS
305 array_accum(node_id) AS node_ids
307 WHERE deleted IS false
310 --------------------------------------------------------------------------------
312 --------------------------------------------------------------------------------
313 CREATE TABLE tag_types (
315 tag_type_id serial PRIMARY KEY, -- ID
316 tagname text UNIQUE NOT NULL, -- Tag Name
317 description text, -- Optional Description
318 min_role_id integer REFERENCES roles DEFAULT 10, -- set minimal role required
319 category text NOT NULL DEFAULT 'general' -- Free text for grouping tags together
322 CREATE TABLE node_tag (
323 node_tag_id serial PRIMARY KEY, -- ID
324 node_id integer REFERENCES nodes NOT NULL, -- node id
325 tag_type_id integer REFERENCES tag_types, -- tag type id
326 value text -- value attached
329 --------------------------------------------------------------------------------
330 -- (network) interfaces
331 --------------------------------------------------------------------------------
333 -- Valid network addressing schemes
334 CREATE TABLE network_types (
335 type text PRIMARY KEY -- Addressing scheme
337 INSERT INTO network_types (type) VALUES ('ipv4');
339 -- Valid network configuration methods
340 CREATE TABLE network_methods (
341 method text PRIMARY KEY -- Configuration method
344 INSERT INTO network_methods (method) VALUES ('static');
345 INSERT INTO network_methods (method) VALUES ('dhcp');
346 INSERT INTO network_methods (method) VALUES ('proxy');
347 INSERT INTO network_methods (method) VALUES ('tap');
348 INSERT INTO network_methods (method) VALUES ('ipmi');
349 INSERT INTO network_methods (method) VALUES ('unknown');
351 -- Node network interfaces
352 CREATE TABLE interfaces (
354 interface_id serial PRIMARY KEY, -- Network interface identifier
355 node_id integer REFERENCES nodes NOT NULL, -- Which node
356 is_primary boolean NOT NULL DEFAULT false, -- Is the primary interface for this node
357 type text REFERENCES network_types NOT NULL, -- Addressing scheme
358 method text REFERENCES network_methods NOT NULL, -- Configuration method
360 -- Optional, depending on type and method
361 ip text, -- IP address
362 mac text, -- MAC address
363 gateway text, -- Default gateway address
364 network text, -- Network address
365 broadcast text, -- Network broadcast address
366 netmask text, -- Network mask
367 dns1 text, -- Primary DNS server
368 dns2 text, -- Secondary DNS server
369 bwlimit integer, -- Bandwidth limit in bps
370 hostname text -- Hostname of this interface
372 CREATE INDEX interfaces_node_id_idx ON interfaces (node_id);
374 -- Ordered by primary interface first
375 CREATE OR REPLACE VIEW interfaces_ordered AS
376 SELECT node_id, interface_id
378 ORDER BY is_primary DESC;
380 -- Network interfaces on each node
381 CREATE OR REPLACE VIEW node_interfaces AS
383 array_accum(interface_id) AS interface_ids
384 FROM interfaces_ordered
387 --------------------------------------------------------------------------------
388 -- Interface tags (formerly known as interface settings)
389 --------------------------------------------------------------------------------
391 CREATE TABLE interface_tag (
392 interface_tag_id serial PRIMARY KEY, -- Interface Setting Identifier
393 interface_id integer REFERENCES interfaces NOT NULL,-- the interface this applies to
394 tag_type_id integer REFERENCES tag_types NOT NULL, -- the setting type
395 value text -- value attached
398 CREATE OR REPLACE VIEW interface_tags AS
400 array_accum(interface_tag_id) AS interface_tag_ids
402 GROUP BY interface_id;
404 CREATE OR REPLACE VIEW view_interface_tags AS
406 interface_tag.interface_tag_id,
407 interface_tag.interface_id,
408 tag_types.tag_type_id,
410 tag_types.description,
412 tag_types.min_role_id,
415 INNER JOIN tag_types USING (tag_type_id);
417 CREATE OR REPLACE VIEW view_interfaces AS
419 interfaces.interface_id,
421 interfaces.is_primary,
428 interfaces.broadcast,
434 COALESCE((SELECT interface_tag_ids FROM interface_tags WHERE interface_tags.interface_id = interfaces.interface_id), '{}') AS interface_tag_ids
437 --------------------------------------------------------------------------------
438 -- ilinks : links between interfaces
439 --------------------------------------------------------------------------------
441 ilink_id serial PRIMARY KEY, -- id
442 tag_type_id integer REFERENCES tag_types, -- id of the tag type
443 src_interface_id integer REFERENCES interfaces not NULL, -- id of src interface
444 dst_interface_id integer REFERENCES interfaces NOT NULL, -- id of dst interface
445 value text -- optional value on the link
448 CREATE OR REPLACE VIEW view_ilinks AS
449 SELECT * FROM tag_types
450 INNER JOIN ilink USING (tag_type_id);
452 -- expose node_ids ???
453 -- -- cannot mention the same table twice in a join ?
454 -- -- CREATE OR REPLACE VIEW ilink_src_node AS
456 -- ilink.tag_type_id,
457 -- ilink.src_interface_id,
458 -- interfaces.node_id AS src_node_id,
459 -- ilink.dst_interface_id
461 -- INNER JOIN interfaces ON ilink.src_interface_id = interfaces.interface_id;
463 -- CREATE OR REPLACE VIEW ilink_nodes AS
466 -- interfaces.node_id as dst_node_id
467 -- FROM ilink_src_node
468 -- INNER JOIN interfaces ON ilink_src_node.dst_interface_id = interfaces.interface_id;
470 --------------------------------------------------------------------------------
472 --------------------------------------------------------------------------------
475 CREATE TABLE nodegroups (
476 nodegroup_id serial PRIMARY KEY, -- Group identifier
477 groupname text UNIQUE NOT NULL, -- Group name
478 tag_type_id integer REFERENCES tag_types, -- node is in nodegroup if it has this tag defined
479 -- can be null, make management faster & easier
480 value text -- with this value attached
483 -- xxx - first rough implem. similar to former semantics but might be slow
484 CREATE OR REPLACE VIEW nodegroup_node AS
485 SELECT nodegroup_id, node_id
490 USING (tag_type_id,value);
492 CREATE OR REPLACE VIEW nodegroup_nodes AS
494 array_accum(node_id) AS node_ids
496 GROUP BY nodegroup_id;
498 -- Node groups that each node is a member of
499 CREATE OR REPLACE VIEW node_nodegroups AS
501 array_accum(nodegroup_id) AS nodegroup_ids
505 --------------------------------------------------------------------------------
506 -- Node configuration files
507 --------------------------------------------------------------------------------
509 CREATE TABLE conf_files (
510 conf_file_id serial PRIMARY KEY, -- Configuration file identifier
511 enabled bool NOT NULL DEFAULT true, -- Configuration file is active
512 source text NOT NULL, -- Relative path on the boot server
513 -- where file can be downloaded
514 dest text NOT NULL, -- Absolute path where file should be installed
515 file_permissions text NOT NULL DEFAULT '0644', -- chmod(1) permissions
516 file_owner text NOT NULL DEFAULT 'root', -- chown(1) owner
517 file_group text NOT NULL DEFAULT 'root', -- chgrp(1) owner
518 preinstall_cmd text, -- Shell command to execute prior to installing
519 postinstall_cmd text, -- Shell command to execute after installing
520 error_cmd text, -- Shell command to execute if any error occurs
521 ignore_cmd_errors bool NOT NULL DEFAULT false, -- Install file anyway even if an error occurs
522 always_update bool NOT NULL DEFAULT false -- Always attempt to install file even if unchanged
525 CREATE TABLE conf_file_node (
526 conf_file_id integer REFERENCES conf_files NOT NULL, -- Configuration file identifier
527 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
528 PRIMARY KEY (conf_file_id, node_id)
530 CREATE INDEX conf_file_node_conf_file_id_idx ON conf_file_node (conf_file_id);
531 CREATE INDEX conf_file_node_node_id_idx ON conf_file_node (node_id);
533 -- Nodes linked to each configuration file
534 CREATE OR REPLACE VIEW conf_file_nodes AS
536 array_accum(node_id) AS node_ids
538 GROUP BY conf_file_id;
540 -- Configuration files linked to each node
541 CREATE OR REPLACE VIEW node_conf_files AS
543 array_accum(conf_file_id) AS conf_file_ids
547 CREATE TABLE conf_file_nodegroup (
548 conf_file_id integer REFERENCES conf_files NOT NULL, -- Configuration file identifier
549 nodegroup_id integer REFERENCES nodegroups NOT NULL, -- Node group identifier
550 PRIMARY KEY (conf_file_id, nodegroup_id)
552 CREATE INDEX conf_file_nodegroup_conf_file_id_idx ON conf_file_nodegroup (conf_file_id);
553 CREATE INDEX conf_file_nodegroup_nodegroup_id_idx ON conf_file_nodegroup (nodegroup_id);
555 -- Node groups linked to each configuration file
556 CREATE OR REPLACE VIEW conf_file_nodegroups AS
558 array_accum(nodegroup_id) AS nodegroup_ids
559 FROM conf_file_nodegroup
560 GROUP BY conf_file_id;
562 -- Configuration files linked to each node group
563 CREATE OR REPLACE VIEW nodegroup_conf_files AS
565 array_accum(conf_file_id) AS conf_file_ids
566 FROM conf_file_nodegroup
567 GROUP BY nodegroup_id;
569 --------------------------------------------------------------------------------
570 -- Power control units (PCUs)
571 --------------------------------------------------------------------------------
575 pcu_id serial PRIMARY KEY, -- PCU identifier
576 site_id integer REFERENCES sites NOT NULL, -- Site identifier
577 hostname text, -- Hostname, not necessarily unique
578 -- (multiple logical sites could use the same PCU)
579 ip text NOT NULL, -- IP, not necessarily unique
582 protocol text, -- Protocol, e.g. ssh or https or telnet
583 username text, -- Username, if applicable
584 "password" text, -- Password, if applicable
585 model text, -- Model, e.g. BayTech or iPal
586 notes text -- Random notes
588 CREATE INDEX pcus_site_id_idx ON pcus (site_id);
590 CREATE OR REPLACE VIEW site_pcus AS
592 array_accum(pcu_id) AS pcu_ids
596 CREATE TABLE pcu_node (
597 pcu_id integer REFERENCES pcus NOT NULL, -- PCU identifier
598 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
599 port integer NOT NULL, -- Port number
600 PRIMARY KEY (pcu_id, node_id), -- The same node cannot be controlled by different ports
601 UNIQUE (pcu_id, port) -- The same port cannot control multiple nodes
603 CREATE INDEX pcu_node_pcu_id_idx ON pcu_node (pcu_id);
604 CREATE INDEX pcu_node_node_id_idx ON pcu_node (node_id);
606 CREATE OR REPLACE VIEW node_pcus AS
608 array_accum(pcu_id) AS pcu_ids,
609 array_accum(port) AS ports
613 CREATE OR REPLACE VIEW pcu_nodes AS
615 array_accum(node_id) AS node_ids,
616 array_accum(port) AS ports
620 --------------------------------------------------------------------------------
622 --------------------------------------------------------------------------------
624 CREATE TABLE slice_instantiations (
625 instantiation text PRIMARY KEY
627 INSERT INTO slice_instantiations (instantiation) VALUES ('not-instantiated'); -- Placeholder slice
628 INSERT INTO slice_instantiations (instantiation) VALUES ('plc-instantiated'); -- Instantiated by Node Manager
629 INSERT INTO slice_instantiations (instantiation) VALUES ('delegated'); -- Manually instantiated
630 INSERT INTO slice_instantiations (instantiation) VALUES ('nm-controller'); -- NM Controller
633 CREATE TABLE slices (
634 slice_id serial PRIMARY KEY, -- Slice identifier
635 site_id integer REFERENCES sites NOT NULL, -- Site identifier
637 name text NOT NULL, -- Slice name
638 instantiation text REFERENCES slice_instantiations -- Slice state, e.g. plc-instantiated
639 NOT NULL DEFAULT 'plc-instantiated',
640 url text, -- Project URL
641 description text, -- Project description
643 max_nodes integer NOT NULL DEFAULT 100, -- Maximum number of nodes that can be assigned to this slice
645 creator_person_id integer REFERENCES persons, -- Creator
646 created timestamp without time zone NOT NULL -- Creation date
647 DEFAULT CURRENT_TIMESTAMP,
648 expires timestamp without time zone NOT NULL -- Expiration date
649 DEFAULT CURRENT_TIMESTAMP + '2 weeks',
651 is_deleted boolean NOT NULL DEFAULT false
653 CREATE INDEX slices_site_id_idx ON slices (site_id);
654 CREATE INDEX slices_name_idx ON slices (name);
657 CREATE TABLE slice_node (
658 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
659 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
660 PRIMARY KEY (slice_id, node_id)
662 CREATE INDEX slice_node_slice_id_idx ON slice_node (slice_id);
663 CREATE INDEX slice_node_node_id_idx ON slice_node (node_id);
665 -- Synonym for slice_node
666 CREATE OR REPLACE VIEW slivers AS
667 SELECT * FROM slice_node;
669 -- Nodes in each slice
670 CREATE OR REPLACE VIEW slice_nodes AS
672 array_accum(node_id) AS node_ids
676 -- Slices on each node
677 CREATE OR REPLACE VIEW node_slices AS
679 array_accum(slice_id) AS slice_ids
683 -- Slices at each site
684 CREATE OR REPLACE VIEW site_slices AS
686 array_accum(slice_id) AS slice_ids
688 WHERE is_deleted is false
692 CREATE TABLE slice_person (
693 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
694 person_id integer REFERENCES persons NOT NULL, -- Account identifier
695 PRIMARY KEY (slice_id, person_id)
697 CREATE INDEX slice_person_slice_id_idx ON slice_person (slice_id);
698 CREATE INDEX slice_person_person_id_idx ON slice_person (person_id);
700 -- Members of the slice
701 CREATE OR REPLACE VIEW slice_persons AS
703 array_accum(person_id) AS person_ids
707 -- Slices of which each person is a member
708 CREATE OR REPLACE VIEW person_slices AS
710 array_accum(slice_id) AS slice_ids
714 --------------------------------------------------------------------------------
716 --------------------------------------------------------------------------------
717 -- slice whitelist on nodes
718 CREATE TABLE node_slice_whitelist (
719 node_id integer REFERENCES nodes NOT NULL, -- Node id of whitelist
720 slice_id integer REFERENCES slices NOT NULL, -- Slice id thats allowd on this node
721 PRIMARY KEY (node_id, slice_id)
723 CREATE INDEX node_slice_whitelist_node_id_idx ON node_slice_whitelist (node_id);
724 CREATE INDEX node_slice_whitelist_slice_id_idx ON node_slice_whitelist (slice_id);
726 -- Slices on each node
727 CREATE OR REPLACE VIEW node_slices_whitelist AS
729 array_accum(slice_id) AS slice_ids_whitelist
730 FROM node_slice_whitelist
733 --------------------------------------------------------------------------------
734 -- Slice tags (formerly known as slice attributes)
735 --------------------------------------------------------------------------------
737 -- Slice/sliver attributes
738 CREATE TABLE slice_tag (
739 slice_tag_id serial PRIMARY KEY, -- Slice attribute identifier
740 slice_id integer REFERENCES slices NOT NULL, -- Slice identifier
741 node_id integer REFERENCES nodes, -- Sliver attribute if set
742 nodegroup_id integer REFERENCES nodegroups, -- Node group attribute if set
743 tag_type_id integer REFERENCES tag_types NOT NULL, -- Attribute type identifier
746 CREATE INDEX slice_tag_slice_id_idx ON slice_tag (slice_id);
747 CREATE INDEX slice_tag_node_id_idx ON slice_tag (node_id);
748 CREATE INDEX slice_tag_nodegroup_id_idx ON slice_tag (nodegroup_id);
750 --------------------------------------------------------------------------------
752 --------------------------------------------------------------------------------
755 CREATE TABLE initscripts (
756 initscript_id serial PRIMARY KEY, -- Initscript identifier
757 name text NOT NULL, -- Initscript name
758 enabled bool NOT NULL DEFAULT true, -- Initscript is active
759 script text NOT NULL, -- Initscript body
762 CREATE INDEX initscripts_name_idx ON initscripts (name);
765 --------------------------------------------------------------------------------
767 --------------------------------------------------------------------------------
771 peer_id serial PRIMARY KEY, -- Peer identifier
772 peername text NOT NULL, -- Peer name
773 peer_url text NOT NULL, -- (HTTPS) URL of the peer PLCAPI interface
774 cacert text, -- (SSL) Public certificate of peer API server
775 key text, -- (GPG) Public key used for authentication
776 deleted boolean NOT NULL DEFAULT false
778 CREATE INDEX peers_peername_idx ON peers (peername) WHERE deleted IS false;
780 -- Objects at each peer
781 CREATE TABLE peer_site (
782 site_id integer REFERENCES sites PRIMARY KEY, -- Local site identifier
783 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
784 peer_site_id integer NOT NULL, -- Foreign site identifier at peer
785 UNIQUE (peer_id, peer_site_id) -- The same foreign site should not be cached twice
787 CREATE INDEX peer_site_peer_id_idx ON peers (peer_id);
789 CREATE OR REPLACE VIEW peer_sites AS
791 array_accum(site_id) AS site_ids,
792 array_accum(peer_site_id) AS peer_site_ids
796 CREATE TABLE peer_person (
797 person_id integer REFERENCES persons PRIMARY KEY, -- Local user identifier
798 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
799 peer_person_id integer NOT NULL, -- Foreign user identifier at peer
800 UNIQUE (peer_id, peer_person_id) -- The same foreign user should not be cached twice
802 CREATE INDEX peer_person_peer_id_idx ON peer_person (peer_id);
804 CREATE OR REPLACE VIEW peer_persons AS
806 array_accum(person_id) AS person_ids,
807 array_accum(peer_person_id) AS peer_person_ids
811 CREATE TABLE peer_key (
812 key_id integer REFERENCES keys PRIMARY KEY, -- Local key identifier
813 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
814 peer_key_id integer NOT NULL, -- Foreign key identifier at peer
815 UNIQUE (peer_id, peer_key_id) -- The same foreign key should not be cached twice
817 CREATE INDEX peer_key_peer_id_idx ON peer_key (peer_id);
819 CREATE OR REPLACE VIEW peer_keys AS
821 array_accum(key_id) AS key_ids,
822 array_accum(peer_key_id) AS peer_key_ids
826 CREATE TABLE peer_node (
827 node_id integer REFERENCES nodes PRIMARY KEY, -- Local node identifier
828 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
829 peer_node_id integer NOT NULL, -- Foreign node identifier
830 UNIQUE (peer_id, peer_node_id) -- The same foreign node should not be cached twice
832 CREATE INDEX peer_node_peer_id_idx ON peer_node (peer_id);
834 CREATE OR REPLACE VIEW peer_nodes AS
836 array_accum(node_id) AS node_ids,
837 array_accum(peer_node_id) AS peer_node_ids
841 CREATE TABLE peer_slice (
842 slice_id integer REFERENCES slices PRIMARY KEY, -- Local slice identifier
843 peer_id integer REFERENCES peers NOT NULL, -- Peer identifier
844 peer_slice_id integer NOT NULL, -- Slice identifier at peer
845 UNIQUE (peer_id, peer_slice_id) -- The same foreign slice should not be cached twice
847 CREATE INDEX peer_slice_peer_id_idx ON peer_slice (peer_id);
849 CREATE OR REPLACE VIEW peer_slices AS
851 array_accum(slice_id) AS slice_ids,
852 array_accum(peer_slice_id) AS peer_slice_ids
856 --------------------------------------------------------------------------------
857 -- Authenticated sessions
858 --------------------------------------------------------------------------------
860 -- Authenticated sessions
861 CREATE TABLE sessions (
862 session_id text PRIMARY KEY, -- Session identifier
863 expires timestamp without time zone
866 -- People can have multiple sessions
867 CREATE TABLE person_session (
868 person_id integer REFERENCES persons NOT NULL, -- Account identifier
869 session_id text REFERENCES sessions NOT NULL, -- Session identifier
870 PRIMARY KEY (person_id, session_id),
871 UNIQUE (session_id) -- Sessions are unique
873 CREATE INDEX person_session_person_id_idx ON person_session (person_id);
875 -- Nodes can have only one session
876 CREATE TABLE node_session (
877 node_id integer REFERENCES nodes NOT NULL, -- Node identifier
878 session_id text REFERENCES sessions NOT NULL, -- Session identifier
879 UNIQUE (node_id), -- Nodes can have only one session
880 UNIQUE (session_id) -- Sessions are unique
883 -------------------------------------------------------------------------------
885 ------------------------------------------------------------------------------
886 CREATE TABLE pcu_types (
887 pcu_type_id serial PRIMARY KEY,
888 model text NOT NULL , -- PCU model name
889 name text -- Full PCU model name
891 CREATE INDEX pcu_types_model_idx ON pcu_types (model);
893 CREATE TABLE pcu_protocol_type (
894 pcu_protocol_type_id serial PRIMARY KEY,
895 pcu_type_id integer REFERENCES pcu_types NOT NULL, -- PCU type identifier
896 port integer NOT NULL, -- PCU port
897 protocol text NOT NULL, -- Protocol
898 supported boolean NOT NULL DEFAULT True -- Does PLC support
900 CREATE INDEX pcu_protocol_type_pcu_type_id ON pcu_protocol_type (pcu_type_id);
903 CREATE OR REPLACE VIEW pcu_protocol_types AS
905 array_accum(pcu_protocol_type_id) as pcu_protocol_type_ids
906 FROM pcu_protocol_type
907 GROUP BY pcu_type_id;
909 --------------------------------------------------------------------------------
911 --------------------------------------------------------------------------------
913 CREATE TABLE messages (
914 message_id text PRIMARY KEY, -- Message name
915 subject text, -- Message summary
916 template text, -- Message template
917 enabled bool NOT NULL DEFAULT true -- Whether message is enabled
920 --------------------------------------------------------------------------------
922 --------------------------------------------------------------------------------
925 CREATE TABLE events (
926 event_id serial PRIMARY KEY, -- Event identifier
927 person_id integer REFERENCES persons, -- Person responsible for event, if any
928 node_id integer REFERENCES nodes, -- Node responsible for event, if any
929 auth_type text, -- Type of auth used. i.e. AuthMethod
930 fault_code integer NOT NULL DEFAULT 0, -- Did this event result in error
931 call_name text NOT NULL, -- Call responsible for this event
932 call text NOT NULL, -- Call responsible for this event, including parameters
933 message text, -- High level description of this event
934 runtime float DEFAULT 0, -- Event run time
935 time timestamp without time zone NOT NULL -- Event timestamp
936 DEFAULT CURRENT_TIMESTAMP
939 -- Database object(s) that may have been affected by a particular event
940 CREATE TABLE event_object (
941 event_id integer REFERENCES events NOT NULL, -- Event identifier
942 object_id integer NOT NULL, -- Object identifier
943 object_type text NOT NULL Default 'Unknown' -- What type of object is this event affecting
945 CREATE INDEX event_object_event_id_idx ON event_object (event_id);
946 CREATE INDEX event_object_object_id_idx ON event_object (object_id);
947 CREATE INDEX event_object_object_type_idx ON event_object (object_type);
949 CREATE OR REPLACE VIEW event_objects AS
951 array_accum(object_id) AS object_ids,
952 array_accum(object_type) AS object_types
956 --------------------------------------------------------------------------------
958 --------------------------------------------------------------------------------
959 CREATE OR REPLACE VIEW view_pcu_types AS
961 pcu_types.pcu_type_id,
964 COALESCE((SELECT pcu_protocol_type_ids FROM pcu_protocol_types
965 WHERE pcu_protocol_types.pcu_type_id = pcu_types.pcu_type_id), '{}')
966 AS pcu_protocol_type_ids
969 --------------------------------------------------------------------------------
970 CREATE OR REPLACE VIEW view_events AS
981 CAST(date_part('epoch', events.time) AS bigint) AS time,
982 COALESCE((SELECT object_ids FROM event_objects WHERE event_objects.event_id = events.event_id), '{}') AS object_ids,
983 COALESCE((SELECT object_types FROM event_objects WHERE event_objects.event_id = events.event_id), '{}') AS object_types
986 CREATE OR REPLACE VIEW view_event_objects AS
996 CAST(date_part('epoch', events.time) AS bigint) AS time,
997 event_object.object_id,
998 event_object.object_type
999 FROM events LEFT JOIN event_object USING (event_id);
1001 --------------------------------------------------------------------------------
1002 CREATE OR REPLACE VIEW view_persons AS
1011 persons.verification_key,
1012 CAST(date_part('epoch', persons.verification_expires) AS bigint) AS verification_expires,
1017 CAST(date_part('epoch', persons.date_created) AS bigint) AS date_created,
1018 CAST(date_part('epoch', persons.last_updated) AS bigint) AS last_updated,
1019 peer_person.peer_id,
1020 peer_person.peer_person_id,
1021 COALESCE((SELECT role_ids FROM person_roles WHERE person_roles.person_id = persons.person_id), '{}') AS role_ids,
1022 COALESCE((SELECT roles FROM person_roles WHERE person_roles.person_id = persons.person_id), '{}') AS roles,
1023 COALESCE((SELECT site_ids FROM person_sites WHERE person_sites.person_id = persons.person_id), '{}') AS site_ids,
1024 COALESCE((SELECT key_ids FROM person_keys WHERE person_keys.person_id = persons.person_id), '{}') AS key_ids,
1025 COALESCE((SELECT slice_ids FROM person_slices WHERE person_slices.person_id = persons.person_id), '{}') AS slice_ids
1027 LEFT JOIN peer_person USING (person_id);
1029 --------------------------------------------------------------------------------
1030 CREATE OR REPLACE VIEW view_peers AS
1033 COALESCE((SELECT site_ids FROM peer_sites WHERE peer_sites.peer_id = peers.peer_id), '{}') AS site_ids,
1034 COALESCE((SELECT peer_site_ids FROM peer_sites WHERE peer_sites.peer_id = peers.peer_id), '{}') AS peer_site_ids,
1035 COALESCE((SELECT person_ids FROM peer_persons WHERE peer_persons.peer_id = peers.peer_id), '{}') AS person_ids,
1036 COALESCE((SELECT peer_person_ids FROM peer_persons WHERE peer_persons.peer_id = peers.peer_id), '{}') AS peer_person_ids,
1037 COALESCE((SELECT key_ids FROM peer_keys WHERE peer_keys.peer_id = peers.peer_id), '{}') AS key_ids,
1038 COALESCE((SELECT peer_key_ids FROM peer_keys WHERE peer_keys.peer_id = peers.peer_id), '{}') AS peer_key_ids,
1039 COALESCE((SELECT node_ids FROM peer_nodes WHERE peer_nodes.peer_id = peers.peer_id), '{}') AS node_ids,
1040 COALESCE((SELECT peer_node_ids FROM peer_nodes WHERE peer_nodes.peer_id = peers.peer_id), '{}') AS peer_node_ids,
1041 COALESCE((SELECT slice_ids FROM peer_slices WHERE peer_slices.peer_id = peers.peer_id), '{}') AS slice_ids,
1042 COALESCE((SELECT peer_slice_ids FROM peer_slices WHERE peer_slices.peer_id = peers.peer_id), '{}') AS peer_slice_ids
1045 --------------------------------------------------------------------------------
1046 CREATE OR REPLACE VIEW node_tags AS
1048 array_accum(node_tag_id) AS tag_ids
1052 CREATE OR REPLACE VIEW view_node_tags AS
1054 node_tag.node_tag_id,
1057 tag_types.tag_type_id,
1059 tag_types.description,
1061 tag_types.min_role_id,
1064 INNER JOIN tag_types USING (tag_type_id)
1065 INNER JOIN nodes USING (node_id);
1067 CREATE OR REPLACE VIEW view_nodes AS
1080 CAST(date_part('epoch', nodes.date_created) AS bigint) AS date_created,
1081 CAST(date_part('epoch', nodes.last_updated) AS bigint) AS last_updated,
1082 CAST(date_part('epoch', nodes.last_contact) AS bigint) AS last_contact,
1084 peer_node.peer_node_id,
1085 COALESCE((SELECT interface_ids FROM node_interfaces
1086 WHERE node_interfaces.node_id = nodes.node_id), '{}')
1088 COALESCE((SELECT nodegroup_ids FROM node_nodegroups
1089 WHERE node_nodegroups.node_id = nodes.node_id), '{}')
1091 COALESCE((SELECT slice_ids FROM node_slices
1092 WHERE node_slices.node_id = nodes.node_id), '{}')
1094 COALESCE((SELECT slice_ids_whitelist FROM node_slices_whitelist
1095 WHERE node_slices_whitelist.node_id = nodes.node_id), '{}')
1096 AS slice_ids_whitelist,
1097 COALESCE((SELECT pcu_ids FROM node_pcus
1098 WHERE node_pcus.node_id = nodes.node_id), '{}')
1100 COALESCE((SELECT ports FROM node_pcus
1101 WHERE node_pcus.node_id = nodes.node_id), '{}')
1103 COALESCE((SELECT conf_file_ids FROM node_conf_files
1104 WHERE node_conf_files.node_id = nodes.node_id), '{}')
1106 COALESCE((SELECT tag_ids FROM node_tags
1107 WHERE node_tags.node_id = nodes.node_id), '{}')
1109 node_session.session_id AS session
1111 LEFT JOIN peer_node USING (node_id)
1112 LEFT JOIN node_session USING (node_id);
1114 --------------------------------------------------------------------------------
1115 CREATE OR REPLACE VIEW view_nodegroups AS
1119 COALESCE((SELECT conf_file_ids FROM nodegroup_conf_files
1120 WHERE nodegroup_conf_files.nodegroup_id = nodegroups.nodegroup_id), '{}')
1122 COALESCE((SELECT node_ids FROM nodegroup_nodes
1123 WHERE nodegroup_nodes.nodegroup_id = nodegroups.nodegroup_id), '{}')
1125 FROM nodegroups INNER JOIN tag_types USING (tag_type_id);
1127 --------------------------------------------------------------------------------
1128 CREATE OR REPLACE VIEW view_conf_files AS
1131 COALESCE((SELECT node_ids FROM conf_file_nodes
1132 WHERE conf_file_nodes.conf_file_id = conf_files.conf_file_id), '{}')
1134 COALESCE((SELECT nodegroup_ids FROM conf_file_nodegroups
1135 WHERE conf_file_nodegroups.conf_file_id = conf_files.conf_file_id), '{}')
1139 --------------------------------------------------------------------------------
1140 CREATE OR REPLACE VIEW view_pcus AS
1143 COALESCE((SELECT node_ids FROM pcu_nodes WHERE pcu_nodes.pcu_id = pcus.pcu_id), '{}') AS node_ids,
1144 COALESCE((SELECT ports FROM pcu_nodes WHERE pcu_nodes.pcu_id = pcus.pcu_id), '{}') AS ports
1147 --------------------------------------------------------------------------------
1148 CREATE OR REPLACE VIEW view_sites AS
1153 sites.abbreviated_name,
1162 sites.ext_consortium_id,
1163 CAST(date_part('epoch', sites.date_created) AS bigint) AS date_created,
1164 CAST(date_part('epoch', sites.last_updated) AS bigint) AS last_updated,
1166 peer_site.peer_site_id,
1167 COALESCE((SELECT person_ids FROM site_persons WHERE site_persons.site_id = sites.site_id), '{}') AS person_ids,
1168 COALESCE((SELECT node_ids FROM site_nodes WHERE site_nodes.site_id = sites.site_id), '{}') AS node_ids,
1169 COALESCE((SELECT address_ids FROM site_addresses WHERE site_addresses.site_id = sites.site_id), '{}') AS address_ids,
1170 COALESCE((SELECT slice_ids FROM site_slices WHERE site_slices.site_id = sites.site_id), '{}') AS slice_ids,
1171 COALESCE((SELECT pcu_ids FROM site_pcus WHERE site_pcus.site_id = sites.site_id), '{}') AS pcu_ids
1173 LEFT JOIN peer_site USING (site_id);
1175 --------------------------------------------------------------------------------
1176 CREATE OR REPLACE VIEW view_addresses AS
1179 COALESCE((SELECT address_type_ids FROM address_address_types WHERE address_address_types.address_id = addresses.address_id), '{}') AS address_type_ids,
1180 COALESCE((SELECT address_types FROM address_address_types WHERE address_address_types.address_id = addresses.address_id), '{}') AS address_types
1183 --------------------------------------------------------------------------------
1184 CREATE OR REPLACE VIEW view_keys AS
1187 person_key.person_id,
1189 peer_key.peer_key_id
1191 LEFT JOIN person_key USING (key_id)
1192 LEFT JOIN peer_key USING (key_id);
1194 --------------------------------------------------------------------------------
1195 CREATE OR REPLACE VIEW slice_tags AS
1197 array_accum(slice_tag_id) AS slice_tag_ids
1201 CREATE OR REPLACE VIEW view_slices AS
1206 slices.instantiation,
1210 slices.creator_person_id,
1212 CAST(date_part('epoch', slices.created) AS bigint) AS created,
1213 CAST(date_part('epoch', slices.expires) AS bigint) AS expires,
1215 peer_slice.peer_slice_id,
1216 COALESCE((SELECT node_ids FROM slice_nodes WHERE slice_nodes.slice_id = slices.slice_id), '{}') AS node_ids,
1217 COALESCE((SELECT person_ids FROM slice_persons WHERE slice_persons.slice_id = slices.slice_id), '{}') AS person_ids,
1218 COALESCE((SELECT slice_tag_ids FROM slice_tags WHERE slice_tags.slice_id = slices.slice_id), '{}') AS slice_tag_ids
1220 LEFT JOIN peer_slice USING (slice_id);
1222 CREATE OR REPLACE VIEW view_slice_tags AS
1224 slice_tag.slice_tag_id,
1227 slice_tag.nodegroup_id,
1228 tag_types.tag_type_id,
1230 tag_types.description,
1232 tag_types.min_role_id,
1235 INNER JOIN tag_types USING (tag_type_id);
1237 --------------------------------------------------------------------------------
1238 CREATE OR REPLACE VIEW view_sessions AS
1240 sessions.session_id,
1241 CAST(date_part('epoch', sessions.expires) AS bigint) AS expires,
1242 person_session.person_id,
1243 node_session.node_id
1245 LEFT JOIN person_session USING (session_id)
1246 LEFT JOIN node_session USING (session_id);
1248 --------------------------------------------------------------------------------
1249 -- Built-in maintenance account and default site
1250 --------------------------------------------------------------------------------
1252 INSERT INTO persons (first_name, last_name, email, password, enabled)
1253 VALUES ('Maintenance', 'Account', 'maint@localhost.localdomain', 'nopass', true);
1255 INSERT INTO person_role (person_id, role_id) VALUES (1, 10);
1256 INSERT INTO person_role (person_id, role_id) VALUES (1, 20);
1257 INSERT INTO person_role (person_id, role_id) VALUES (1, 30);
1258 INSERT INTO person_role (person_id, role_id) VALUES (1, 40);
1260 INSERT INTO sites (login_base, name, abbreviated_name, max_slices)
1261 VALUES ('pl', 'PlanetLab Central', 'PLC', 100);