Skip to content

Commit f84c81a

Browse files
committed
bug 8533: all IP Address fields in DB have char(40) type
status 8533: resolved fixed
1 parent 89fbaad commit f84c81a

3 files changed

Lines changed: 144 additions & 20 deletions

File tree

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/**
2+
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
3+
*
4+
* This software is licensed under the GNU General Public License v3 or later.
5+
*
6+
* It is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or any later version.
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
*/
18+
19+
package com.cloud.api.commands;
20+
21+
import org.apache.log4j.Logger;
22+
23+
import com.cloud.api.ApiConstants;
24+
import com.cloud.api.BaseCmd;
25+
import com.cloud.api.Implementation;
26+
import com.cloud.api.Parameter;
27+
import com.cloud.api.ServerApiException;
28+
import com.cloud.api.response.NetworkResponse;
29+
import com.cloud.exception.ConcurrentOperationException;
30+
import com.cloud.exception.InsufficientCapacityException;
31+
import com.cloud.exception.InvalidParameterValueException;
32+
import com.cloud.network.Network;
33+
import com.cloud.user.UserContext;
34+
35+
@Implementation(description="Updates a network", responseObject=NetworkResponse.class)
36+
public class UpdateNetworkCmd extends BaseCmd {
37+
public static final Logger s_logger = Logger.getLogger(UpdateNetworkCmd.class.getName());
38+
39+
private static final String s_name = "updatenetworkresponse";
40+
41+
/////////////////////////////////////////////////////
42+
//////////////// API parameters /////////////////////
43+
/////////////////////////////////////////////////////
44+
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the network")
45+
private Long id;
46+
47+
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="the new name for the network")
48+
private String name;
49+
50+
@Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, description="the new display text for the network")
51+
private String displayText;
52+
53+
54+
/////////////////////////////////////////////////////
55+
/////////////////// Accessors ///////////////////////
56+
/////////////////////////////////////////////////////
57+
58+
public Long getId() {
59+
return id;
60+
}
61+
62+
public String getNetworkName() {
63+
return name;
64+
}
65+
66+
public String getDisplayText() {
67+
return displayText;
68+
}
69+
70+
71+
/////////////////////////////////////////////////////
72+
/////////////// API Implementation///////////////////
73+
/////////////////////////////////////////////////////
74+
75+
@Override
76+
public String getCommandName() {
77+
return s_name;
78+
}
79+
80+
@Override
81+
public long getEntityOwnerId() {
82+
Network network = _networkService.getNetwork(id);
83+
if (network == null) {
84+
throw new InvalidParameterValueException("Networkd id=" + id + " doesn't exist");
85+
} else {
86+
return _networkService.getNetwork(id).getAccountId();
87+
}
88+
}
89+
90+
@Override
91+
public void execute() throws InsufficientCapacityException, ConcurrentOperationException{
92+
93+
Network result = _networkService.updateNetwork(getId(), getNetworkName(), getDisplayText(), UserContext.current().getCaller());
94+
if (result != null) {
95+
NetworkResponse response = _responseGenerator.createNetworkResponse(result);
96+
response.setResponseName(getCommandName());
97+
this.setResponseObject(response);
98+
}else {
99+
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update network");
100+
}
101+
}
102+
}

