@@ -50,7 +50,43 @@ protected void upgradeStoragePools(Connection conn) {
5050 } catch (SQLException e ) {
5151 throw new CloudRuntimeException ("Can't upgrade storage pool " , e );
5252 }
53-
53+ }
54+
55+ protected long insertNetworkOffering (Connection conn , String name , String displayText ,
56+ String trafficType , boolean systemOnly , boolean defaultNetworkOffering ,
57+ String availability , boolean dns_service , boolean gateway_service ,
58+ boolean firewall_service , boolean lb_service ,
59+ boolean userdata_service , boolean vpn_service ,
60+ boolean dhcp_service , String guest_type ) {
61+ String insertSql =
62+ "INSERT INTO network_offerings (name, display_text, nw_rate, mc_rate, concurrent_connections, traffic_type, tags, system_only, specify_vlan, service_offering_id, created, removed, default, availability, dns_service, gateway_service, firewall_service, lb_service, userdata_service, vpn_service, dhcp_service, guest_type) " +
63+ "VALUES (?, ?, NULL, NULL, NULL, ?, NULL, ?, 0, NULL, now(), NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" ;
64+ try {
65+ PreparedStatement pstmt = conn .prepareStatement (insertSql );
66+ int i = 1 ;
67+ pstmt .setString (i ++, name );
68+ pstmt .setString (i ++, displayText );
69+ pstmt .setString (i ++, trafficType );
70+ pstmt .setBoolean (i ++, systemOnly );
71+ pstmt .setBoolean (i ++, defaultNetworkOffering );
72+ pstmt .setString (i ++, availability );
73+ pstmt .setBoolean (i ++, dns_service );
74+ pstmt .setBoolean (i ++, gateway_service );
75+ pstmt .setBoolean (i ++, firewall_service );
76+ pstmt .setBoolean (i ++, lb_service );
77+ pstmt .setBoolean (i ++, userdata_service );
78+ pstmt .setBoolean (i ++, vpn_service );
79+ pstmt .setBoolean (i ++, dhcp_service );
80+ pstmt .setString (i ++, guest_type );
81+ pstmt .executeUpdate ();
82+ ResultSet rs = pstmt .getGeneratedKeys ();
83+ rs .close ();
84+ pstmt .close ();
85+ long id = rs .getLong (1 );
86+ return id ;
87+ } catch (SQLException e ) {
88+ throw new CloudRuntimeException ("Unable to insert network offering " , e );
89+ }
5490 }
5591
5692 protected void insertNetwork (Connection conn , String name , String displayText , String trafficType , String broadcastDomainType , String broadcastUri ,
@@ -59,8 +95,8 @@ protected void insertNetwork(Connection conn, String name, String displayText, S
5995 String networkDomain , boolean isDefault ) {
6096 String getNextNetworkSequenceSql = "SELECT value from sequence where name='networks_seq'" ;
6197 String advanceNetworkSequenceSql = "UPDATE sequence set value=value+1 where name='networks_seq'" ;
62- String insertNetworkSql = "INSERT INTO NETWORKS (id, name, display_text, traffic_type, broadcast_domain_type, gateway, cidr, mode, network_offering_id, data_center_id, guru_name, state, domain_id, account_id, dns1, dns2, guest_type, shared, is_default, created, network_domain) " +
63- "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, , false , true , now(), ?)" ;
98+ String insertNetworkSql = "INSERT INTO networks (id, name, display_text, traffic_type, broadcast_domain_type, gateway, cidr, mode, network_offering_id, data_center_id, guru_name, state, domain_id, account_id, dns1, dns2, guest_type, shared, is_default, created, network_domain, related ) " +
99+ "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? , ? , ? , now(), ?, ?)" ;
64100 try {
65101 PreparedStatement pstmt = conn .prepareStatement (getNextNetworkSequenceSql );
66102 ResultSet rs = pstmt .executeQuery ();
@@ -95,6 +131,7 @@ protected void insertNetwork(Connection conn, String name, String displayText, S
95131 pstmt .setBoolean (i ++, shared );
96132 pstmt .setBoolean (i ++, isDefault );
97133 pstmt .setString (i ++, networkDomain );
134+ pstmt .setLong (i ++, seq );
98135 pstmt .executeUpdate ();
99136 } catch (SQLException e ) {
100137 throw new CloudRuntimeException ("Unable to create network" , e );
@@ -132,39 +169,77 @@ protected void upgradeDataCenter(Connection conn) {
132169 pstmt .executeUpdate ();
133170 pstmt .close ();
134171
172+ pstmt = conn .prepareStatement ("SELECT id FROM data_center" );
173+ rs = pstmt .executeQuery ();
174+ ArrayList <Long > dcs = new ArrayList <Long >();
175+ while (rs .next ()) {
176+ dcs .add (rs .getLong (1 ));
177+ }
178+ rs .close ();
179+ pstmt .close ();
180+
181+ pstmt = conn .prepareStatement ("SELECT id FROM network_offerings WHERE name='System-Management-Network'" );
182+ rs = pstmt .executeQuery ();
183+ if (!rs .next ()) {
184+ throw new CloudRuntimeException ("Unable to find the management network offering." );
185+ }
186+ long managementNetworkOfferingId = rs .getLong (1 );
187+ rs .close ();
188+ pstmt .close ();
189+
190+ pstmt = conn .prepareStatement ("SELECT id FROM network_offerings WHERE name='System-Public-Network'" );
191+ rs = pstmt .executeQuery ();
192+ if (!rs .next ()) {
193+ throw new CloudRuntimeException ("Unable to find the public network offering." );
194+ }
195+ long publicNetworkOfferingId = rs .getLong (1 );
196+ rs .close ();
197+ pstmt .close ();
198+
199+ pstmt = conn .prepareStatement ("SELECT id FROM network_offerings WHERE name='System-Control-Network'" );
200+ rs = pstmt .executeQuery ();
201+ if (!rs .next ()) {
202+ throw new CloudRuntimeException ("Unable to find the control network offering." );
203+ }
204+ long controlNetworkOfferingId = rs .getLong (1 );
205+ rs .close ();
206+ pstmt .close ();
207+
208+ pstmt = conn .prepareStatement ("SELECT id FROM network_offerings WHERE name='System-Storage-Network'" );
209+ rs = pstmt .executeQuery ();
210+ if (!rs .next ()) {
211+ throw new CloudRuntimeException ("Unable to find the storage network offering." );
212+ }
213+ long storageNetworkOfferingId = rs .getLong (1 );
214+ rs .close ();
215+ pstmt .close ();
216+
217+ for (Long dcId : dcs ) {
218+ insertNetwork (conn , "ManagementNetwork" + dcId , "Management Network created for Zone " + dcId , "Management" , "Native" , null , null , null , "Static" , managementNetworkOfferingId , dcId , "PodBasedNetworkGuru" , "Setup" , 1 , 1 , null , null , null , true , null , false );
219+ insertNetwork (conn , "StorageNetwork" + dcId , "Storage Network created for Zone " + dcId , "Storage" , "Native" , null , null , null , "Static" , storageNetworkOfferingId , dcId , "PodBasedNetworkGuru" , "Setup" , 1 , 1 , null , null , null , true , null , false );
220+ insertNetwork (conn , "ControlNetwork" + dcId , "Control Network created for Zone " + dcId , "Control" , "Native" , null , null , null , "Static" , publicNetworkOfferingId , dcId , "PublicNetworkGuru" , "Setup" , 1 , 1 , null , null , null , true , null , false );
221+ }
222+
223+
135224 if (_basicZone ) {
136- // CREATE TABLE `networks` (
137- // `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
138- // `name` varchar(255) DEFAULT NULL COMMENT 'name for this network',
139- // `display_text` varchar(255) DEFAULT NULL COMMENT 'display text for this network',
140- // `traffic_type` varchar(32) NOT NULL COMMENT 'type of traffic going through this network',
141- // `broadcast_domain_type` varchar(32) NOT NULL COMMENT 'type of broadcast domain used',
142- // `broadcast_uri` varchar(255) DEFAULT NULL COMMENT 'broadcast domain specifier',
143- // `gateway` varchar(15) DEFAULT NULL COMMENT 'gateway for this network configuration',
144- // `cidr` varchar(18) DEFAULT NULL COMMENT 'network cidr',
145- // `mode` varchar(32) DEFAULT NULL COMMENT 'How to retrieve ip address in this network',
146- // `network_offering_id` bigint(20) unsigned NOT NULL COMMENT 'network offering id that this configuration is created from',
147- // `data_center_id` bigint(20) unsigned NOT NULL COMMENT 'data center id that this configuration is used in',
148- // `guru_name` varchar(255) NOT NULL COMMENT 'who is responsible for this type of network configuration',
149- // `state` varchar(32) NOT NULL COMMENT 'what state is this configuration in',
150- // `related` bigint(20) unsigned NOT NULL COMMENT 'related to what other network configuration',
151- // `domain_id` bigint(20) unsigned NOT NULL COMMENT 'foreign key to domain id',
152- // `account_id` bigint(20) unsigned NOT NULL COMMENT 'owner of this network',
153- // `dns1` varchar(255) DEFAULT NULL COMMENT 'comma separated DNS list',
154- // `dns2` varchar(255) DEFAULT NULL COMMENT 'comma separated DNS list',
155- // `guru_data` varchar(1024) DEFAULT NULL COMMENT 'data stored by the netwolrk guru that setup this network',
156- // `set_fields` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT 'which fields are set already',
157- // `guest_type` char(32) DEFAULT NULL COMMENT 'type of guest network',
158- // `shared` int(1) unsigned NOT NULL DEFAULT '0' COMMENT '0 if network is shared, 1 if network dedicated',
159- // `network_domain` varchar(255) DEFAULT NULL COMMENT 'domain',
160- // `reservation_id` char(40) DEFAULT NULL COMMENT 'reservation id',
161- // `is_default` int(1) unsigned NOT NULL DEFAULT '0' COMMENT '1 if network is default',
162- // `created` datetime NOT NULL COMMENT 'date created',
163- // `removed` datetime DEFAULT NULL COMMENT 'date removed if not null',
164- // `is_security_group_enabled` tinyint(4) NOT NULL DEFAULT '0' COMMENT '1: enabled, 0: not',
165- // (200,NULL,NULL,'Management','Native',NULL,NULL,NULL,'Static',2,1,'PodBasedNetworkGuru','Setup',200,1,1,NULL,NULL,NULL,0,NULL,1,NULL,NULL,0,now(),NULL,0)
225+ long networkOfferingId = insertNetworkOffering (conn , "System-Guest-Network" , "System-Guest-Network" , "Guest" , false , true , "Required" , true , false , false , false , true , false , true , "Direct" );
226+ for (Long dcId : dcs ) {
227+ // (200,NULL,NULL,'Management','Native',NULL,NULL,NULL,'Static',2,1,'PodBasedNetworkGuru','Setup',200,1,1,NULL,NULL,NULL,0,NULL,1,NULL,NULL,0,'2011-03-01 03:18:53',NULL,0),
228+ // (201,NULL,NULL,'Control','LinkLocal',NULL,'169.254.0.1','169.254.0.0/16','Static',3,1,'ControlNetworkGuru','Setup',201,1,1,NULL,NULL,NULL,0,NULL,1,NULL,NULL,0,'2011-03-01 03:18:53',NULL,0),
229+ // (202,NULL,NULL,'Storage','Native',NULL,NULL,NULL,'Static',4,1,'PodBasedNetworkGuru','Setup',202,1,1,NULL,NULL,NULL,0,NULL,1,NULL,NULL,0,'2011-03-01 03:18:53',NULL,0),
230+ // (203,NULL,NULL,'Guest','Native',NULL,NULL,NULL,'Dhcp',5,1,'DirectPodBasedNetworkGuru','Setup',203,1,1,NULL,NULL,NULL,0,'Direct',1,NULL,NULL,1,'2011-03-01 03:18:53',NULL,1);
231+ // (1,'System-Public-Network','System Offering for System-Public-Network',NULL,NULL,NULL,'Public',NULL,1,0,NULL,'2011-03-01 03:18:01',NULL,0,'Required',0,0,0,0,0,0,0,NULL),
232+ // (2,'System-Management-Network','System Offering for System-Management-Network',NULL,NULL,NULL,'Management',NULL,1,0,NULL,'2011-03-01 03:18:01',NULL,0,'Required',0,0,0,0,0,0,0,NULL),
233+ // (3,'System-Control-Network','System Offering for System-Control-Network',NULL,NULL,NULL,'Control',NULL,1,0,NULL,'2011-03-01 03:18:01',NULL,0,'Required',0,0,0,0,0,0,0,NULL),
234+ // (4,'System-Storage-Network','System Offering for System-Storage-Network',NULL,NULL,NULL,'Storage',NULL,1,0,NULL,'2011-03-01 03:18:02',NULL,0,'Required',0,0,0,0,0,0,0,NULL),
235+ // (5,'System-Guest-Network','System-Guest-Network',NULL,NULL,NULL,'Guest',NULL,1,0,NULL,'2011-03-01 03:18:02',NULL,1,'Required',1,0,0,0,1,0,1,'Direct'),
236+ // (6,'DefaultVirtualizedNetworkOffering','Virtual Vlan',NULL,NULL,NULL,'Guest',NULL,0,0,NULL,'2011-03-01 03:18:02',NULL,1,'Required',1,1,1,1,1,1,1,'Virtual'),
237+ // (7,'DefaultDirectNetworkOffering','Direct',NULL,NULL,NULL,'Guest',NULL,0,0,NULL,'2011-03-01 03:18:02',NULL,1,'Required',1,0,0,0,1,0,1,'Direct');
238+ pstmt = conn .prepareStatement ("INSERT INTO network_offerings VALUES ('System-Guest-Network','System-Guest-Network',NULL,NULL,NULL,'Guest',NULL,1,0,NULL,now(),NULL,1,'Required',1,0,0,0,1,0,1,'Direct')" );
239+
240+ insertNetwork (conn , "BasicZoneDirectNetwork" + dcId , "Basic Zone Direct Network created for Zone " + dcId , "Guest" , "Native" , null , null , null , "Dhcp" , networkOfferingId , dcId , "DirectPodBasedNetworkGuru" , "Setup" , 1 , 1 , null , null , null , true , null , false );
241+ }
166242
167- // insertNetwork(conn, "BasicZoneNetwork", "Network created for Basic Zone " + dataCenterId, "Management", "Native", null, null, null, "Static", 2, 1, )
168243 } else {
169244 }
170245 } catch (SQLException e ) {
0 commit comments