From 3af54ec1a8313c51c0faf98bf41e99450a3d0079 Mon Sep 17 00:00:00 2001 From: Frank Maximus Date: Thu, 7 Jun 2018 07:48:24 +0200 Subject: [PATCH 1/3] CLOUDSTACK-10382: Fix cloud-get-vm-data-configdrive.in (#2688) --- setup/bindir/cloud-get-vm-data-configdrive.in | 62 ++++++++----------- 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/setup/bindir/cloud-get-vm-data-configdrive.in b/setup/bindir/cloud-get-vm-data-configdrive.in index 946ec3b1cdf..c6b70be321b 100644 --- a/setup/bindir/cloud-get-vm-data-configdrive.in +++ b/setup/bindir/cloud-get-vm-data-configdrive.in @@ -21,23 +21,28 @@ mountdir=$(mktemp -d) filepath=$mountdir/cloudstack user_data=$filepath/userdata/user_data.txt -availability_zone=$filepath/metadata/availability_zone.txt -cloud_identifier=$filepath/metadata/cloud_identifier.txt -instance_id=$filepath/metadata/instance_id.txt -local_hostname=$filepath/metadata/local_hostname.txt -service_offering=$filepath/metadata/service_offering.txt -vm_id=$filepath/metadata/vm_id.txt -public_key=$filepath/metadata/public_keys.txt vm_password=$filepath/password/vm_password.txt +declare -A metadata=( +["availability-zone"]=$filepath/metadata/availability-zone.txt +["cloud-identifier"]=$filepath/metadata/cloud-identifier.txt +["instance-id"]=$filepath/metadata/instance-id.txt +["local-hostname"]=$filepath/metadata/local-hostname.txt +["local-ipv4"]=$filepath/metadata/local-ipv4.txt +["public-ipv4"]=$filepath/metadata/public-ipv4.txt +["service-offering"]=$filepath/metadata/service-offering.txt +["vm-id"]=$filepath/metadata/vm-id.txt +["public-key"]=$filepath/metadata/public-keys.txt +) # If lable name is other than config, please change the below line as required DefaultDisk=/dev/disk/by-label/config-2 function usage { + keys=${!metadata[@]} echo -e "USAGE: cloud-get-vm-data -options" echo -e " where options include:" - echo -e "\\t-m | --metadata [availability-zone | cloud-identifier | instance-id | local-hostname | service-offering | vm-id | public-key] \\n\\t\\tprint vm metadata" + echo -e "\\t-m | --metadata [${keys// / | }] \\n\\t\\tprint vm metadata" echo -e "\\t-p | --password \\n\\t\\tprint vm password" echo -e "\\t-u | --userdata \\n\\t\\tprint vm userdata" } @@ -52,7 +57,7 @@ function prepare_mount if [ -e $DefaultDisk ]; then Disk=$DefaultDisk else - BLOCK_DEVICE=$(blkid -t LABEL='config' /dev/hd? /dev/sd? /dev/xvd? -o device) + BLOCK_DEVICE=$(blkid -t LABEL='config-2' /dev/sr? /dev/hd? /dev/sd? /dev/xvd? -o device) if [ -n $BLOCK_DEVICE ]; then Disk=$BLOCK_DEVICE else @@ -81,34 +86,21 @@ case $1 in ;; -m | --metadata ) shift if [ "$1" != "" ]; then - case $1 in - availability-zone ) echo -n "availability zone: "; filename=$availability_zone - ;; - cloud-identifier ) echo -n "cloud identifier: "; filename=$cloud_identifier - ;; - instance-id ) echo -n "instance-id: "; filename=$instance_id - ;; - local-hostname ) echo -n "local-hostname: "; filename=$local_hostname - ;; - service-offering ) echo -n "service-offering: "; filename=$service_offering - ;; - vm-id ) echo -n "vm-id: "; filename=$vm_id - ;; - public-key ) echo -n "public-key: "; filename=$public_key - ;; - * ) usage - remove_mount - exit 1 - esac + if [ -n "${metadata[$1]}" ]; then + echo -n "$1: " + filename=${metadata[$1]} + else + usage + remove_mount + exit 1 + fi else echo -e "METADATA\\n" - [ -f $availability_zone ] && echo -e "availability zone:\t" "$(cat $availability_zone)" - [ -f $cloud_identifier ] && echo -e "cloud identifier:\t" "$(cat $cloud_identifier)" - [ -f $instance_id ] && echo -e "instance-id:\t\t" "$(cat $instance_id)" - [ -f $local_hostname ] && echo -e "local-hostname:\t\t" "$(cat $local_hostname)" - [ -f $service_offering ] && echo -e "service-offering:\t" "$(cat $service_offering)" - [ -f $vm_id ] && echo -e "vm-id:\t\t\t" "$(cat $vm_id)" - [ -f $public_key ] && echo -e "public-key:\t\t" "$(cat $public_key)" + for entry in "${!metadata[@]}" + do + file=${metadata[$entry]} + [ -f $file ] && printf "%18s :\t%s\n" $entry "$(cat $file)" + done fi ;; -p | --password ) echo -n "PASSWORD: " From 99ca81a676006cc5d351bd94e32e284256d00b4a Mon Sep 17 00:00:00 2001 From: Nicolas Vazquez Date: Thu, 7 Jun 2018 02:50:37 -0300 Subject: [PATCH 2/3] ui: do not send conserve mode on L2 network offering creation from the UI (#2694) Do not send conserve mode param on L2 network offering creation from the UI. Fix config drive NPE issue on L2 network. --- .../storage/configdrive/ConfigDriveBuilder.java | 2 +- ui/scripts/configuration.js | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/engine/storage/configdrive/src/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilder.java b/engine/storage/configdrive/src/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilder.java index dc6b8893495..55e7979a772 100644 --- a/engine/storage/configdrive/src/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilder.java +++ b/engine/storage/configdrive/src/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilder.java @@ -286,7 +286,7 @@ public class ConfigDriveBuilder { if (!NetworkModel.METATDATA_DIR.equals(dataType)) { return; } - if (StringUtils.isNotBlank(content)) { + if (StringUtils.isEmpty(content)) { return; } //keys are a special case in OpenStack format diff --git a/ui/scripts/configuration.js b/ui/scripts/configuration.js index 2eee7bbeae0..f229d24b19e 100644 --- a/ui/scripts/configuration.js +++ b/ui/scripts/configuration.js @@ -2412,14 +2412,17 @@ if ($useVpcCb.is(':checked')) { //if useVpc is checked, $useVpcCb.removeAttr("checked"); //remove "checked" attribute in useVpc } + $conservemode.css('display', 'inline-block'); } else if ($guestTypeField.val() == 'Isolated') { //Isolated network offering $useVpc.css('display', 'inline-block'); $supportedServices.css('display', 'inline-block'); $userDataL2.hide(); + $conservemode.css('display', 'inline-block'); } else if ($guestTypeField.val() == 'L2') { $useVpc.hide(); $supportedServices.hide(); $userDataL2.css('display', 'inline-block'); + $conservemode.hide(); } var $providers = $useVpcCb.closest('form').find('.dynamic-input select[name!="service.Connectivity.provider"]'); var $optionsOfProviders = $providers.find('option'); @@ -3403,6 +3406,9 @@ } else { delete inputData.serviceProviderList; } + + //Conserve mode is irrelevant on L2 network offerings as there are no resources to conserve, do not pass it, true by default on server side + delete inputData.conservemode; } if (inputData['forvpc'] == 'on') { @@ -3411,10 +3417,12 @@ delete inputData.forvpc; //if forVpc checkbox is unchecked, do not pass forVpc parameter to API call since we need to keep API call's size as small as possible (p.s. forVpc is defaulted as false at server-side) } - if (inputData['conservemode'] == 'on') { - delete inputData.conservemode; //if ConserveMode checkbox is checked, do not pass conservemode parameter to API call since we need to keep API call's size as small as possible (p.s. conservemode is defaulted as true at server-side) - } else { - inputData['conservemode'] = false; + if (inputData['guestIpType'] == "Shared" || inputData['guestIpType'] == "Isolated") { + if (inputData['conservemode'] == 'on') { + delete inputData.conservemode; //if ConserveMode checkbox is checked, do not pass conservemode parameter to API call since we need to keep API call's size as small as possible (p.s. conservemode is defaulted as true at server-side) + } else { + inputData['conservemode'] = false; + } } // Make service provider map From 76367db8fb1aef0f58a9359c193548985def3d92 Mon Sep 17 00:00:00 2001 From: Nicolas Vazquez Date: Thu, 7 Jun 2018 02:53:35 -0300 Subject: [PATCH 3/3] L2: add default L2 network offerings (#2683) Adds default L2 network offerings. Adds check for existing default L2 networks. --- .../com/cloud/offering/NetworkOffering.java | 4 ++ .../orchestration/NetworkOrchestrator.java | 2 + .../offerings/dao/NetworkOfferingDao.java | 5 ++ .../offerings/dao/NetworkOfferingDaoImpl.java | 48 +++++++++++++++++++ .../cloud/server/ConfigurationServerImpl.java | 2 + 5 files changed, 61 insertions(+) diff --git a/api/src/com/cloud/offering/NetworkOffering.java b/api/src/com/cloud/offering/NetworkOffering.java index 0c8378908e6..33b165bfa29 100644 --- a/api/src/com/cloud/offering/NetworkOffering.java +++ b/api/src/com/cloud/offering/NetworkOffering.java @@ -57,6 +57,10 @@ public interface NetworkOffering extends InfrastructureEntity, InternalIdentity, public final static String DefaultIsolatedNetworkOfferingForVpcNetworks = "DefaultIsolatedNetworkOfferingForVpcNetworks"; public final static String DefaultIsolatedNetworkOfferingForVpcNetworksNoLB = "DefaultIsolatedNetworkOfferingForVpcNetworksNoLB"; public final static String DefaultIsolatedNetworkOfferingForVpcNetworksWithInternalLB = "DefaultIsolatedNetworkOfferingForVpcNetworksWithInternalLB"; + public final static String DefaultL2NetworkOffering = "DefaultL2NetworkOffering"; + public final static String DefaultL2NetworkOfferingVlan = "DefaultL2NetworkOfferingVlan"; + public final static String DefaultL2NetworkOfferingConfigDrive = "DefaultL2NetworkOfferingConfigDrive"; + public final static String DefaultL2NetworkOfferingConfigDriveVlan = "DefaultL2NetworkOfferingConfigDriveVlan"; /** * @return name for the network offering. diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java index 8f436467812..b5aca5d9f10 100644 --- a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java +++ b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java @@ -561,6 +561,8 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra offering.setDedicatedLB(false); _networkOfferingDao.update(offering.getId(), offering); } + + _networkOfferingDao.persistDefaultL2NetworkOfferings(); } }); diff --git a/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDao.java b/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDao.java index 19beddd1001..238a191bd77 100644 --- a/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDao.java +++ b/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDao.java @@ -64,4 +64,9 @@ public interface NetworkOfferingDao extends GenericDao List listNetworkOfferingID(); boolean isUsingServicePackage(String uuid); + + /** + * Create default L2 network offerings + */ + void persistDefaultL2NetworkOfferings(); } diff --git a/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDaoImpl.java b/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDaoImpl.java index b0cf0fe320b..5c40795a56b 100644 --- a/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDaoImpl.java +++ b/engine/schema/src/com/cloud/offerings/dao/NetworkOfferingDaoImpl.java @@ -23,6 +23,7 @@ import java.util.Map; import javax.inject.Inject; import javax.persistence.EntityExistsException; +import com.cloud.offerings.NetworkOfferingServiceMapVO; import org.apache.commons.collections.CollectionUtils; import org.springframework.stereotype.Component; @@ -52,6 +53,8 @@ public class NetworkOfferingDaoImpl extends GenericDaoBase UpgradeSearch; @Inject NetworkOfferingDetailsDao _detailsDao; + @Inject + private NetworkOfferingServiceMapDao networkOfferingServiceMapDao; protected NetworkOfferingDaoImpl() { super(); @@ -221,4 +224,49 @@ public class NetworkOfferingDaoImpl extends GenericDaoBase