‎setup/db/create-schema.sql‎

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ CREATE TABLE `cloud`.`nics` (
216216
`id` bigint unsigned NOT NULL UNIQUE AUTO_INCREMENT COMMENT 'id',
217217
`instance_id` bigint unsigned COMMENT 'vm instance id',
218218
`mac_address` varchar(17) COMMENT 'mac address',
219-
`ip4_address` varchar(15) COMMENT 'ip4 address',
219+
`ip4_address` char(40) COMMENT 'ip4 address',
220220
`netmask` varchar(15) COMMENT 'netmask for ip4 address',
221221
`gateway` varchar(15) COMMENT 'gateway',
222222
`ip_type` varchar(32) COMMENT 'type of ip',
@@ -300,7 +300,7 @@ CREATE TABLE `cloud`.`op_host_upgrade` (
300300
CREATE TABLE `cloud`.`op_lock` (
301301
`key` varchar(128) NOT NULL UNIQUE COMMENT 'primary key of the table',
302302
`mac` varchar(17) NOT NULL COMMENT 'mac address of who acquired this lock',
303-
`ip` varchar(15) NOT NULL COMMENT 'ip address of who acquired this lock',
303+
`ip` char(40) NOT NULL COMMENT 'ip address of who acquired this lock',
304304
`thread` varchar(255) NOT NULL COMMENT 'Thread that acquired this lock',
305305
`acquired_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Time acquired',
306306
`waiters` int NOT NULL DEFAULT 0 COMMENT 'How many have waited for this',
@@ -371,7 +371,7 @@ CREATE TABLE `cloud`.`volumes` (
371371
`pod_id` bigint unsigned COMMENT 'pod this volume belongs to',
372372
`data_center_id` bigint unsigned NOT NULL COMMENT 'data center this volume belongs to',
373373
`iscsi_name` varchar(255) COMMENT 'iscsi target name',
374-
`host_ip` varchar(15) COMMENT 'host ip address for convenience',
374+
`host_ip` char(40) COMMENT 'host ip address for convenience',
375375
`volume_type` varchar(64) NOT NULL COMMENT 'root, swap or data',
376376
`resource_type` varchar(64) COMMENT 'pool-based or host-based',
377377
`pool_type` varchar(64) COMMENT 'type of the pool',
@@ -490,7 +490,7 @@ CREATE TABLE `cloud`.`data_center` (
490490

491491
CREATE TABLE `cloud`.`op_dc_ip_address_alloc` (
492492
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key',
493-
`ip_address` varchar(15) NOT NULL COMMENT 'ip address',
493+
`ip_address` char(40) NOT NULL COMMENT 'ip address',
494494
`data_center_id` bigint unsigned NOT NULL COMMENT 'data center it belongs to',
495495
`pod_id` bigint unsigned NOT NULL COMMENT 'pod it belongs to',
496496
`instance_id` bigint unsigned NULL COMMENT 'instance id',
@@ -507,7 +507,7 @@ CREATE TABLE `cloud`.`op_dc_ip_address_alloc` (
507507

508508
CREATE TABLE `cloud`.`op_dc_link_local_ip_address_alloc` (
509509
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key',
510-
`ip_address` varchar(15) NOT NULL COMMENT 'ip address',
510+
`ip_address` char(40) NOT NULL COMMENT 'ip address',
511511
`data_center_id` bigint unsigned NOT NULL COMMENT 'data center it belongs to',
512512
`pod_id` bigint unsigned NOT NULL COMMENT 'pod it belongs to',
513513
`instance_id` bigint unsigned NULL COMMENT 'instance id',
@@ -600,17 +600,17 @@ CREATE TABLE `cloud`.`host` (
600600
`name` varchar(255) NOT NULL,
601601
`status` varchar(32) NOT NULL,
602602
`type` varchar(32) NOT NULL,
603-
`private_ip_address` varchar(15) NOT NULL,
603+
`private_ip_address` char(40) NOT NULL,
604604
`private_netmask` varchar(15),
605605
`private_mac_address` varchar(17),
606-
`storage_ip_address` varchar(15) NOT NULL,
606+
`storage_ip_address` char(40) NOT NULL,
607607
`storage_netmask` varchar(15),
608608
`storage_mac_address` varchar(17),
609-
`storage_ip_address_2` varchar(15),
609+
`storage_ip_address_2` char(40),
610610
`storage_mac_address_2` varchar(17),
611611
`storage_netmask_2` varchar(15),
612612
`cluster_id` bigint unsigned COMMENT 'foreign key to cluster',
613-
`public_ip_address` varchar(15),
613+
`public_ip_address` char(40),
614614
`public_netmask` varchar(15),
615615
`public_mac_address` varchar(17),
616616
`proxy_port` int(10) unsigned,
@@ -667,7 +667,7 @@ CREATE TABLE `cloud`.`mshost` (
667667
`msid` bigint unsigned NOT NULL UNIQUE COMMENT 'management server id derived from MAC address',
668668
`name` varchar(255),
669669
`version` varchar(255),
670-
`service_ip` varchar(15) NOT NULL,
670+
`service_ip` char(40) NOT NULL,
671671
`service_port` integer NOT NULL,
672672
`last_update` DATETIME NULL COMMENT 'Last record update time',
673673
`removed` datetime COMMENT 'date removed if not null',
@@ -746,7 +746,7 @@ CREATE TABLE `cloud`.`user_statistics` (
746746
`id` bigint unsigned UNIQUE NOT NULL AUTO_INCREMENT,
747747
`data_center_id` bigint unsigned NOT NULL,
748748
`account_id` bigint unsigned NOT NULL,
749-
`public_ip_address` varchar(15),
749+
`public_ip_address` char(40),
750750
`device_id` bigint unsigned NOT NULL,
751751
`device_type` varchar(32) NOT NULL,
752752
`network_id` bigint unsigned,
@@ -792,7 +792,7 @@ CREATE TABLE `cloud`.`vm_instance` (
792792
`vm_template_id` bigint unsigned,
793793
`guest_os_id` bigint unsigned NOT NULL,
794794
`private_mac_address` varchar(17),
795-
`private_ip_address` varchar(15),
795+
`private_ip_address` char(40),
796796
`private_netmask` varchar(15),
797797
`pod_id` bigint unsigned,
798798
`data_center_id` bigint unsigned NOT NULL COMMENT 'Data Center the instance belongs to',
@@ -834,7 +834,7 @@ CREATE TABLE `cloud`.`user_vm` (
834834
`id` bigint unsigned UNIQUE NOT NULL,
835835
`iso_id` bigint unsigned,
836836
`display_name` varchar(255),
837-
`guest_ip_address` varchar(15) COMMENT 'ip address within the guest network',
837+
`guest_ip_address` char(40) COMMENT 'ip address within the guest network',
838838
`guest_mac_address` varchar(17) COMMENT 'mac address within the guest network',
839839
`guest_netmask` varchar(15) COMMENT 'netmask within the guest network',
840840
`user_data` varchar(2048),
@@ -855,10 +855,10 @@ CREATE TABLE `cloud`.`user_vm_details` (
855855
CREATE TABLE `cloud`.`domain_router` (
856856
`id` bigint unsigned UNIQUE NOT NULL COMMENT 'Primary Key',
857857
`public_mac_address` varchar(17) COMMENT 'mac address of the public facing network card',
858-
`public_ip_address` varchar(15) COMMENT 'public ip address used for source net',
858+
`public_ip_address` char(40) COMMENT 'public ip address used for source net',
859859
`public_netmask` varchar(15) COMMENT 'netmask used for the domR',
860860
`guest_netmask` varchar(15) COMMENT 'netmask used for the guest network',
861-
`guest_ip_address` varchar(15) COMMENT ' ip address in the guest network',
861+
`guest_ip_address` char(40) COMMENT ' ip address in the guest network',
862862
`network_id` bigint unsigned NOT NULL DEFAULT 0 COMMENT 'network configuration that this domain router belongs to',
863863
`role` varchar(64) NOT NULL COMMENT 'type of role played by this router',
864864
PRIMARY KEY (`id`),
@@ -924,7 +924,7 @@ CREATE TABLE `cloud`.`template_zone_ref` (
924924
CREATE TABLE `cloud`.`console_proxy` (
925925
`id` bigint unsigned NOT NULL auto_increment,
926926
`public_mac_address` varchar(17) unique COMMENT 'mac address of the public facing network card',
927-
`public_ip_address` varchar(15) UNIQUE COMMENT 'public ip address for the console proxy',
927+
`public_ip_address` char(40) UNIQUE COMMENT 'public ip address for the console proxy',
928928
`public_netmask` varchar(15) COMMENT 'public netmask used for the console proxy',
929929
`active_session` int(10) NOT NULL DEFAULT 0 COMMENT 'active session number',
930930
`last_update` DATETIME NULL COMMENT 'Last session update time',
@@ -936,7 +936,7 @@ CREATE TABLE `cloud`.`console_proxy` (
936936
CREATE TABLE `cloud`.`secondary_storage_vm` (
937937
`id` bigint unsigned NOT NULL auto_increment,
938938
`public_mac_address` varchar(17) unique COMMENT 'mac address of the public facing network card',
939-
`public_ip_address` varchar(15) UNIQUE COMMENT 'public ip address for the sec storage vm',
939+
`public_ip_address` char(40) UNIQUE COMMENT 'public ip address for the sec storage vm',
940940
`public_netmask` varchar(15) COMMENT 'public netmask used for the sec storage vm',
941941
`guid` varchar(255) COMMENT 'copied from guid of secondary storage host',
942942
`nfs_share` varchar(255) COMMENT 'server and path exported by the nfs server ',
@@ -1128,7 +1128,7 @@ CREATE TABLE `cloud`.`load_balancer` (
11281128
`name` varchar(255) NOT NULL,
11291129
`description` varchar(4096) NULL,
11301130
`account_id` bigint unsigned NOT NULL,
1131-
`ip_address` varchar(15) NOT NULL,
1131+
`ip_address` char(40) NOT NULL,
11321132
`public_port` varchar(10) NOT NULL,
11331133
`private_port` varchar(10) NOT NULL,
11341134
`algorithm` varchar(255) NOT NULL,
@@ -1140,7 +1140,7 @@ CREATE TABLE `cloud`.`remote_access_vpn` (
11401140
`account_id` bigint unsigned NOT NULL,
11411141
`network_id` bigint unsigned NOT NULL,
11421142
`domain_id` bigint unsigned NOT NULL,
1143-
`local_ip` varchar(15) NOT NULL,
1143+
`local_ip` char(40) NOT NULL,
11441144
`ip_range` varchar(32) NOT NULL,
11451145
`ipsec_psk` varchar(256) NOT NULL,
11461146
`state` char(32) NOT NULL,
@@ -1176,7 +1176,7 @@ CREATE TABLE `cloud`.`storage_pool` (
11761176
`cluster_id` bigint unsigned COMMENT 'foreign key to cluster',
11771177
`available_bytes` bigint unsigned,
11781178
`capacity_bytes` bigint unsigned,
1179-
`host_address` varchar(255) NOT NULL COMMENT 'FQDN or IP of storage server',
1179+
`host_address` char(40) NOT NULL COMMENT 'FQDN or IP of storage server',
11801180
`path` varchar(255) NOT NULL COMMENT 'Filesystem path that is shared',
11811181
`created` datetime COMMENT 'date the pool created',
11821182
`removed` datetime COMMENT 'date removed if not null',

‎setup/db/schema-222to224.sql‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,25 @@ CREATE TABLE `cloud`.`domain_network_ref` (
1414
CONSTRAINT `fk_domain_network_ref__domain_id` FOREIGN KEY (`domain_id`) REFERENCES `domain`(`id`) ON DELETE CASCADE,
1515
CONSTRAINT `fk_domain_network_ref__networks_id` FOREIGN KEY (`network_id`) REFERENCES `networks`(`id`) ON DELETE CASCADE
1616
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
17+
18+
ALTER TABLE `cloud`.`nics` MODIFY `ip4_address` char(40);
19+
ALTER TABLE `cloud`.`op_lock` MODIFY `ip` char(40) NOT NULL;
20+
ALTER TABLE `cloud`.`volumes` MODIFY `host_ip` char(40);
21+
ALTER TABLE `cloud`.`op_dc_ip_address_alloc` MODIFY `ip_address` char(40) NOT NULL;
22+
ALTER TABLE `cloud`.`op_dc_link_local_ip_address_alloc` MODIFY `ip_address` char(40) NOT NULL;
23+
ALTER TABLE `cloud`.`host` MODIFY `private_ip_address` char(40) NOT NULL;
24+
ALTER TABLE `cloud`.`host` MODIFY `storage_ip_address` char(40) NOT NULL;
25+
ALTER TABLE `cloud`.`host` MODIFY `storage_ip_address_2` char(40);
26+
ALTER TABLE `cloud`.`host` MODIFY `public_ip_address` char(40);
27+
ALTER TABLE `cloud`.`mshost` MODIFY `service_ip` char(40) NOT NULL;
28+
ALTER TABLE `cloud`.`user_statistics` MODIFY `public_ip_address` char(40);
29+
ALTER TABLE `cloud`.`vm_instance` MODIFY `private_ip_address` char(40);
30+
ALTER TABLE `cloud`.`user_vm` MODIFY `guest_ip_address` char(40);
31+
ALTER TABLE `cloud`.`domain_router` MODIFY `public_ip_address` char(40);
32+
ALTER TABLE `cloud`.`domain_router` MODIFY `guest_ip_address` char(40);
33+
ALTER TABLE `cloud`.`console_proxy` MODIFY `public_ip_address` char(40) UNIQUE;
34+
ALTER TABLE `cloud`.`secondary_storage_vm` MODIFY `public_ip_address` char(40) UNIQUE;
35+
ALTER TABLE `cloud`.`load_balancer` MODIFY `ip_address` char(40) NOT NULL;
36+
ALTER TABLE `cloud`.`remote_access_vpn` MODIFY `local_ip` char(40) NOT NULL;
37+
ALTER TABLE `cloud`.`storage_pool` MODIFY `host_address` char(40) NOT NULL;
38+

0 commit comments

Comments
 (0)