├── version ├── src ├── main │ ├── resources │ │ ├── buildInfo.properties │ │ ├── validation.properties │ │ ├── deployment │ │ │ ├── isolinux_esxi.cfg │ │ │ ├── isolinux_esx.cfg │ │ │ ├── ksESX-noomsa.cfg │ │ │ ├── ksESXI-noomsa.cfg │ │ │ ├── ksESXI5-noomsa.cfg │ │ │ ├── ksESX.cfg │ │ │ ├── ksESXI.cfg │ │ │ └── ksESXI5.cfg │ │ └── bootstrap.yml │ └── java │ │ └── com │ │ └── dell │ │ └── isg │ │ └── smi │ │ └── osdeployment │ │ ├── BuildInfo.java │ │ ├── Application.java │ │ ├── model │ │ ├── Version.java │ │ ├── MessageKey.java │ │ ├── NetworkSettings.java │ │ ├── ObmRequestBase.java │ │ ├── ServiceResponse.java │ │ ├── BootableIsoRequest.java │ │ ├── CreateIsoResponse.java │ │ ├── DeploymentISOType.java │ │ ├── ServerStatusEnum.java │ │ ├── InstallationTypeEnum.java │ │ └── IsoConfigProperties.java │ │ ├── SimpleCORSFilter.java │ │ ├── common │ │ ├── UriConstants.java │ │ ├── OSDeployUtils.java │ │ └── model │ │ │ └── Version.java │ │ ├── service │ │ ├── MinimalIsoService.java │ │ ├── iso │ │ │ ├── FileExtractor.java │ │ │ ├── FileExtractorImpl.java │ │ │ ├── BootLoaderConfigurator.java │ │ │ └── BootLoaderConfiguratorImpl.java │ │ ├── MiminalIsoServiceImpl.java │ │ ├── OSDeploymentService.java │ │ └── OSDeploymentServiceImpl.java │ │ ├── validators │ │ ├── DeployOsValidator.java │ │ └── BootableIsoValidator.java │ │ ├── controller │ │ ├── IosDeploymentController.java │ │ └── OsDeploymentControllerImpl.java │ │ └── infrastructure │ │ ├── OSDeploymentInfrastructure.java │ │ └── OSDeploymentInfrastructureImpl.java ├── docs │ └── asciidoc │ │ └── index.adoc └── test │ └── java │ └── com │ └── dell │ └── isg │ └── smi │ ├── Swagger2MarkupTest.java │ └── ServiceServerOsDeploymentApplicationTests.java ├── license-template ├── .gitignore ├── application.yml ├── Dockerfile ├── .project ├── gradle.properties ├── README.md └── LICENSE /version: -------------------------------------------------------------------------------- 1 | 1.1.0 2 | -------------------------------------------------------------------------------- /src/main/resources/buildInfo.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /license-template: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/license-template -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle/ 2 | .settings/org.eclipse.jdt.core.prefs 3 | bin/bootstrap.yml 4 | bin/ 5 | build/ 6 | src/docs/asciidoc/generated/ 7 | -------------------------------------------------------------------------------- /src/docs/asciidoc/index.adoc: -------------------------------------------------------------------------------- 1 | include::{generated}/overview.adoc[] 2 | include::{generated}/paths.adoc[] 3 | include::{generated}/definitions.adoc[] -------------------------------------------------------------------------------- /src/main/resources/validation.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/resources/validation.properties -------------------------------------------------------------------------------- /src/test/java/com/dell/isg/smi/Swagger2MarkupTest.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/test/java/com/dell/isg/smi/Swagger2MarkupTest.java -------------------------------------------------------------------------------- /application.yml: -------------------------------------------------------------------------------- 1 | #server: 2 | #port: 46014 3 | 4 | logging: 5 | level.root: INFO 6 | level.com.dell.smi: TRACE 7 | level.org.apache.tomcat: INFO 8 | file: /var/log/dell/osdeploy.log 9 | -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/BuildInfo.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/BuildInfo.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/Application.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/Application.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/model/Version.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/model/Version.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/SimpleCORSFilter.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/SimpleCORSFilter.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/model/MessageKey.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/model/MessageKey.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/common/UriConstants.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/common/UriConstants.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/common/OSDeployUtils.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/common/OSDeployUtils.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/common/model/Version.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/common/model/Version.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/model/NetworkSettings.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/model/NetworkSettings.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/model/ObmRequestBase.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/model/ObmRequestBase.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/model/ServiceResponse.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/model/ServiceResponse.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/model/BootableIsoRequest.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/model/BootableIsoRequest.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/model/CreateIsoResponse.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/model/CreateIsoResponse.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/model/DeploymentISOType.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/model/DeploymentISOType.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/model/ServerStatusEnum.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/model/ServerStatusEnum.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/model/InstallationTypeEnum.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/model/InstallationTypeEnum.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/model/IsoConfigProperties.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/model/IsoConfigProperties.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/service/MinimalIsoService.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/service/MinimalIsoService.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/service/iso/FileExtractor.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/service/iso/FileExtractor.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/service/MiminalIsoServiceImpl.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/service/MiminalIsoServiceImpl.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/service/OSDeploymentService.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/service/OSDeploymentService.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/service/iso/FileExtractorImpl.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/service/iso/FileExtractorImpl.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/validators/DeployOsValidator.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/validators/DeployOsValidator.java -------------------------------------------------------------------------------- /src/test/java/com/dell/isg/smi/ServiceServerOsDeploymentApplicationTests.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/test/java/com/dell/isg/smi/ServiceServerOsDeploymentApplicationTests.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/service/OSDeploymentServiceImpl.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/service/OSDeploymentServiceImpl.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/validators/BootableIsoValidator.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/validators/BootableIsoValidator.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/controller/IosDeploymentController.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/controller/IosDeploymentController.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/service/iso/BootLoaderConfigurator.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/service/iso/BootLoaderConfigurator.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/controller/OsDeploymentControllerImpl.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/controller/OsDeploymentControllerImpl.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/service/iso/BootLoaderConfiguratorImpl.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/service/iso/BootLoaderConfiguratorImpl.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/infrastructure/OSDeploymentInfrastructure.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/infrastructure/OSDeploymentInfrastructure.java -------------------------------------------------------------------------------- /src/main/java/com/dell/isg/smi/osdeployment/infrastructure/OSDeploymentInfrastructureImpl.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RackHD/smi-service-dell-server-os-deployment/master/src/main/java/com/dell/isg/smi/osdeployment/infrastructure/OSDeploymentInfrastructureImpl.java -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jre 2 | VOLUME /tmp 3 | ADD build/libs/service-server-osdeployment*.jar app.jar 4 | RUN apt-get update && apt-get install -y genisoimage 5 | RUN bash -c 'touch /app.jar' 6 | COPY /application.yml /application.yml 7 | EXPOSE 46014 8 | ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] 9 | 10 | -------------------------------------------------------------------------------- /src/main/resources/deployment/isolinux_esxi.cfg: -------------------------------------------------------------------------------- 1 | default menu.c32 2 | menu title VMware VMvisor Boot Menu 3 | timeout 80 4 | 5 | label ESXi Installer 6 | menu label ^ESXi Installer 7 | kernel mboot.c32 8 | append vmkboot.gz --- vmkernel.gz --- sys.vgz --- cim.vgz --- ienviron.vgz --- install.vgz 9 | 10 | label ^Boot from local disk 11 | menu label ^Boot from local disk 12 | localboot 0x80 -------------------------------------------------------------------------------- /src/main/resources/deployment/isolinux_esx.cfg: -------------------------------------------------------------------------------- 1 | default esx 2 | gfxboot bootlogo 3 | prompt 1 4 | #menu title ESX build 260247 5 | timeout 300 6 | 7 | LABEL esx 8 | menu default 9 | menu label Install ESX in graphical mode 10 | kernel vmlinuz 11 | append initrd=initrd.img debugLogToSerial=1 vmkConsole=false mem=512M quiet 12 | 13 | LABEL skip-install 14 | menu label ^Boot from first hard disk 15 | localboot 0x80 16 | -------------------------------------------------------------------------------- /src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 46014 3 | --- 4 | 5 | spring: 6 | profiles: default 7 | application: 8 | name: SERVER-OS-DEPLOYMENT 9 | cloud: 10 | bus: 11 | enabled: false 12 | consul: 13 | enabled: false 14 | config: 15 | enabled: false 16 | --- 17 | 18 | spring: 19 | profiles: consul 20 | application: 21 | name: SERVER-OS-DEPLOYMENT 22 | cloud: 23 | consul: 24 | enabled: false 25 | host: service-registry 26 | port: 8500 27 | config: 28 | prefix: config 29 | profileSeparator: '::' 30 | format: YAML 31 | data-key: data 32 | fail-fast: false -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | smi-service-dell-server-os-deployment 4 | 5 | 6 | 7 | org.eclipse.jdt.core.javanature 8 | org.eclipse.buildship.core.gradleprojectnature 9 | 10 | 11 | 12 | org.eclipse.jdt.core.javabuilder 13 | 14 | 15 | 16 | org.eclipse.buildship.core.gradleprojectbuilder 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | version=1.0 2 | dockerTag=devel 3 | buildInfo.licenseControl.runChecks=true 4 | buildInfo.licenseControl.autoDiscover=true 5 | buildInfo.build.name=com.dell.isg.smi:OSDeploymentServices 6 | systemProp.sonar.host.url=https://sonarqube.com 7 | systemProp.sonar.organization=rackhd-smi 8 | systemProp.sonar.login=##sonarqubeLogin-placeholder## 9 | bintrayRepo=docs 10 | bintrayUserOrg=rackhd 11 | bintrayVcsUrl=https://bintray.com/rackhd/docs/apidoc 12 | bintrayUser=##bintray-user-placeholder## 13 | bintrayApiKey=##bintray-api-key-placeholder## 14 | wsmanlibVersion=1.0.61 15 | wsmanclientVersion=1.0.37 16 | commonsModelVersion=1.0.97 17 | commonsElmVersion=1.0.82 18 | commonsUtilitiesVersion=1.0.32 19 | adapterServerVersion=1.0.81 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # smi-service-dell-server-os-deployment 2 | A Java Spring Boot Microservice that exposes a REST API. Used to perform operating system deployment on Dell servers using the IDRAC's ability to mount and expose an ISO. 3 | 4 | This service is intended to support the deployment of various Operating System types. Currently only ESXI 6.x is supported. 5 | 6 | Copyright © 2017 Dell Inc. or its subsidiaries. All Rights Reserved. 7 | 8 | ### Purpose 9 | The service-os-deployment container is a stateless spring-boot microservice that exposes a REST API's to: 10 | - Read files from a source ISO and create a new, repackaged ISO that specifies the location of a Kickstart file to use 11 | - deploy an ISO image stored on a network share to to a Dell server 12 | - detach virtual media on a Dell server 13 | 14 | --- 15 | 16 | ### How to use 17 | 18 | #### Startup 19 | 20 | 1) On the host system that runs docker, create a directory and mount a remote NFS or CIFS share. Example: 21 | ~~~ 22 | sudo mkdir /mnt/filesFromFs01 23 | sudo mount 100.100.100.100:/opt/dell/public /mnt/filesFromFs01 24 | ~~~ 25 | 26 | 2) Use docker run with the -v option to use the mount above inside of the container. Example: 27 | ~~~ 28 | sudo docker run --name osdeployment -p 0.0.0.0:46014:46014 -v /mnt/filesFromFs01:/public -d rackhd/dell-os-deployment:latest 29 | ~~~ 30 | 31 | #### API Definitions 32 | 33 | A swagger UI is provided by the microservice at: 34 | ~~~ 35 | http://<>:46014/swagger-ui.html 36 | ~~~ 37 | 38 | ##### Example API Endpoints 39 | 40 | ###### Create ISO 41 | Endpoint: POST /api/1.0/server/osdeployment/iso/create 42 | ~~~ 43 | { 44 | "kickStartFileName" :"myCustomKickstart.cfg", 45 | "ksLocation" : "nfs://100.100.100.100/opt/dell/public/", 46 | "sourceDir": "/public", 47 | "fileName": "VMware-VMvisor-Installer-6.0.0.update03-5572656.x86_64-DellEMC_Customized-A04.iso", 48 | "destinationDir": "/public", 49 | "shareAddress": "100.100.100.100", 50 | "destinationFileName": "myCustomIso.iso" 51 | } 52 | 53 | ~~~ 54 | 55 | ###### Deploy ISO 56 | Endpoint: POST /api/1.0/server/osdeployment/deploy 57 | ~~~ 58 | { 59 | "serverAddress": "100.68.124.121", 60 | "userName": "root", 61 | "password": "calvin", 62 | "hypervisorType": "ESXi6", 63 | "hypervisorVersion": "6.5", 64 | "isoFileShare": 65 | { 66 | "address": "100.100.100.100", 67 | "description": "nfs", 68 | "fileName": "myCustomIso.iso", 69 | "path": "/public", 70 | "scriptDirectory": "NA", 71 | "scriptName": "NA", 72 | "type": "NFS", 73 | "name": "Name-NFS 74 | } 75 | } 76 | ~~~ 77 | 78 | 79 | ###### Unmount ISO 80 | Endpoint: POST /api/1.0/server/osdeployment/iso/detach 81 | ~~~ 82 | { 83 | "address": "100.68.124.121", 84 | "userName": "root", 85 | "password": "calvin" 86 | } 87 | ~~~ 88 | 89 | 90 | ### Licensing 91 | Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 92 | 93 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 94 | 95 | Source code for this microservice is available in repositories at https://github.com/RackHD. 96 | 97 | The microservice makes use of dependent Jar libraries that may be covered by other licenses. In order to comply with the requirements of applicable licenses, the source for dependent libraries used by this microservice is available for download at: https://bintray.com/rackhd/binary/download_file?file_path=smi-service-dell-server-os-deployment-dependency-sources-devel.zip 98 | 99 | The following dependent jar libraries are licensed under the LGPL license (https://www.gnu.org/copyleft/lesser.txt): 100 |        loopy-core-1.2.2.jar 101 |        loopy-vfs-1.2.2.jar 102 | 103 | The following dependent jar libraries are licensed under the LGPL 2.1 license (http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html): 104 |        jcifs-1.3.18-kohsuke-1.jar 105 |        logback-classic-1.1.9.jar 106 |        logback-core-1.1.9.jar 107 |        hk2-api-2.5.0-b32.jar 108 |        hk2-locator-2.5.0-b32.jar 109 |        hk2-utils-2.5.0-b32.jar 110 | 111 | The following dependent jar libraries are licensed under the CDDL 1.1 and GPL 2.0 license (https://spdx.org/licenses/CDDL-1.1.html) : 112 |        javax.ws.rs-api-2.0.1.jar 113 |        jersey-apache-client4-1.19.1.jar 114 |        jersey-client-1.19.1.jar 115 |        jersey-client-2.25.1.jar 116 |        jersey-common-2.25.1.jar 117 |        jersey-core-1.19.1.jar 118 |        jersey-entity-filtering-2.25.1.jar 119 |        jersey-guava-2.25.1.jar 120 |        jersey-media-json-jackson-2.25.1.jar 121 | 122 | The following dependent jar library is licensed under the CDDL license (https://opensource.org/licenses/cddl1.php): 123 |        jsr311-api-1.1.1.jar 124 | 125 | The following dependent jar library is licensed under the EPL 1.0 license (http://www.eclipse.org/legal/epl-v10.html): 126 |        aspectjweaver-1.8.9.jar 127 | 128 | This product may be distributed with open source code, licensed to you in accordance with the applicable open source license. If you would like a copy of any such source code, Dell EMC will provide a copy of the source code that is required to be made available in accordance with the applicable open source license. Dell EMC may charge reasonable shipping and handling charges for such distribution. Please direct requests in writing to Dell EMC Legal, 176 South St., Hopkinton, MA 01748, ATTN: Open Source Program Office. 129 | 130 | Additionally the binary and source jars for all dependent libraries are available for download on Maven Central. 131 | 132 | RackHD is a Trademark of Dell EMC 133 | 134 | --- 135 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /src/main/resources/deployment/ksESX-noomsa.cfg: -------------------------------------------------------------------------------- 1 | vmaccepteula 2 | %include /tmp/rootpw.cfg 3 | install nfs --server={0} --dir={1} 4 | reboot 5 | %pre --interpreter=bash 6 | cat >/tmp/daemon.py << EOF1 7 | import sys, os, time, atexit, commands 8 | from signal import SIGTERM 9 | class Daemon: 10 | def __init__(self, pidfile, stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'): 11 | self.stdin = stdin 12 | self.stdout = stdout 13 | self.stderr = stderr 14 | self.pidfile = pidfile 15 | 16 | def daemonize(self): 17 | try: 18 | pid = os.fork() 19 | if pid > 0: 20 | # exit first parent 21 | sys.exit(0) 22 | except OSError, e: 23 | sys.stderr.write("fork #1 failed: %d (%s)\n" % (e.errno, e.strerror)) 24 | sys.exit(1) 25 | 26 | # decouple from parent environment 27 | os.chdir("/") 28 | os.setsid() 29 | os.umask(0) 30 | 31 | # do second fork 32 | try: 33 | pid = os.fork() 34 | if pid > 0: 35 | # exit from second parent 36 | sys.exit(0) 37 | except OSError, e: 38 | sys.stderr.write("fork #2 failed: %d (%s)\n" % (e.errno, e.strerror)) 39 | sys.exit(1) 40 | 41 | # redirect standard file descriptors 42 | sys.stdout.flush() 43 | sys.stderr.flush() 44 | si = file(self.stdin, 'r') 45 | so = file(self.stdout, 'a+') 46 | se = file(self.stderr, 'a+', 0) 47 | os.dup2(si.fileno(), sys.stdin.fileno()) 48 | os.dup2(so.fileno(), sys.stdout.fileno()) 49 | os.dup2(se.fileno(), sys.stderr.fileno()) 50 | 51 | # write pidfile 52 | atexit.register(self.delpid) 53 | pid = str(os.getpid()) 54 | file(self.pidfile,'w+').write("%s\n" % pid) 55 | 56 | def delpid(self): 57 | os.remove(self.pidfile) 58 | 59 | def start(self): 60 | # Check for a pidfile to see if the daemon already runs 61 | try: 62 | pf = file(self.pidfile,'r') 63 | pid = int(pf.read().strip()) 64 | pf.close() 65 | except IOError: 66 | pid = None 67 | 68 | if pid: 69 | message = "pidfile %s already exist. Daemon already running?\n" 70 | sys.stderr.write(message % self.pidfile) 71 | sys.exit(1) 72 | 73 | # Start the daemon 74 | self.daemonize() 75 | self.run() 76 | 77 | def stop(self): 78 | # Get the pid from the pidfile 79 | try: 80 | pf = file(self.pidfile,'r') 81 | pid = int(pf.read().strip()) 82 | pf.close() 83 | except IOError: 84 | pid = None 85 | 86 | if not pid: 87 | message = "pidfile %s does not exist. Daemon not running?\n" 88 | sys.stderr.write(message % self.pidfile) 89 | return # not an error in a restart 90 | 91 | # Try killing the daemon process 92 | try: 93 | MY_OP="" 94 | CTR = 0 95 | while CTR < 10: 96 | CTR += 1 97 | TEMP_CMD="kill -9 " + str(pid) 98 | MY_OP = commands.getoutput(TEMP_CMD) 99 | if (MY_OP.find("No such process")) > 0: 100 | if os.path.exists(self.pidfile): 101 | os.remove(self.pidfile) 102 | time.sleep(2) 103 | except OSError, err: 104 | err = str(err) 105 | if err.find("No such process") > 0: 106 | if os.path.exists(self.pidfile): 107 | os.remove(self.pidfile) 108 | else: 109 | print str(err) 110 | sys.exit(1) 111 | 112 | def restart(self): 113 | self.stop() 114 | self.start() 115 | 116 | def run(self): 117 | message = "Initiating install progress monitor daemon" 118 | EOF1 119 | cat >/tmp/runDaemon.py << EOF2 120 | import sys, time, httplib, string, commands 121 | from xml.dom.minidom import parseString 122 | from daemon import Daemon 123 | class MyDaemon(Daemon): 124 | def run(self): 125 | MY_SVCTAG =commands.getoutput("esxcfg-info -w | grep -i serial | sed 's/[^a-zA-Z0-9]*\./ /g' | awk '{print \$3}'") 126 | ERR_MSG = [] 127 | ERR_MSG_STR = '' 128 | ERR_CODE = '267195' 129 | CTR = 0 130 | errorFound = False 131 | while (CTR < 50 and errorFound == False): 132 | time.sleep(30) 133 | CTR += 1 134 | f=open('/var/log/esx_install.log','r') 135 | if (f): 136 | LINES = f.readlines() 137 | f.close() 138 | for i in range(len(LINES)): 139 | if ((string.find(LINES[i],"ERROR") != -1) and (string.find(LINES[i],"DEBUG") == -1) and (string.find(LINES[i],"metadata.zip") == -1) and (string.find(LINES[i],"No route to host") == -1)): 140 | TEMP_STR = LINES[i].rstrip('\n') 141 | ERR_MSG.append(TEMP_STR) 142 | errorFound = True 143 | if (len(ERR_MSG) > 0 and errorFound == True): 144 | for MSG in ERR_MSG: 145 | ERR_MSG_STR += MSG 146 | if (len(MY_SVCTAG) == 7 and len(ERR_MSG_STR) > 0): 147 | defNS="http://pg.dell.com/spectre/deploymentprogress/ws" 148 | envelope_template = """""" 149 | envelope_template += """""" 150 | envelope_template += """""" 151 | envelope_template += """""" 152 | envelope_template += """""" + MY_SVCTAG + """""" 153 | envelope_template += """""" + ERR_CODE + """""" 154 | envelope_template += """""" + ERR_MSG_STR + """""" 155 | envelope_template += """""" 156 | envelope_template += """""" 157 | envelope_template += """""" 158 | try: 159 | envlen = len(envelope_template) 160 | _post = 'http:///Spectre/DeploymentProgressService' 161 | _host = '' 162 | _port = 443 163 | http_conn = httplib.HTTPSConnection(_host,_port) 164 | http_conn.putrequest('POST', _post) 165 | http_conn.putheader('Host', _host) 166 | http_conn.putheader('Content-Type', 'text/xml; charset="utf-8"') 167 | http_conn.putheader('Content-Length', str(envlen)) 168 | http_conn.putheader('SOAPAction', 'http://pg.dell.com/spectre/deploymentprogress/ws/SetInstallationError') 169 | http_conn.endheaders() 170 | http_conn.send(envelope_template) 171 | httpresponse = http_conn.getresponse() 172 | response = httpresponse.read() 173 | http_conn.close() 174 | idResponseBlob = parseString(response) 175 | idResponseBlob.unlink() 176 | daemon.stop() 177 | except Exception,detail: 178 | TEMP_STR = "logger Exception:" + str(detail) 179 | print TEMP_STR 180 | daemon.stop() 181 | 182 | if __name__ == "__main__": 183 | daemon = MyDaemon('/tmp/daemon-example.pid') 184 | if len(sys.argv) == 2: 185 | if 'start' == sys.argv[1]: 186 | daemon.start() 187 | elif 'stop' == sys.argv[1]: 188 | daemon.stop() 189 | elif 'restart' == sys.argv[1]: 190 | daemon.restart() 191 | else: 192 | print "Unknown command" 193 | sys.exit(0) 194 | else: 195 | print "usage: %s start|stop|restart" % sys.argv[0] 196 | EOF2 197 | cat > /tmp/getIdentity.py <""" 212 | envelope_template += """""" 213 | envelope_template += """""" 214 | envelope_template += """""" 215 | envelope_template += """""" + MY_SVCTAG + """""" 216 | envelope_template += """""" + MY_MAC + """""" 217 | envelope_template += """""" 218 | envelope_template += """""" 219 | envelope_template += """""" 220 | try: 221 | envlen = len(envelope_template) 222 | _post = 'http:///Spectre/DeploymentProgressService' 223 | _host = '' 224 | _port = 443 225 | http_conn = httplib.HTTPSConnection(_host,_port) 226 | http_conn.putrequest('POST', _post) 227 | http_conn.putheader('Host', _host) 228 | http_conn.putheader('Content-Type', 'text/xml; charset="utf-8"') 229 | http_conn.putheader('Content-Length', str(envlen)) 230 | http_conn.putheader('SOAPAction', 'http://pg.dell.com/spectre/deploymentprogress/ws/GetIdentity') 231 | http_conn.endheaders() 232 | http_conn.send(envelope_template) 233 | httpresponse = http_conn.getresponse() 234 | response = httpresponse.read() 235 | http_conn.close() 236 | idResponseBlob = parseString(response) 237 | serverDetailsNodeList = idResponseBlob.getElementsByTagNameNS(defNS,'ServerDetails') 238 | if (serverDetailsNodeList == None or serverDetailsNodeList.length <= 0): 239 | print "ERROR: Unable to get server detail info from Dell Plugin" 240 | else: 241 | for serverDetailsNode in serverDetailsNodeList.item(0).childNodes: 242 | if (serverDetailsNode and serverDetailsNode.hasChildNodes()): 243 | tempNodeVal = serverDetailsNode.childNodes.item(0).nodeValue 244 | if (serverDetailsNode.localName == "password" and tempNodeVal != None): 245 | ksOutput += "rootpw --iscrypted " + tempNodeVal + "\n" 246 | elif (serverDetailsNode.localName == "NetworkDetails"): 247 | networkDetailsChildren = serverDetailsNode.childNodes 248 | if (networkDetailsChildren and networkDetailsChildren.length > 0): 249 | for networkDetailNode in networkDetailsChildren: 250 | tempNodeName = networkDetailNode.localName 251 | if (networkDetailNode.hasChildNodes()): 252 | tempNodeVal = networkDetailNode.childNodes.item(0).nodeValue 253 | if (tempNodeVal != None): 254 | if (tempNodeName == "ipAddress" and tempNodeVal !=None): 255 | ipAddrToken = tempNodeVal 256 | useStaticIP = True 257 | if (tempNodeName == "macAddress" and tempNodeVal != None): 258 | macAddrToken = tempNodeVal 259 | if (tempNodeName == "vLanId" and tempNodeVal != None and tempNodeVal != "-1"): 260 | vlanidToken = tempNodeVal 261 | if (useStaticIP == False): 262 | ksOutput += "network --bootproto=dhcp" 263 | if (macAddrToken and len(macAddrToken) > 0): 264 | ksOutput += " --device=" + macAddrToken 265 | if (vlanidToken and len(vlanidToken) > 0): 266 | ksOutput += " --vlanid=" + vlanidToken 267 | ksOutput += "\n" 268 | else: 269 | ksOutput += "network --bootproto=static" 270 | if (vlanidToken and len(vlanidToken) > 0): 271 | ksOutput += " --vlanid=" + vlanidToken 272 | if (ipAddrToken and len(ipAddrToken) > 0): 273 | ksOutput += " --ip=" + ipAddrToken 274 | if (macAddrToken and len(macAddrToken) > 0): 275 | ksOutput += " --device=" + macAddrToken 276 | for networkDetailNode in networkDetailsChildren: 277 | tempNodeName = networkDetailNode.localName 278 | if (networkDetailNode.hasChildNodes()): 279 | tempNodeVal = networkDetailNode.childNodes.item(0).nodeValue 280 | if (tempNodeVal != None): 281 | if (tempNodeName == "defaultGateway"): 282 | ksOutput += " --gateway=" + tempNodeVal 283 | if (tempNodeName == "subnetMask"): 284 | ksOutput += " --netmask=" + tempNodeVal 285 | if (tempNodeName == "preferredDns"): 286 | dnsServers = tempNodeVal 287 | if (tempNodeName == "alternateDns"): 288 | dnsServers += "," + tempNodeVal 289 | if (tempNodeName == "hostName"): 290 | ksOutput += " --hostname=" + tempNodeVal 291 | if (dnsServers and len(dnsServers) > 0): 292 | ksOutput += " --nameserver=" + dnsServers 293 | ksOutput += "\n" 294 | else: 295 | commands.getoutput("logger Unable to derive network details") 296 | else: 297 | continue 298 | # Run and parse the first available virtual disk 299 | cmdStatus = 256 300 | cmdOutput = None 301 | tmpCmd = "esxcli corestorage device list > /tmp/diskResponse.txt" 302 | (status, cmdoutput) = commands.getstatusoutput(tmpCmd) 303 | if (status != 0): 304 | ksOutput += "clearpart --firstdisk --overwritevmfs" 305 | ksOutput += "\n" 306 | ksOutput += "autopart --firstdisk" 307 | ksOutput += "\n" 308 | else: 309 | devfsStr = ".*Devfs Path:*" 310 | virtualDiskStr = ".*Model: Virtual Disk*" 311 | devfsExp = re.compile(devfsStr, re.IGNORECASE) 312 | virtualDiskExp = re.compile(virtualDiskStr, re.IGNORECASE) 313 | isOpSuccess = 0 314 | matchObj = None 315 | devFsPath = [] 316 | displayLines = [] 317 | opFileHdl = open('/tmp/diskResponse.txt', 'r') 318 | if (opFileHdl): 319 | displayLines = opFileHdl.readlines() 320 | opFileHdl.close() 321 | if (displayLines and len(displayLines) > 0): 322 | for line in displayLines: 323 | matchObj = devfsExp.match(line) 324 | if (matchObj): 325 | devFsPath = None 326 | devFsPath = line.split(':') 327 | continue 328 | matchObj = virtualDiskExp.match(line) 329 | if (matchObj): 330 | if (devFsPath and len(devFsPath) > 1): 331 | isOpSuccess = 1 332 | break; 333 | if(isOpSuccess == 1): 334 | ksOutput += "clearpart --drives=" + devFsPath[1].strip() + " --overwritevmfs" 335 | ksOutput += "\n" 336 | ksOutput += "autopart --drive=" + devFsPath[1].strip() 337 | ksOutput += "\n" 338 | else: 339 | ksOutput += "clearpart --firstdisk --overwritevmfs" 340 | ksOutput += "\n" 341 | ksOutput += "autopart --firstdisk" 342 | ksOutput += "\n" 343 | # Completed parsing all nodes - time to dump output into /tmp/rootpw.cfg 344 | fileHdl = open('/tmp/rootpw.cfg', 'w') 345 | if (fileHdl): 346 | fileHdl.write(ksOutput) 347 | fileHdl.close() 348 | idResponseBlob.unlink() 349 | except Exception,detail: 350 | TEMP_CMD="logger Exception:" + str(detail) 351 | print TEMP_CMD 352 | EOF3 353 | python /tmp/runDaemon.py start 354 | python /tmp/getIdentity.py 355 | %post --interpreter=bash --nochroot 356 | python /tmp/runDaemon.py stop 357 | %post --interpreter=bash 358 | cat > /root/installomsa.py < 0): 366 | currTime = time.strftime("%d %b %y %H:%M:%S",time.gmtime()) 367 | TEMP_STR = currTime + " " + progressData 368 | print TEMP_STR 369 | logFile.write(TEMP_STR) 370 | logFile.close() 371 | 372 | def callbackConsole(): 373 | MY_SVCTAG =commands.getoutput("esxcfg-info -w | grep -i serial | sed 's/[^a-zA-Z0-9]*\./ /g' | awk '{print \$3}'") 374 | MY_IPADDR =commands.getoutput("esxcfg-vswif -l | grep -vi broadcast | awk '{print \$5}'") 375 | print "Initial IP address is ", MY_IPADDR 376 | ctr = 0 377 | while (MY_IPADDR == "0.0.0.0" and ctr < 5): 378 | time.sleep(60) 379 | ctr += 1 380 | MY_IPADDR =commands.getoutput("esxcfg-vswif -l | grep -vi broadcast | awk '{print \$5}'") 381 | defNS="http://pg.dell.com/spectre/deploymentprogress/ws" 382 | envelope_template = """""" 383 | envelope_template += """""" 384 | envelope_template += """""" 385 | envelope_template += """""" 386 | envelope_template += """""" + MY_SVCTAG + """""" 387 | envelope_template += """""" + MY_IPADDR + """""" 388 | envelope_template += """""" 389 | envelope_template += """""" 390 | envelope_template += """""" 391 | try: 392 | envlen = len(envelope_template) 393 | _post = 'http:///Spectre/DeploymentProgressService' 394 | _host = '' 395 | _port = 443 396 | http_conn = httplib.HTTPSConnection(_host,_port) 397 | http_conn.putrequest('POST', _post) 398 | http_conn.putheader('Host', _host) 399 | http_conn.putheader('Content-Type', 'text/xml; charset="utf-8"') 400 | http_conn.putheader('Content-Length', str(envlen)) 401 | http_conn.putheader('SOAPAction', 'http://pg.dell.com/spectre/deploymentprogress/ws/UpdateHostDetails') 402 | http_conn.endheaders() 403 | http_conn.send(envelope_template) 404 | httpresponse = http_conn.getresponse() 405 | response = httpresponse.read() 406 | http_conn.close() 407 | idResponseBlob = parseString(response) 408 | ## Dump the response from spectre into the install log 409 | logInstallProgress(idResponseBlob.toprettyxml()) 410 | updateResponseNode = idResponseBlob.getElementsByTagNameNS(defNS,'UpdateHostDetailsResponse') 411 | if (updateResponseNode == None or updateResponseNode.length <= 0): 412 | logInstallProgress("No update response node in ack from console...potential fault") 413 | idResponseBlob.unlink() 414 | return False 415 | else: 416 | logInstallProgress("Found update response node in ack from console...Exiting") 417 | idResponseBlob.unlink() 418 | return True 419 | except Exception,detail: 420 | TEMP_STR = "Exception:" + str(detail) 421 | logInstallProgress(TEMP_STR) 422 | return False 423 | 424 | def logErrors(errorString): 425 | if (errorString and len(errorString) > 0): 426 | print errorString 427 | reportErrors(errorString) 428 | 429 | (CMD_STATUS, MY_HYP_VER) = commands.getstatusoutput("vmware -v | awk '{print \$2 \$3}'") 430 | try: 431 | if (CMD_STATUS == 0): 432 | # Reset the status of the command 433 | CMD_STATUS = 256 434 | # Now check if we can open the firewall for retreiving the file 435 | (CMD_STATUS, OPEN_FIREWALL) = commands.getstatusoutput("esxcfg-firewall -o 443,tcp,in,out,https") 436 | if (CMD_STATUS == 0): 437 | ctr = 0 438 | ackRecvd = False 439 | while (ctr < 4 and ackRecvd == False): 440 | ctr += 1 441 | ackRecvd = callbackConsole() 442 | time.sleep(30) 443 | # Reset command status and close firewall HTTPS exception 444 | CMD_STATUS = 256 445 | (CMD_STATUS, CLOSE_FIREWALL) = commands.getstatusoutput("esxcfg-firewall -c 443,tcp,in,out,https") 446 | if (CMD_STATUS == 0): 447 | TEMP_STR = "Closed firewall for HTTPs requests successfully\n" 448 | logInstallProgress(TEMP_STR) 449 | else: 450 | TEMP_STR = "Unable to close firewall for HTTPs exception:" + CLOSE_FIREWALL + "\n" 451 | logInstallProgress(TEMP_STR) 452 | else: 453 | logInstallProgress("Unable to open firewall for https...\n") 454 | else: 455 | logInstallProgress("Unable to get hypervisor version...not calling back console\n") 456 | except Exception,detail: 457 | TEMP_STR = "Exception occured : " + str(detail) 458 | logInstallProgress(TEMP_STR) 459 | EOFOMSA 460 | cp /etc/rc.d/rc.local /etc/rc.d/rc.local.bak 461 | cat >> /etc/rc.d/rc.local </tmp/daemon.py << EOF1 7 | import sys, os, time, atexit,commands 8 | from signal import SIGTERM 9 | class Daemon: 10 | def __init__(self, pidfile, stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'): 11 | self.stdin = stdin 12 | self.stdout = stdout 13 | self.stderr = stderr 14 | self.pidfile = pidfile 15 | 16 | def daemonize(self): 17 | try: 18 | pid = os.fork() 19 | if pid > 0: 20 | # exit first parent 21 | sys.exit(0) 22 | except OSError, e: 23 | sys.stderr.write("fork #1 failed: %d (%s)\n" % (e.errno, e.strerror)) 24 | sys.exit(1) 25 | 26 | # decouple from parent environment 27 | os.chdir("/") 28 | os.setsid() 29 | os.umask(0) 30 | 31 | # do second fork 32 | try: 33 | pid = os.fork() 34 | if pid > 0: 35 | # exit from second parent 36 | sys.exit(0) 37 | except OSError, e: 38 | sys.stderr.write("fork #2 failed: %d (%s)\n" % (e.errno, e.strerror)) 39 | sys.exit(1) 40 | 41 | # redirect standard file descriptors 42 | sys.stdout.flush() 43 | sys.stderr.flush() 44 | si = file(self.stdin, 'r') 45 | so = file(self.stdout, 'a+') 46 | se = file(self.stderr, 'a+', 0) 47 | os.dup2(si.fileno(), sys.stdin.fileno()) 48 | os.dup2(so.fileno(), sys.stdout.fileno()) 49 | os.dup2(se.fileno(), sys.stderr.fileno()) 50 | 51 | # write pidfile 52 | atexit.register(self.delpid) 53 | pid = str(os.getpid()) 54 | file(self.pidfile,'w+').write("%s\n" % pid) 55 | 56 | def delpid(self): 57 | os.remove(self.pidfile) 58 | 59 | def start(self): 60 | # Check for a pidfile to see if the daemon already runs 61 | try: 62 | pf = file(self.pidfile,'r') 63 | pid = int(pf.read().strip()) 64 | pf.close() 65 | except IOError: 66 | pid = None 67 | 68 | if pid: 69 | message = "pidfile %s already exist. Daemon already running?\n" 70 | sys.stderr.write(message % self.pidfile) 71 | sys.exit(1) 72 | 73 | # Start the daemon 74 | self.daemonize() 75 | self.run() 76 | 77 | def stop(self): 78 | # Get the pid from the pidfile 79 | try: 80 | pf = file(self.pidfile,'r') 81 | pid = int(pf.read().strip()) 82 | pf.close() 83 | except IOError: 84 | pid = None 85 | 86 | if not pid: 87 | message = "pidfile %s does not exist. Daemon not running?\n" 88 | sys.stderr.write(message % self.pidfile) 89 | return # not an error in a restart 90 | 91 | # Try killing the daemon process 92 | try: 93 | MY_OP="" 94 | CTR = 0 95 | while CTR < 10: 96 | CTR += 1 97 | TEMP_CMD="kill -9 " + str(pid) 98 | MY_OP = commands.getoutput(TEMP_CMD) 99 | if (MY_OP.find("No such process")) > 0: 100 | if os.path.exists(self.pidfile): 101 | os.remove(self.pidfile) 102 | time.sleep(2) 103 | except OSError, err: 104 | err = str(err) 105 | if err.find("No such process") > 0: 106 | if os.path.exists(self.pidfile): 107 | os.remove(self.pidfile) 108 | else: 109 | print str(err) 110 | sys.exit(1) 111 | 112 | def restart(self): 113 | self.stop() 114 | self.start() 115 | 116 | def run(self): 117 | message = "hello there..." 118 | EOF1 119 | cat >/tmp/runDaemon.py << EOF2 120 | import sys, time, httplib, string, commands 121 | from xml.dom.minidom import parseString 122 | from daemon import Daemon 123 | class MyDaemon(Daemon): 124 | def run(self): 125 | MY_SVCTAG =commands.getoutput("esxcfg-info -w | grep -i serial | sed 's/[^a-zA-Z0-9]*\./ /g' | awk '{print \$3}'") 126 | ERR_MSG = [] 127 | ERR_MSG_STR = '' 128 | ERR_CODE = '267195' 129 | CTR = 0 130 | errorFound = False 131 | while (CTR < 40 and errorFound == False): 132 | time.sleep(30) 133 | CTR += 1 134 | f=open('/var/log/esxi_install.log','r') 135 | if (f): 136 | LINES = f.readlines() 137 | f.close() 138 | for i in range(len(LINES)): 139 | if ((string.find(LINES[i],"ERROR") != -1) and (string.find(LINES[i],"DEBUG") == -1)): 140 | TEMP_STR = LINES[i].rstrip('\n') 141 | ERR_MSG.append(TEMP_STR) 142 | errorFound = True 143 | if (len(ERR_MSG) > 0): 144 | for MSG in ERR_MSG: 145 | ERR_MSG_STR += MSG 146 | 147 | if (len(MY_SVCTAG) == 7 and len(ERR_MSG_STR) > 0): 148 | defNS="http://pg.dell.com/spectre/deploymentprogress/ws" 149 | envelope_template = """""" 150 | envelope_template += """""" 151 | envelope_template += """""" 152 | envelope_template += """""" 153 | envelope_template += """""" + MY_SVCTAG + """""" 154 | envelope_template += """""" + ERR_CODE + """""" 155 | envelope_template += """""" + ERR_MSG_STR + """""" 156 | envelope_template += """""" 157 | envelope_template += """""" 158 | envelope_template += """""" 159 | try: 160 | envlen = len(envelope_template) 161 | _post = 'http:///Spectre/DeploymentProgressService' 162 | _host = '' 163 | _port = 443 164 | http_conn = httplib.HTTPSConnection(_host,_port) 165 | http_conn.putrequest('POST', _post) 166 | http_conn.putheader('Host', _host) 167 | http_conn.putheader('Content-Type', 'text/xml; charset="utf-8"') 168 | http_conn.putheader('Content-Length', str(envlen)) 169 | http_conn.putheader('SOAPAction', 'http://pg.dell.com/spectre/deploymentprogress/ws/SetInstallationError') 170 | http_conn.endheaders() 171 | http_conn.send(envelope_template) 172 | httpresponse = http_conn.getresponse() 173 | response = httpresponse.read() 174 | http_conn.close() 175 | idResponseBlob = parseString(response) 176 | idResponseBlob.unlink() 177 | daemon.stop() 178 | except Exception,detail: 179 | TEMP_STR="logger Exception:" + str(detail) 180 | print TEMP_STR 181 | daemon.stop() 182 | 183 | if __name__ == "__main__": 184 | daemon = MyDaemon('/tmp/daemon-example.pid') 185 | if len(sys.argv) == 2: 186 | if 'start' == sys.argv[1]: 187 | daemon.start() 188 | elif 'stop' == sys.argv[1]: 189 | daemon.stop() 190 | elif 'restart' == sys.argv[1]: 191 | daemon.restart() 192 | else: 193 | print "Unknown command" 194 | #sys.exit(2) 195 | sys.exit(0) 196 | else: 197 | print "usage: %s start|stop|restart" % sys.argv[0] 198 | EOF2 199 | cat > /tmp/getIdentity.py <""" 214 | envelope_template += """""" 215 | envelope_template += """""" 216 | envelope_template += """""" 217 | envelope_template += """""" + MY_SVCTAG + """""" 218 | envelope_template += """""" + MY_MAC + """""" 219 | envelope_template += """""" 220 | envelope_template += """""" 221 | envelope_template += """""" 222 | try: 223 | envlen = len(envelope_template) 224 | _post = 'http:///Spectre/DeploymentProgressService' 225 | _host = '' 226 | _port = 443 227 | http_conn = httplib.HTTPSConnection(_host,_port) 228 | http_conn.putrequest('POST', _post) 229 | http_conn.putheader('Host', _host) 230 | http_conn.putheader('Content-Type', 'text/xml; charset="utf-8"') 231 | http_conn.putheader('Content-Length', str(envlen)) 232 | http_conn.putheader('SOAPAction', 'http://pg.dell.com/spectre/deploymentprogress/ws/GetIdentity') 233 | http_conn.endheaders() 234 | http_conn.send(envelope_template) 235 | httpresponse = http_conn.getresponse() 236 | response = httpresponse.read() 237 | http_conn.close() 238 | idResponseBlob = parseString(response) 239 | serverDetailsNodeList = idResponseBlob.getElementsByTagNameNS(defNS,'ServerDetails') 240 | if (serverDetailsNodeList == None or serverDetailsNodeList.length <= 0): 241 | print "ERROR: Unable to get server detail info from Dell Plugin" 242 | else: 243 | for serverDetailsNode in serverDetailsNodeList.item(0).childNodes: 244 | if (serverDetailsNode and serverDetailsNode.hasChildNodes()): 245 | tempNodeVal = serverDetailsNode.childNodes.item(0).nodeValue 246 | if (serverDetailsNode.localName == "password" and tempNodeVal != None): 247 | ksOutput += "rootpw --iscrypted " + tempNodeVal + "\n" 248 | elif (serverDetailsNode.localName == "NetworkDetails"): 249 | networkDetailsChildren = serverDetailsNode.childNodes 250 | if (networkDetailsChildren and networkDetailsChildren.length > 0): 251 | for networkDetailNode in networkDetailsChildren: 252 | tempNodeName = networkDetailNode.localName 253 | if (networkDetailNode.hasChildNodes()): 254 | tempNodeVal = networkDetailNode.childNodes.item(0).nodeValue 255 | if (tempNodeVal != None): 256 | if (tempNodeName == "ipAddress" and tempNodeVal !=None): 257 | ipAddrToken = tempNodeVal 258 | useStaticIP = True 259 | if (tempNodeName == "macAddress" and tempNodeVal != None): 260 | macAddrToken = tempNodeVal 261 | if (tempNodeName == "vLanId" and tempNodeVal != None and tempNodeVal != "-1"): 262 | vlanidToken = tempNodeVal 263 | if (useStaticIP == False): 264 | ksOutput += "network --bootproto=dhcp" 265 | if (macAddrToken and len(macAddrToken) > 0): 266 | ksOutput += " --device=" + macAddrToken 267 | if (vlanidToken and len(vlanidToken) > 0): 268 | ksOutput += " --vlanid=" + vlanidToken 269 | ksOutput += "\n" 270 | else: 271 | ksOutput += "network --bootproto=static" 272 | if (vlanidToken and len(vlanidToken) > 0): 273 | ksOutput += " --vlanid=" + vlanidToken 274 | if (ipAddrToken and len(ipAddrToken) > 0): 275 | ksOutput += " --ip=" + ipAddrToken 276 | if (macAddrToken and len(macAddrToken) > 0): 277 | ksOutput += " --device=" + macAddrToken 278 | for networkDetailNode in networkDetailsChildren: 279 | tempNodeName = networkDetailNode.localName 280 | if (networkDetailNode.hasChildNodes()): 281 | tempNodeVal = networkDetailNode.childNodes.item(0).nodeValue 282 | if (tempNodeVal != None): 283 | if (tempNodeName == "defaultGateway"): 284 | ksOutput += " --gateway=" + tempNodeVal 285 | if (tempNodeName == "subnetMask"): 286 | ksOutput += " --netmask=" + tempNodeVal 287 | if (tempNodeName == "preferredDns"): 288 | dnsServers = tempNodeVal 289 | if (tempNodeName == "alternateDns"): 290 | dnsServers += "," + tempNodeVal 291 | if (tempNodeName == "hostName"): 292 | ksOutput += " --hostname=" + tempNodeVal 293 | if (dnsServers and len(dnsServers) > 0): 294 | ksOutput += " --nameserver=" + dnsServers 295 | ksOutput += "\n" 296 | else: 297 | commands.getoutput("logger Unable to derive network details") 298 | else: 299 | continue 300 | # Run and parse the first available virtual disk 301 | cmdStatus = 256 302 | cmdOutput = None 303 | tmpCmd = "esxcfg-scsidevs -l > /tmp/diskResponse.txt" 304 | (status, cmdoutput) = commands.getstatusoutput(tmpCmd) 305 | if (status != 0): 306 | ksOutput += "clearpart --firstdisk --overwritevmfs" 307 | ksOutput += "\n" 308 | ksOutput += "autopart --firstdisk --overwritevmfs" 309 | ksOutput += "\n" 310 | else: 311 | devfsStr = ".*Devfs Path:*" 312 | virtualDiskStr = ".*Model: Virtual Disk*" 313 | devfsExp = re.compile(devfsStr, re.IGNORECASE) 314 | virtualDiskExp = re.compile(virtualDiskStr, re.IGNORECASE) 315 | isOpSuccess = 0 316 | matchObj = None 317 | devFsPath = [] 318 | displayLines = [] 319 | opFileHdl = open('/tmp/diskResponse.txt', 'r') 320 | if (opFileHdl): 321 | displayLines = opFileHdl.readlines() 322 | opFileHdl.close() 323 | if (displayLines and len(displayLines) > 0): 324 | for line in displayLines: 325 | matchObj = devfsExp.match(line) 326 | if (matchObj): 327 | devFsPath = None 328 | devFsPath = line.split(':') 329 | continue 330 | matchObj = virtualDiskExp.match(line) 331 | if (matchObj): 332 | if (devFsPath and len(devFsPath) > 1): 333 | isOpSuccess = 1 334 | break; 335 | if(isOpSuccess == 1): 336 | ksOutput += "clearpart --drives=" + devFsPath[1].strip() + " --overwritevmfs" 337 | ksOutput += "\n" 338 | ksOutput += "autopart --drive=" + devFsPath[1].strip() + " --overwritevmfs" 339 | ksOutput += "\n" 340 | else: 341 | ksOutput += "clearpart --firstdisk --overwritevmfs" 342 | ksOutput += "\n" 343 | ksOutput += "autopart --firstdisk --overwritevmfs" 344 | ksOutput += "\n" 345 | # Completed parsing all nodes - time to dump output into /tmp/rootpw.cfg 346 | fileHdl = open('/tmp/rootpw.cfg', 'w') 347 | if (fileHdl): 348 | fileHdl.write(ksOutput) 349 | fileHdl.close() 350 | idResponseBlob.unlink() 351 | except Exception,detail: 352 | TEMP_CMD="logger Exception:" + str(detail) 353 | print TEMP_CMD 354 | EOF3 355 | python /tmp/runDaemon.py start 356 | python /tmp/getIdentity.py 357 | %post --unsupported --interpreter=busybox 358 | python /tmp/runDaemon.py stop 359 | %firstboot --unsupported --interpreter=python --level=999 360 | import commands,os,httplib,time,string 361 | from xml.dom.minidom import parseString 362 | CMD_STATUS = 256 363 | MY_IPADDR =commands.getoutput("esxcfg-vmknic -l | grep -vi Interface | awk '{print $5}'") 364 | ctr = 0 365 | time.sleep(60) 366 | while (MY_IPADDR == "0.0.0.0" and ctr < 5): 367 | time.sleep(20) 368 | ctr += 1 369 | MY_IPADDR =commands.getoutput("esxcfg-vmknic -l | grep -vi Interface | awk '{print $5}'") 370 | 371 | def logInstallProgress(progressData): 372 | try: 373 | logFile = open('/store/dell_postinstall.log','a') 374 | if (logFile and progressData and len(progressData) > 0): 375 | currTime = time.strftime("%d %b %y %H:%M:%S",time.gmtime()) 376 | TEMP_STR = currTime + " " + progressData + "\n" 377 | print TEMP_STR 378 | logFile.write(TEMP_STR) 379 | logFile.close() 380 | except Exception,detail: 381 | TEMP_CMD="logger Exception:" + str(detail) 382 | print TEMP_CMD 383 | 384 | def configureDNSOnESXi(): 385 | MY_VIRT_NIC = "" 386 | MY_DHCP_STR = "" 387 | STATUS = 0 388 | try: 389 | logInstallProgress("Configuring DNS on ESXi........") 390 | (STATUS, OUTPUTSTR) = commands.getstatusoutput("esxcfg-vmknic -l | grep -vi Interface") 391 | if (STATUS == 0): 392 | VMKNICARR = OUTPUTSTR.split() 393 | MY_VIRT_NIC = VMKNICARR[0] 394 | MY_DHCP_STR = VMKNICARR[11] 395 | logInstallProgress("Virtual NIC device name is " + MY_VIRT_NIC) 396 | logInstallProgress("DHCP status on system is "+MY_DHCP_STR) 397 | if (MY_DHCP_STR == "DHCP"): 398 | logInstallProgress("System is set with DHCP ..configuring DNS") 399 | TEMP_STR = "vim-cmd hostsvc/net/dns_set --dhcp=true --dhcp-virtualnic=" + MY_VIRT_NIC 400 | (STATUS,OUTPUTSTR) = commands.getstatusoutput(TEMP_STR) 401 | if (STATUS == 0): 402 | logInstallProgress("Successfully set dns entries") 403 | commands.getoutput("vim-cmd hostsvc/net/refresh") 404 | else: 405 | logInstallProgress("Unable to set DNS entries") 406 | else: 407 | logInstallProgress("System configured for static IP..Extracting resolv.conf settings") 408 | fileHdl = open('/etc/resolv.conf','r') 409 | if (fileHdl): 410 | resolvFileLines = fileHdl.readlines() 411 | fileHdl.close() 412 | opFileHdl = open('/store/resolv.conf','w') 413 | if (opFileHdl): 414 | resolveFileContents = ''.join(resolvFileLines) 415 | opFileHdl.write(resolveFileContents) 416 | opFileHdl.close() 417 | logInstallProgress("Dumped DNS settings to /store/resolv.conf") 418 | else: 419 | logInstallProgress("Unable to open /store/resolv.conf for writing") 420 | else: 421 | logInstallProgress("Unable to open /etc/resolv.conf for reading") 422 | else: 423 | logInstallProgress("Unable to get esxcfg-vmknic output..exiting") 424 | except Exception,detail: 425 | TEMP_CMD="logger Exception:" + str(detail) 426 | print TEMP_CMD 427 | 428 | def callbackConsole(): 429 | MY_SVCTAG =commands.getoutput("esxcfg-info -w | grep -i serial | sed 's/[^a-zA-Z0-9]*\./ /g' | awk '{print $3}'") 430 | MY_IPADDR =commands.getoutput("esxcfg-vmknic -l | grep -vi Interface | awk '{print $5}'") 431 | logInstallProgress("Firstboot:Initial IP address is " + MY_IPADDR) 432 | ctr = 0 433 | while (MY_IPADDR == "0.0.0.0" and ctr < 5): 434 | time.sleep(60) 435 | ctr += 1 436 | MY_IPADDR =commands.getoutput("esxcfg-vmknic -l | grep -vi Interface | awk '{print $5}'") 437 | logInstallProgress("Resolved IP address is " + MY_IPADDR) 438 | 439 | defNS="http://pg.dell.com/spectre/deploymentprogress/ws" 440 | envelope_template = """""" 441 | envelope_template += """""" 442 | envelope_template += """""" 443 | envelope_template += """""" 444 | envelope_template += """""" + MY_SVCTAG + """""" 445 | envelope_template += """""" + MY_IPADDR + """""" 446 | envelope_template += """""" 447 | envelope_template += """""" 448 | envelope_template += """""" 449 | try: 450 | envlen = len(envelope_template) 451 | _post = 'http:///Spectre/DeploymentProgressService' 452 | _host = '' 453 | _port = 443 454 | logInstallProgress("Initiated connection for updatehost") 455 | http_conn = httplib.HTTPSConnection(_host,_port) 456 | http_conn.putrequest('POST', _post) 457 | http_conn.putheader('Host', _host) 458 | http_conn.putheader('Content-Type', 'text/xml; charset="utf-8"') 459 | http_conn.putheader('Content-Length', str(envlen)) 460 | http_conn.putheader('SOAPAction', 'http://pg.dell.com/spectre/deploymentprogress/ws/UpdateHostDetails') 461 | http_conn.endheaders() 462 | http_conn.send(envelope_template) 463 | httpresponse = http_conn.getresponse() 464 | response = httpresponse.read() 465 | http_conn.close() 466 | idResponseBlob = parseString(response) 467 | logInstallProgress(idResponseBlob.toprettyxml()) 468 | updateResponseNode = idResponseBlob.getElementsByTagNameNS(defNS,'UpdateHostDetailsResponse') 469 | if (updateResponseNode == None or updateResponseNode.length <= 0): 470 | logInstallProgress("No update response node in ack from console...potential fault") 471 | idResponseBlob.unlink() 472 | return False 473 | else: 474 | logInstallProgress("Found update response node in ack from console...Exiting") 475 | idResponseBlob.unlink() 476 | return True 477 | except Exception,detail: 478 | TEMP_STR="logger Exception:" + str(detail) 479 | logInstallProgress(TEMP_STR) 480 | return False 481 | 482 | configureDNSOnESXi() 483 | ackRecvd = False 484 | while (ctr < 4 and ackRecvd == False): 485 | ctr += 1 486 | ackRecvd = callbackConsole() 487 | time.sleep(30) 488 | -------------------------------------------------------------------------------- /src/main/resources/deployment/ksESXI5-noomsa.cfg: -------------------------------------------------------------------------------- 1 | vmaccepteula 2 | %include /tmp/rootpw.cfg 3 | reboot 4 | %pre --interpreter=busybox 5 | cat >/tmp/daemon.py << EOF1 6 | import sys, os, time, atexit,commands 7 | from signal import SIGTERM 8 | class Daemon: 9 | def __init__(self, pidfile, stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'): 10 | self.stdin = stdin 11 | self.stdout = stdout 12 | self.stderr = stderr 13 | self.pidfile = pidfile 14 | 15 | def daemonize(self): 16 | try: 17 | pid = os.fork() 18 | if pid > 0: 19 | # exit first parent 20 | sys.exit(0) 21 | except OSError, e: 22 | sys.stderr.write("fork #1 failed: %d (%s)\n" % (e.errno, e.strerror)) 23 | sys.exit(1) 24 | 25 | # decouple from parent environment 26 | os.chdir("/") 27 | os.setsid() 28 | os.umask(0) 29 | 30 | # do second fork 31 | try: 32 | pid = os.fork() 33 | if pid > 0: 34 | # exit from second parent 35 | sys.exit(0) 36 | except OSError, e: 37 | sys.stderr.write("fork #2 failed: %d (%s)\n" % (e.errno, e.strerror)) 38 | sys.exit(1) 39 | 40 | # redirect standard file descriptors 41 | sys.stdout.flush() 42 | sys.stderr.flush() 43 | si = file(self.stdin, 'r') 44 | so = file(self.stdout, 'a+') 45 | se = file(self.stderr, 'a+', 0) 46 | os.dup2(si.fileno(), sys.stdin.fileno()) 47 | os.dup2(so.fileno(), sys.stdout.fileno()) 48 | os.dup2(se.fileno(), sys.stderr.fileno()) 49 | 50 | # write pidfile 51 | atexit.register(self.delpid) 52 | pid = str(os.getpid()) 53 | file(self.pidfile,'w+').write("%s\n" % pid) 54 | 55 | def delpid(self): 56 | os.remove(self.pidfile) 57 | 58 | def start(self): 59 | # Check for a pidfile to see if the daemon already runs 60 | try: 61 | pf = file(self.pidfile,'r') 62 | pid = int(pf.read().strip()) 63 | pf.close() 64 | except IOError: 65 | pid = None 66 | 67 | if pid: 68 | message = "pidfile %s already exist. Daemon already running?\n" 69 | sys.stderr.write(message % self.pidfile) 70 | sys.exit(1) 71 | 72 | # Start the daemon 73 | self.daemonize() 74 | self.run() 75 | 76 | def stop(self): 77 | # Get the pid from the pidfile 78 | try: 79 | pf = file(self.pidfile,'r') 80 | pid = int(pf.read().strip()) 81 | pf.close() 82 | except IOError: 83 | pid = None 84 | 85 | if not pid: 86 | message = "pidfile %s does not exist. Daemon not running?\n" 87 | sys.stderr.write(message % self.pidfile) 88 | return # not an error in a restart 89 | 90 | # Try killing the daemon process 91 | try: 92 | MY_OP="" 93 | CTR = 0 94 | while CTR < 10: 95 | CTR += 1 96 | TEMP_CMD="kill -9 " + str(pid) 97 | MY_OP = commands.getoutput(TEMP_CMD) 98 | if (MY_OP.find("No such process")) > 0: 99 | if os.path.exists(self.pidfile): 100 | os.remove(self.pidfile) 101 | time.sleep(2) 102 | except OSError, err: 103 | err = str(err) 104 | if err.find("No such process") > 0: 105 | if os.path.exists(self.pidfile): 106 | os.remove(self.pidfile) 107 | else: 108 | print str(err) 109 | sys.exit(1) 110 | 111 | def restart(self): 112 | self.stop() 113 | self.start() 114 | 115 | def run(self): 116 | message = "hello there..." 117 | EOF1 118 | cat >/tmp/runDaemon.py << EOF2 119 | import sys, time, httplib, string, commands 120 | from xml.dom.minidom import parseString 121 | from daemon import Daemon 122 | class MyDaemon(Daemon): 123 | def run(self): 124 | MY_SVCTAG =commands.getoutput("esxcfg-info -w | grep -i 'serial number' | sed 's/[^a-zA-Z0-9]*\./ /g' | awk '{printf \$3}'") 125 | ERR_MSG = [] 126 | ERR_MSG_STR = '' 127 | ERR_CODE = '267195' 128 | CTR = 0 129 | errorFound = False 130 | while (CTR < 40 and errorFound == False): 131 | time.sleep(30) 132 | CTR += 1 133 | f=open('/var/log/esxi_install.log','r') 134 | if (f): 135 | LINES = f.readlines() 136 | f.close() 137 | for i in range(len(LINES)): 138 | if ((string.find(LINES[i],"ERROR") != -1) and (string.find(LINES[i],"DEBUG") == -1)): 139 | TEMP_STR = LINES[i].rstrip('\n') 140 | ERR_MSG.append(TEMP_STR) 141 | errorFound = True 142 | if (len(ERR_MSG) > 0): 143 | for MSG in ERR_MSG: 144 | ERR_MSG_STR += MSG 145 | 146 | if (len(MY_SVCTAG) == 7 and len(ERR_MSG_STR) > 0): 147 | defNS="http://pg.dell.com/spectre/deploymentprogress/ws" 148 | envelope_template = """""" 149 | envelope_template += """""" 150 | envelope_template += """""" 151 | envelope_template += """""" 152 | envelope_template += """""" + MY_SVCTAG + """""" 153 | envelope_template += """""" + ERR_CODE + """""" 154 | envelope_template += """""" + ERR_MSG_STR + """""" 155 | envelope_template += """""" 156 | envelope_template += """""" 157 | envelope_template += """""" 158 | try: 159 | envlen = len(envelope_template) 160 | _post = 'http:///Spectre/DeploymentProgressService' 161 | _host = '' 162 | _port = 443 163 | http_conn = httplib.HTTPSConnection(_host,_port) 164 | http_conn.putrequest('POST', _post) 165 | http_conn.putheader('Host', _host) 166 | http_conn.putheader('Content-Type', 'text/xml; charset="utf-8"') 167 | http_conn.putheader('Content-Length', str(envlen)) 168 | http_conn.putheader('SOAPAction', 'http://pg.dell.com/spectre/deploymentprogress/ws/SetInstallationError') 169 | http_conn.endheaders() 170 | http_conn.send(envelope_template) 171 | httpresponse = http_conn.getresponse() 172 | response = httpresponse.read() 173 | http_conn.close() 174 | idResponseBlob = parseString(response) 175 | idResponseBlob.unlink() 176 | daemon.stop() 177 | except Exception,detail: 178 | TEMP_STR="logger Exception:" + str(detail) 179 | print TEMP_STR 180 | daemon.stop() 181 | 182 | if __name__ == "__main__": 183 | daemon = MyDaemon('/tmp/daemon-example.pid') 184 | if len(sys.argv) == 2: 185 | if 'start' == sys.argv[1]: 186 | daemon.start() 187 | elif 'stop' == sys.argv[1]: 188 | daemon.stop() 189 | elif 'restart' == sys.argv[1]: 190 | daemon.restart() 191 | else: 192 | print "Unknown command" 193 | #sys.exit(2) 194 | sys.exit(0) 195 | else: 196 | print "usage: %s start|stop|restart" % sys.argv[0] 197 | EOF2 198 | cat > /tmp/getIdentity.py <""" 239 | envelope_template += """""" 240 | envelope_template += """""" 241 | envelope_template += """""" 242 | envelope_template += """""" + MY_SVCTAG + """""" 243 | envelope_template += """""" + MY_MAC + """""" 244 | envelope_template += """""" 245 | envelope_template += """""" 246 | envelope_template += """""" 247 | try: 248 | envlen = len(envelope_template) 249 | _post = 'http:///Spectre/DeploymentProgressService' 250 | _host = '' 251 | _port = 443 252 | http_conn = httplib.HTTPSConnection(_host,_port) 253 | http_conn.putrequest('POST', _post) 254 | http_conn.putheader('Host', _host) 255 | http_conn.putheader('Content-Type', 'text/xml; charset="utf-8"') 256 | http_conn.putheader('Content-Length', str(envlen)) 257 | http_conn.putheader('SOAPAction', 'http://pg.dell.com/spectre/deploymentprogress/ws/GetIdentity') 258 | http_conn.endheaders() 259 | http_conn.send(envelope_template) 260 | httpresponse = http_conn.getresponse() 261 | response = httpresponse.read() 262 | http_conn.close() 263 | idResponseBlob = parseString(response) 264 | serverDetailsNodeList = idResponseBlob.getElementsByTagNameNS(defNS,'ServerDetails') 265 | if (serverDetailsNodeList == None or serverDetailsNodeList.length <= 0): 266 | print "ERROR: Unable to get server detail info from Dell Plugin" 267 | else: 268 | for serverDetailsNode in serverDetailsNodeList.item(0).childNodes: 269 | if (serverDetailsNode and serverDetailsNode.hasChildNodes()): 270 | tempNodeVal = serverDetailsNode.childNodes.item(0).nodeValue 271 | if (serverDetailsNode.localName == "password" and tempNodeVal != None): 272 | ksOutput += "rootpw --iscrypted " + tempNodeVal + "\n" 273 | elif (serverDetailsNode.localName == "NetworkDetails"): 274 | networkDetailsChildren = serverDetailsNode.childNodes 275 | if (networkDetailsChildren and networkDetailsChildren.length > 0): 276 | for networkDetailNode in networkDetailsChildren: 277 | tempNodeName = networkDetailNode.localName 278 | if (networkDetailNode.hasChildNodes()): 279 | tempNodeVal = networkDetailNode.childNodes.item(0).nodeValue 280 | if (tempNodeVal != None): 281 | if (tempNodeName == "ipAddress" and tempNodeVal !=None): 282 | ipAddrToken = tempNodeVal 283 | useStaticIP = True 284 | if (tempNodeName == "macAddress" and tempNodeVal != None): 285 | macAddrToken = tempNodeVal 286 | if (tempNodeName == "vLanId" and tempNodeVal != None and tempNodeVal != "-1"): 287 | vlanidToken = tempNodeVal 288 | if (useStaticIP == False): 289 | ksOutput += "network --bootproto=dhcp" 290 | if (macAddrToken and len(macAddrToken) > 0): 291 | ksOutput += " --device=" + macAddrToken 292 | if (vlanidToken and len(vlanidToken) > 0): 293 | ksOutput += " --vlanid=" + vlanidToken 294 | ksOutput += "\n" 295 | else: 296 | ksOutput += "network --bootproto=static" 297 | if (vlanidToken and len(vlanidToken) > 0): 298 | ksOutput += " --vlanid=" + vlanidToken 299 | if (ipAddrToken and len(ipAddrToken) > 0): 300 | ksOutput += " --ip=" + ipAddrToken 301 | if (macAddrToken and len(macAddrToken) > 0): 302 | ksOutput += " --device=" + macAddrToken 303 | for networkDetailNode in networkDetailsChildren: 304 | tempNodeName = networkDetailNode.localName 305 | if (networkDetailNode.hasChildNodes()): 306 | tempNodeVal = networkDetailNode.childNodes.item(0).nodeValue 307 | if (tempNodeVal != None): 308 | if (tempNodeName == "defaultGateway"): 309 | ksOutput += " --gateway=" + tempNodeVal 310 | if (tempNodeName == "subnetMask"): 311 | ksOutput += " --netmask=" + tempNodeVal 312 | if (tempNodeName == "preferredDns"): 313 | dnsServers = tempNodeVal 314 | if (tempNodeName == "alternateDns"): 315 | dnsServers += "," + tempNodeVal 316 | if (tempNodeName == "hostName"): 317 | ksOutput += " --hostname=" + tempNodeVal 318 | if (dnsServers and len(dnsServers) > 0): 319 | ksOutput += " --nameserver=" + dnsServers 320 | ksOutput += "\n" 321 | else: 322 | commands.getoutput("logger Unable to derive network details") 323 | else: 324 | continue 325 | #Clean up response from soap request and return output to write 326 | #into the kickstart include 327 | idResponseBlob.unlink() 328 | except Exception,detail: 329 | TEMP_CMD="logger Exception:" + str(detail) 330 | print TEMP_CMD 331 | 332 | return ksOutput 333 | 334 | def getVirtualDiskInfo(): 335 | ksOutput = "" 336 | try: 337 | # Run and parse the first available virtual disk 338 | cmdStatus = 256 339 | cmdOutput = None 340 | tmpCmd = "esxcfg-scsidevs -l > /tmp/diskResponse.txt" 341 | (status, cmdoutput) = commands.getstatusoutput(tmpCmd) 342 | if (status != 0): 343 | ksOutput += "clearpart --firstdisk --overwritevmfs" 344 | ksOutput += "\n" 345 | ksOutput += "install --firstdisk --overwritevmfs" 346 | ksOutput += "\n" 347 | else: 348 | devfsStr = ".*Devfs Path:*" 349 | virtualDiskStr = ".*Model: Virtual Disk*" 350 | devfsExp = re.compile(devfsStr, re.IGNORECASE) 351 | virtualDiskExp = re.compile(virtualDiskStr, re.IGNORECASE) 352 | isOpSuccess = 0 353 | matchObj = None 354 | devFsPath = [] 355 | displayLines = [] 356 | opFileHdl = open('/tmp/diskResponse.txt', 'r') 357 | if (opFileHdl): 358 | displayLines = opFileHdl.readlines() 359 | opFileHdl.close() 360 | if (displayLines and len(displayLines) > 0): 361 | for line in displayLines: 362 | matchObj = devfsExp.match(line) 363 | if (matchObj): 364 | devFsPath = None 365 | devFsPath = line.split(':') 366 | continue 367 | matchObj = virtualDiskExp.match(line) 368 | if (matchObj): 369 | if (devFsPath and len(devFsPath) > 1): 370 | isOpSuccess = 1 371 | break; 372 | if(isOpSuccess == 1): 373 | ksOutput += "clearpart --drives=" + devFsPath[1].strip() + " --overwritevmfs" 374 | ksOutput += "\n" 375 | ksOutput += "install --drive=" + devFsPath[1].strip() + " --overwritevmfs" 376 | ksOutput += "\n" 377 | else: 378 | ksOutput += "clearpart --firstdisk --overwritevmfs" 379 | ksOutput += "\n" 380 | ksOutput += "install --firstdisk --overwritevmfs" 381 | ksOutput += "\n" 382 | except Exception,detail: 383 | TEMP_CMD="logger Exception:" + str(detail) 384 | print TEMP_CMD 385 | 386 | return ksOutput 387 | 388 | def parseRipsDiskData(): 389 | diskObjects = [] 390 | try: 391 | xmlBlob = None 392 | status = 256 393 | OUTPUTSTR = "" 394 | (status,OUTPUTSTR) = commands.getstatusoutput("esxcfg-info -s -F xml > /tmp/storageinfo.xml") 395 | if (status == 0): 396 | xmlBlob = parse('/tmp/storageinfo.xml') 397 | 398 | if (xmlBlob): 399 | lunNodes = xmlBlob.getElementsByTagName('lun') 400 | if (lunNodes != None and lunNodes.length > 0): 401 | numChildNodes = lunNodes.length 402 | for ctr in range(numChildNodes): 403 | diskObj = DiskObject() 404 | lunChildNodes = lunNodes[ctr] 405 | if (lunChildNodes.hasChildNodes()): 406 | for lunChild in lunChildNodes.childNodes: 407 | if (lunChild != None and lunChild.attributes != None): 408 | if "name" in lunChild.attributes.keys(): 409 | model = None 410 | size = None 411 | devPath = None 412 | tempVal = None; 413 | attrInst = lunChild.attributes["name"] 414 | if (lunChild.hasChildNodes()): 415 | tempVal = lunChild.firstChild.nodeValue 416 | else: 417 | tempVal = lunChild.nodeValue 418 | if attrInst.value.lower() == "vendor": 419 | diskObj.vendor = tempVal 420 | if attrInst.value.lower() == "model": 421 | diskObj.model = tempVal 422 | if attrInst.value.lower() == "size": 423 | diskObj.size = tempVal 424 | if attrInst.value.lower() == "name": 425 | diskObj.diskPath = tempVal 426 | diskObjects.append(diskObj); 427 | except Exception,detail: 428 | TEMP_CMD="logger Exception:" + str(detail) 429 | print TEMP_CMD 430 | 431 | return diskObjects 432 | 433 | def getRipsObject(): 434 | ripsDisk = None 435 | retDisk = None 436 | diskList = parseRipsDiskData() 437 | if (diskList != None and len(diskList) > 0): 438 | for ripsDisk in diskList: 439 | if ( (ripsDisk.model.lower() == "internal dual sd") or (ripsDisk.model.lower() == "idsdm") ): 440 | retDisk = ripsDisk 441 | break 442 | return retDisk 443 | 444 | def getDiskInfo(): 445 | installCondition = "" 446 | ripsDisk = None 447 | ksOutput = "" 448 | try: 449 | if (installCondition == "sd_only" or installCondition == "first_sd_then_hd"): 450 | ripsDisk = getRipsObject() 451 | if (ripsDisk != None): 452 | ksOutput = "clearpart --drives=" + ripsDisk.diskPath + " --overwritevmfs\n" 453 | ksOutput += "install --drive=" + ripsDisk.diskPath + " --overwritevmfs --novmfsondisk\n" 454 | else: 455 | if (installCondition == "sd_only"): 456 | TEMP_STR = "Unable to find SD card...Error" 457 | logInstallProgress(TEMP_STR) 458 | reportErrors("267179") 459 | else: 460 | ksOutput = getVirtualDiskInfo() 461 | TEMP_STR = "Unable to find SD card, now installing to HD...Warning" 462 | logInstallProgress(TEMP_STR) 463 | else: 464 | ksOutput = getVirtualDiskInfo() 465 | except Exception,detail: 466 | TEMP_CMD="logger Exception:" + str(detail) 467 | print TEMP_CMD 468 | return ksOutput 469 | 470 | # Get network and disk information into 471 | # the file included by kickstart 472 | rootPwOut = getNetworkInfo() 473 | rootPwOut += getDiskInfo() 474 | writeIncludeOutput() 475 | EOF3 476 | python /tmp/runDaemon.py start 477 | python /tmp/getIdentity.py 478 | %post --interpreter=busybox 479 | python /tmp/runDaemon.py stop 480 | %firstboot --interpreter=python 481 | import commands,os,httplib,time,string 482 | from xml.dom.minidom import parseString 483 | CMD_STATUS = 256 484 | MY_IPADDR =commands.getoutput("esxcfg-vmknic -l | grep -vi Interface | awk '{print $5}'") 485 | ctr = 0 486 | time.sleep(60) 487 | while (MY_IPADDR == "0.0.0.0" and ctr < 5): 488 | time.sleep(20) 489 | ctr += 1 490 | MY_IPADDR =commands.getoutput("esxcfg-vmknic -l | grep -vi Interface | awk '{print $5}'") 491 | 492 | def logInstallProgress(progressData): 493 | try: 494 | logFile = open('/store/dell_postinstall.log','a') 495 | if (logFile and progressData and len(progressData) > 0): 496 | currTime = time.strftime("%d %b %y %H:%M:%S",time.gmtime()) 497 | TEMP_STR = currTime + " " + progressData + "\n" 498 | print TEMP_STR 499 | logFile.write(TEMP_STR) 500 | logFile.close() 501 | except Exception,detail: 502 | TEMP_CMD="logger Exception:" + str(detail) 503 | print TEMP_CMD 504 | 505 | def configureDNSOnESXi(): 506 | MY_VIRT_NIC = "" 507 | MY_DHCP_STR = "" 508 | STATUS = 0 509 | try: 510 | logInstallProgress("Configuring DNS on ESXi........") 511 | (STATUS, OUTPUTSTR) = commands.getstatusoutput("esxcfg-vmknic -l | grep -vi Interface") 512 | if (STATUS == 0): 513 | VMKNICARR = OUTPUTSTR.split() 514 | MY_VIRT_NIC = VMKNICARR[0] 515 | MY_DHCP_STR = VMKNICARR[11] 516 | logInstallProgress("Virtual NIC device name is " + MY_VIRT_NIC) 517 | logInstallProgress("DHCP status on system is "+MY_DHCP_STR) 518 | if (MY_DHCP_STR == "DHCP"): 519 | logInstallProgress("System is set with DHCP ..configuring DNS") 520 | TEMP_STR = "vim-cmd hostsvc/net/dns_set --dhcp=true --dhcp-virtualnic=" + MY_VIRT_NIC 521 | (STATUS,OUTPUTSTR) = commands.getstatusoutput(TEMP_STR) 522 | if (STATUS == 0): 523 | logInstallProgress("Successfully set dns entries") 524 | commands.getoutput("vim-cmd hostsvc/net/refresh") 525 | else: 526 | logInstallProgress("Unable to set DNS entries") 527 | else: 528 | logInstallProgress("System configured for static IP..Extracting resolv.conf settings") 529 | fileHdl = open('/etc/resolv.conf','r') 530 | if (fileHdl): 531 | resolvFileLines = fileHdl.readlines() 532 | fileHdl.close() 533 | opFileHdl = open('/store/resolv.conf','w') 534 | if (opFileHdl): 535 | resolveFileContents = ''.join(resolvFileLines) 536 | opFileHdl.write(resolveFileContents) 537 | opFileHdl.close() 538 | logInstallProgress("Dumped DNS settings to /store/resolv.conf") 539 | else: 540 | logInstallProgress("Unable to open /store/resolv.conf for writing") 541 | else: 542 | logInstallProgress("Unable to open /etc/resolv.conf for reading") 543 | else: 544 | logInstallProgress("Unable to get esxcfg-vmknic output..exiting") 545 | except Exception,detail: 546 | TEMP_CMD="logger Exception:" + str(detail) 547 | print TEMP_CMD 548 | 549 | def callbackConsole(): 550 | MY_SVCTAG =commands.getoutput("esxcfg-info -w | grep -i 'serial number' | sed 's/[^a-zA-Z0-9]*\./ /g' | awk '{printf $3}'") 551 | MY_IPADDR =commands.getoutput("esxcfg-vmknic -l | grep -i IPv4 | awk '{print $5}'") 552 | logInstallProgress("Firstboot:Initial IP address is " + MY_IPADDR) 553 | ctr = 0 554 | while (MY_IPADDR == "0.0.0.0" and ctr < 5): 555 | time.sleep(60) 556 | ctr += 1 557 | MY_IPADDR =commands.getoutput("esxcfg-vmknic -l | grep -i IPv4 | awk '{print $5}'") 558 | logInstallProgress("Resolved IP address is " + MY_IPADDR) 559 | 560 | MY_COMMAND =commands.getoutput("esxcfg-advcfg -j overrideDuplicateImageDetection") 561 | logInstallProgress("overrideDuplicateImageDetection is " + MY_COMMAND) 562 | 563 | defNS="http://pg.dell.com/spectre/deploymentprogress/ws" 564 | envelope_template = """""" 565 | envelope_template += """""" 566 | envelope_template += """""" 567 | envelope_template += """""" 568 | envelope_template += """""" + MY_SVCTAG + """""" 569 | envelope_template += """""" + MY_IPADDR + """""" 570 | envelope_template += """""" 571 | envelope_template += """""" 572 | envelope_template += """""" 573 | try: 574 | envlen = len(envelope_template) 575 | _post = 'http:///Spectre/DeploymentProgressService' 576 | _host = '' 577 | _port = 443 578 | logInstallProgress("Initiated connection for updatehost") 579 | http_conn = httplib.HTTPSConnection(_host,_port) 580 | http_conn.putrequest('POST', _post) 581 | http_conn.putheader('Host', _host) 582 | http_conn.putheader('Content-Type', 'text/xml; charset="utf-8"') 583 | http_conn.putheader('Content-Length', str(envlen)) 584 | http_conn.putheader('SOAPAction', 'http://pg.dell.com/spectre/deploymentprogress/ws/UpdateHostDetails') 585 | http_conn.endheaders() 586 | http_conn.send(envelope_template) 587 | httpresponse = http_conn.getresponse() 588 | response = httpresponse.read() 589 | http_conn.close() 590 | idResponseBlob = parseString(response) 591 | logInstallProgress(idResponseBlob.toprettyxml()) 592 | updateResponseNode = idResponseBlob.getElementsByTagNameNS(defNS,'UpdateHostDetailsResponse') 593 | if (updateResponseNode == None or updateResponseNode.length <= 0): 594 | logInstallProgress("No update response node in ack from console...potential fault") 595 | idResponseBlob.unlink() 596 | return False 597 | else: 598 | logInstallProgress("Found update response node in ack from console...Exiting") 599 | idResponseBlob.unlink() 600 | return True 601 | except Exception,detail: 602 | TEMP_STR="logger Exception:" + str(detail) 603 | logInstallProgress(TEMP_STR) 604 | return False 605 | 606 | configureDNSOnESXi() 607 | ackRecvd = False 608 | while (ctr < 4 and ackRecvd == False): 609 | ctr += 1 610 | ackRecvd = callbackConsole() 611 | time.sleep(30) 612 | -------------------------------------------------------------------------------- /src/main/resources/deployment/ksESX.cfg: -------------------------------------------------------------------------------- 1 | vmaccepteula 2 | %include /tmp/rootpw.cfg 3 | install nfs --server={0} --dir={1} 4 | reboot 5 | %pre --interpreter=bash 6 | cat >/tmp/daemon.py << EOF1 7 | import sys, os, time, atexit, commands 8 | from signal import SIGTERM 9 | class Daemon: 10 | def __init__(self, pidfile, stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'): 11 | self.stdin = stdin 12 | self.stdout = stdout 13 | self.stderr = stderr 14 | self.pidfile = pidfile 15 | 16 | def daemonize(self): 17 | try: 18 | pid = os.fork() 19 | if pid > 0: 20 | # exit first parent 21 | sys.exit(0) 22 | except OSError, e: 23 | sys.stderr.write("fork #1 failed: %d (%s)\n" % (e.errno, e.strerror)) 24 | sys.exit(1) 25 | 26 | # decouple from parent environment 27 | os.chdir("/") 28 | os.setsid() 29 | os.umask(0) 30 | 31 | # do second fork 32 | try: 33 | pid = os.fork() 34 | if pid > 0: 35 | # exit from second parent 36 | sys.exit(0) 37 | except OSError, e: 38 | sys.stderr.write("fork #2 failed: %d (%s)\n" % (e.errno, e.strerror)) 39 | sys.exit(1) 40 | 41 | # redirect standard file descriptors 42 | sys.stdout.flush() 43 | sys.stderr.flush() 44 | si = file(self.stdin, 'r') 45 | so = file(self.stdout, 'a+') 46 | se = file(self.stderr, 'a+', 0) 47 | os.dup2(si.fileno(), sys.stdin.fileno()) 48 | os.dup2(so.fileno(), sys.stdout.fileno()) 49 | os.dup2(se.fileno(), sys.stderr.fileno()) 50 | 51 | # write pidfile 52 | atexit.register(self.delpid) 53 | pid = str(os.getpid()) 54 | file(self.pidfile,'w+').write("%s\n" % pid) 55 | 56 | def delpid(self): 57 | os.remove(self.pidfile) 58 | 59 | def start(self): 60 | # Check for a pidfile to see if the daemon already runs 61 | try: 62 | pf = file(self.pidfile,'r') 63 | pid = int(pf.read().strip()) 64 | pf.close() 65 | except IOError: 66 | pid = None 67 | 68 | if pid: 69 | message = "pidfile %s already exist. Daemon already running?\n" 70 | sys.stderr.write(message % self.pidfile) 71 | sys.exit(1) 72 | 73 | # Start the daemon 74 | self.daemonize() 75 | self.run() 76 | 77 | def stop(self): 78 | # Get the pid from the pidfile 79 | try: 80 | pf = file(self.pidfile,'r') 81 | pid = int(pf.read().strip()) 82 | pf.close() 83 | except IOError: 84 | pid = None 85 | 86 | if not pid: 87 | message = "pidfile %s does not exist. Daemon not running?\n" 88 | sys.stderr.write(message % self.pidfile) 89 | return # not an error in a restart 90 | 91 | # Try killing the daemon process 92 | try: 93 | MY_OP="" 94 | CTR = 0 95 | while CTR < 10: 96 | CTR += 1 97 | TEMP_CMD="kill -9 " + str(pid) 98 | MY_OP = commands.getoutput(TEMP_CMD) 99 | if (MY_OP.find("No such process")) > 0: 100 | if os.path.exists(self.pidfile): 101 | os.remove(self.pidfile) 102 | time.sleep(2) 103 | except OSError, err: 104 | err = str(err) 105 | if err.find("No such process") > 0: 106 | if os.path.exists(self.pidfile): 107 | os.remove(self.pidfile) 108 | else: 109 | print str(err) 110 | sys.exit(1) 111 | 112 | def restart(self): 113 | self.stop() 114 | self.start() 115 | 116 | def run(self): 117 | message = "Initiating install progress monitor daemon" 118 | EOF1 119 | cat >/tmp/runDaemon.py << EOF2 120 | import sys, time, httplib, string, commands 121 | from xml.dom.minidom import parseString 122 | from daemon import Daemon 123 | class MyDaemon(Daemon): 124 | def run(self): 125 | MY_SVCTAG =commands.getoutput("esxcfg-info -w | grep -i serial | sed 's/[^a-zA-Z0-9]*\./ /g' | awk '{print \$3}'") 126 | ERR_MSG = [] 127 | ERR_MSG_STR = '' 128 | ERR_CODE = '267195' 129 | CTR = 0 130 | errorFound = False 131 | while (CTR < 50 and errorFound == False): 132 | time.sleep(30) 133 | CTR += 1 134 | f=open('/var/log/esx_install.log','r') 135 | if (f): 136 | LINES = f.readlines() 137 | f.close() 138 | for i in range(len(LINES)): 139 | if ((string.find(LINES[i],"ERROR") != -1) and (string.find(LINES[i],"DEBUG") == -1) and (string.find(LINES[i],"metadata.zip") == -1) and (string.find(LINES[i],"No route to host") == -1)): 140 | TEMP_STR = LINES[i].rstrip('\n') 141 | ERR_MSG.append(TEMP_STR) 142 | errorFound = True 143 | if (len(ERR_MSG) > 0 and errorFound == True): 144 | for MSG in ERR_MSG: 145 | ERR_MSG_STR += MSG 146 | if (len(MY_SVCTAG) == 7 and len(ERR_MSG_STR) > 0): 147 | defNS="http://pg.dell.com/spectre/deploymentprogress/ws" 148 | envelope_template = """""" 149 | envelope_template += """""" 150 | envelope_template += """""" 151 | envelope_template += """""" 152 | envelope_template += """""" + MY_SVCTAG + """""" 153 | envelope_template += """""" + ERR_CODE + """""" 154 | envelope_template += """""" + ERR_MSG_STR + """""" 155 | envelope_template += """""" 156 | envelope_template += """""" 157 | envelope_template += """""" 158 | try: 159 | envlen = len(envelope_template) 160 | _post = 'http:///Spectre/DeploymentProgressService' 161 | _host = '' 162 | _port = 443 163 | http_conn = httplib.HTTPSConnection(_host,_port) 164 | http_conn.putrequest('POST', _post) 165 | http_conn.putheader('Host', _host) 166 | http_conn.putheader('Content-Type', 'text/xml; charset="utf-8"') 167 | http_conn.putheader('Content-Length', str(envlen)) 168 | http_conn.putheader('SOAPAction', 'http://pg.dell.com/spectre/deploymentprogress/ws/SetInstallationError') 169 | http_conn.endheaders() 170 | http_conn.send(envelope_template) 171 | httpresponse = http_conn.getresponse() 172 | response = httpresponse.read() 173 | http_conn.close() 174 | idResponseBlob = parseString(response) 175 | idResponseBlob.unlink() 176 | daemon.stop() 177 | except Exception,detail: 178 | TEMP_STR = "logger Exception:" + str(detail) 179 | print TEMP_STR 180 | daemon.stop() 181 | 182 | if __name__ == "__main__": 183 | daemon = MyDaemon('/tmp/daemon-example.pid') 184 | if len(sys.argv) == 2: 185 | if 'start' == sys.argv[1]: 186 | daemon.start() 187 | elif 'stop' == sys.argv[1]: 188 | daemon.stop() 189 | elif 'restart' == sys.argv[1]: 190 | daemon.restart() 191 | else: 192 | print "Unknown command" 193 | sys.exit(0) 194 | else: 195 | print "usage: %s start|stop|restart" % sys.argv[0] 196 | EOF2 197 | cat > /tmp/getIdentity.py <""" 212 | envelope_template += """""" 213 | envelope_template += """""" 214 | envelope_template += """""" 215 | envelope_template += """""" + MY_SVCTAG + """""" 216 | envelope_template += """""" + MY_MAC + """""" 217 | envelope_template += """""" 218 | envelope_template += """""" 219 | envelope_template += """""" 220 | try: 221 | envlen = len(envelope_template) 222 | _post = 'http:///Spectre/DeploymentProgressService' 223 | _host = '' 224 | _port = 443 225 | http_conn = httplib.HTTPSConnection(_host,_port) 226 | http_conn.putrequest('POST', _post) 227 | http_conn.putheader('Host', _host) 228 | http_conn.putheader('Content-Type', 'text/xml; charset="utf-8"') 229 | http_conn.putheader('Content-Length', str(envlen)) 230 | http_conn.putheader('SOAPAction', 'http://pg.dell.com/spectre/deploymentprogress/ws/GetIdentity') 231 | http_conn.endheaders() 232 | http_conn.send(envelope_template) 233 | httpresponse = http_conn.getresponse() 234 | response = httpresponse.read() 235 | http_conn.close() 236 | idResponseBlob = parseString(response) 237 | serverDetailsNodeList = idResponseBlob.getElementsByTagNameNS(defNS,'ServerDetails') 238 | if (serverDetailsNodeList == None or serverDetailsNodeList.length <= 0): 239 | print "ERROR: Unable to get server detail info from Dell Plugin" 240 | else: 241 | for serverDetailsNode in serverDetailsNodeList.item(0).childNodes: 242 | if (serverDetailsNode and serverDetailsNode.hasChildNodes()): 243 | tempNodeVal = serverDetailsNode.childNodes.item(0).nodeValue 244 | if (serverDetailsNode.localName == "password" and tempNodeVal != None): 245 | ksOutput += "rootpw --iscrypted " + tempNodeVal + "\n" 246 | elif (serverDetailsNode.localName == "NetworkDetails"): 247 | networkDetailsChildren = serverDetailsNode.childNodes 248 | if (networkDetailsChildren and networkDetailsChildren.length > 0): 249 | for networkDetailNode in networkDetailsChildren: 250 | tempNodeName = networkDetailNode.localName 251 | if (networkDetailNode.hasChildNodes()): 252 | tempNodeVal = networkDetailNode.childNodes.item(0).nodeValue 253 | if (tempNodeVal != None): 254 | if (tempNodeName == "ipAddress" and tempNodeVal !=None): 255 | ipAddrToken = tempNodeVal 256 | useStaticIP = True 257 | if (tempNodeName == "macAddress" and tempNodeVal != None): 258 | macAddrToken = tempNodeVal 259 | if (tempNodeName == "vLanId" and tempNodeVal != None and tempNodeVal != "-1"): 260 | vlanidToken = tempNodeVal 261 | if (useStaticIP == False): 262 | ksOutput += "network --bootproto=dhcp" 263 | if (macAddrToken and len(macAddrToken) > 0): 264 | ksOutput += " --device=" + macAddrToken 265 | if (vlanidToken and len(vlanidToken) > 0): 266 | ksOutput += " --vlanid=" + vlanidToken 267 | ksOutput += "\n" 268 | else: 269 | ksOutput += "network --bootproto=static" 270 | if (vlanidToken and len(vlanidToken) > 0): 271 | ksOutput += " --vlanid=" + vlanidToken 272 | if (ipAddrToken and len(ipAddrToken) > 0): 273 | ksOutput += " --ip=" + ipAddrToken 274 | if (macAddrToken and len(macAddrToken) > 0): 275 | ksOutput += " --device=" + macAddrToken 276 | for networkDetailNode in networkDetailsChildren: 277 | tempNodeName = networkDetailNode.localName 278 | if (networkDetailNode.hasChildNodes()): 279 | tempNodeVal = networkDetailNode.childNodes.item(0).nodeValue 280 | if (tempNodeVal != None): 281 | if (tempNodeName == "defaultGateway"): 282 | ksOutput += " --gateway=" + tempNodeVal 283 | if (tempNodeName == "subnetMask"): 284 | ksOutput += " --netmask=" + tempNodeVal 285 | if (tempNodeName == "preferredDns"): 286 | dnsServers = tempNodeVal 287 | if (tempNodeName == "alternateDns"): 288 | dnsServers += "," + tempNodeVal 289 | if (tempNodeName == "hostName"): 290 | ksOutput += " --hostname=" + tempNodeVal 291 | if (dnsServers and len(dnsServers) > 0): 292 | ksOutput += " --nameserver=" + dnsServers 293 | ksOutput += "\n" 294 | else: 295 | commands.getoutput("logger Unable to derive network details") 296 | else: 297 | continue 298 | # Run and parse the first available virtual disk 299 | cmdStatus = 256 300 | cmdOutput = None 301 | tmpCmd = "esxcli corestorage device list > /tmp/diskResponse.txt" 302 | (status, cmdoutput) = commands.getstatusoutput(tmpCmd) 303 | if (status != 0): 304 | ksOutput += "clearpart --firstdisk --overwritevmfs" 305 | ksOutput += "\n" 306 | ksOutput += "autopart --firstdisk" 307 | ksOutput += "\n" 308 | else: 309 | devfsStr = ".*Devfs Path:*" 310 | virtualDiskStr = ".*Model: Virtual Disk*" 311 | devfsExp = re.compile(devfsStr, re.IGNORECASE) 312 | virtualDiskExp = re.compile(virtualDiskStr, re.IGNORECASE) 313 | isOpSuccess = 0 314 | matchObj = None 315 | devFsPath = [] 316 | displayLines = [] 317 | opFileHdl = open('/tmp/diskResponse.txt', 'r') 318 | if (opFileHdl): 319 | displayLines = opFileHdl.readlines() 320 | opFileHdl.close() 321 | if (displayLines and len(displayLines) > 0): 322 | for line in displayLines: 323 | matchObj = devfsExp.match(line) 324 | if (matchObj): 325 | devFsPath = None 326 | devFsPath = line.split(':') 327 | continue 328 | matchObj = virtualDiskExp.match(line) 329 | if (matchObj): 330 | if (devFsPath and len(devFsPath) > 1): 331 | isOpSuccess = 1 332 | break; 333 | if(isOpSuccess == 1): 334 | ksOutput += "clearpart --drives=" + devFsPath[1].strip() + " --overwritevmfs" 335 | ksOutput += "\n" 336 | ksOutput += "autopart --drive=" + devFsPath[1].strip() 337 | ksOutput += "\n" 338 | else: 339 | ksOutput += "clearpart --firstdisk --overwritevmfs" 340 | ksOutput += "\n" 341 | ksOutput += "autopart --firstdisk" 342 | ksOutput += "\n" 343 | # Completed parsing all nodes - time to dump output into /tmp/rootpw.cfg 344 | fileHdl = open('/tmp/rootpw.cfg', 'w') 345 | if (fileHdl): 346 | fileHdl.write(ksOutput) 347 | fileHdl.close() 348 | idResponseBlob.unlink() 349 | except Exception,detail: 350 | TEMP_CMD="logger Exception:" + str(detail) 351 | print TEMP_CMD 352 | EOF3 353 | python /tmp/runDaemon.py start 354 | python /tmp/getIdentity.py 355 | %post --interpreter=bash --nochroot 356 | python /tmp/runDaemon.py stop 357 | %post --interpreter=bash 358 | cat > /root/installomsa.py < 0): 372 | currTime = time.strftime("%d %b %y %H:%M:%S",time.gmtime()) 373 | TEMP_STR = currTime + " " + progressData 374 | print TEMP_STR 375 | logFile.write(TEMP_STR) 376 | logFile.close() 377 | 378 | ## Method to report errors back to the Spectre Engine ## 379 | def reportErrors(ERR_MSG_STR): 380 | ERR_DTL = '' 381 | MY_SVCTAG =commands.getoutput("esxcfg-info -w | grep -i serial | sed 's/[^a-zA-Z0-9]*\./ /g' | awk '{print \$3}'") 382 | if (len(MY_SVCTAG) == 7 and len(ERR_MSG_STR) > 0): 383 | defNS="http://pg.dell.com/spectre/deploymentprogress/ws" 384 | envelope_template = """""" 385 | envelope_template += """""" 386 | envelope_template += """""" 387 | envelope_template += """""" 388 | envelope_template += """""" + MY_SVCTAG + """""" 389 | envelope_template += """""" + ERR_MSG_STR + """""" 390 | envelope_template += """""" + ERR_DTL + """""" 391 | envelope_template += """""" 392 | envelope_template += """""" 393 | envelope_template += """""" 394 | try: 395 | envlen = len(envelope_template) 396 | _post = 'http:///Spectre/DeploymentProgressService' 397 | _host = '' 398 | _port = 443 399 | http_conn = httplib.HTTPSConnection(_host,_port) 400 | http_conn.putrequest('POST', _post) 401 | http_conn.putheader('Host', _host) 402 | http_conn.putheader('Content-Type', 'text/xml; charset="utf-8"') 403 | http_conn.putheader('Content-Length', str(envlen)) 404 | http_conn.putheader('SOAPAction', 'http://pg.dell.com/spectre/deploymentprogress/ws/SetInstallationError') 405 | http_conn.endheaders() 406 | http_conn.send(envelope_template) 407 | httpresponse = http_conn.getresponse() 408 | response = httpresponse.read() 409 | http_conn.close() 410 | idResponseBlob = parseString(response) 411 | idResponseBlob.unlink() 412 | except Exception,detail: 413 | TEMP_STR="logger Exception:" + str(detail) 414 | logInstallProgress(TEMP_STR) 415 | print TEMP_STR 416 | 417 | def callbackConsole(): 418 | MY_SVCTAG =commands.getoutput("esxcfg-info -w | grep -i serial | sed 's/[^a-zA-Z0-9]*\./ /g' | awk '{print \$3}'") 419 | MY_IPADDR =commands.getoutput("esxcfg-vswif -l | grep -vi broadcast | awk '{print \$5}'") 420 | print "Initial IP address is ", MY_IPADDR 421 | ctr = 0 422 | while (MY_IPADDR == "0.0.0.0" and ctr < 5): 423 | time.sleep(60) 424 | ctr += 1 425 | MY_IPADDR =commands.getoutput("esxcfg-vswif -l | grep -vi broadcast | awk '{print \$5}'") 426 | defNS="http://pg.dell.com/spectre/deploymentprogress/ws" 427 | envelope_template = """""" 428 | envelope_template += """""" 429 | envelope_template += """""" 430 | envelope_template += """""" 431 | envelope_template += """""" + MY_SVCTAG + """""" 432 | envelope_template += """""" + MY_IPADDR + """""" 433 | envelope_template += """""" 434 | envelope_template += """""" 435 | envelope_template += """""" 436 | try: 437 | envlen = len(envelope_template) 438 | _post = 'http:///Spectre/DeploymentProgressService' 439 | _host = '' 440 | _port = 443 441 | http_conn = httplib.HTTPSConnection(_host,_port) 442 | http_conn.putrequest('POST', _post) 443 | http_conn.putheader('Host', _host) 444 | http_conn.putheader('Content-Type', 'text/xml; charset="utf-8"') 445 | http_conn.putheader('Content-Length', str(envlen)) 446 | http_conn.putheader('SOAPAction', 'http://pg.dell.com/spectre/deploymentprogress/ws/UpdateHostDetails') 447 | http_conn.endheaders() 448 | http_conn.send(envelope_template) 449 | httpresponse = http_conn.getresponse() 450 | response = httpresponse.read() 451 | http_conn.close() 452 | idResponseBlob = parseString(response) 453 | ## Dump the response from spectre into the install log 454 | logInstallProgress(idResponseBlob.toprettyxml()) 455 | updateResponseNode = idResponseBlob.getElementsByTagNameNS(defNS,'UpdateHostDetailsResponse') 456 | if (updateResponseNode == None or updateResponseNode.length <= 0): 457 | logInstallProgress("No update response node in ack from console...potential fault") 458 | idResponseBlob.unlink() 459 | return False 460 | else: 461 | logInstallProgress("Found update response node in ack from console...Exiting") 462 | idResponseBlob.unlink() 463 | return True 464 | except Exception,detail: 465 | TEMP_STR = "Exception:" + str(detail) 466 | logInstallProgress(TEMP_STR) 467 | return False 468 | 469 | def logErrors(errorString): 470 | if (errorString and len(errorString) > 0): 471 | print "Error Code: " + errorString 472 | reportErrors(errorString) 473 | 474 | def installOMSAOnESX(esxVersion): 475 | CMD_STATUS = 256 476 | MY_TEMP_FILE = "/tmp/omsa_esx.tar.gz" 477 | MY_WORKING_DIR = "/tmp/omsa_esx" 478 | 479 | logInstallProgress("Downloading OMSA tarball for ESX 4.1\n") 480 | urllib.urlretrieve(MY_ESX41_URL, MY_TEMP_FILE) 481 | logInstallProgress("Completed download of OMSA tarball for ESX 4.1\n") 482 | 483 | if (os.path.exists(MY_TEMP_FILE)): 484 | logInstallProgress("Temporary omsa download exists...\n") 485 | fileSize = os.stat(MY_TEMP_FILE)[ST_SIZE] 486 | if (fileSize > 32768): 487 | TEMP_CMD = "mkdir " + MY_WORKING_DIR 488 | (CMD_STATUS, INFO) = commands.getstatusoutput(TEMP_CMD) 489 | if (CMD_STATUS == 0): 490 | logInstallProgress("Temporary working directory created for OMSA install\n") 491 | CMD_STATUS = 256 492 | TEMP_CMD = "tar -zxvf " + MY_TEMP_FILE + " -C " + MY_WORKING_DIR 493 | logInstallProgress("Successfully untarred omsa archive into temp dir\n") 494 | (CMD_STATUS,INFO) = commands.getstatusoutput(TEMP_CMD) 495 | if (CMD_STATUS == 0): 496 | CMD_STATUS = 256 497 | logInstallProgress("Initializing OMSA install\n") 498 | TEMP_CMD = MY_WORKING_DIR + "/linux/supportscripts/srvadmin-install.sh -x -c" 499 | (CMD_STATUS,INFO) = commands.getstatusoutput(TEMP_CMD) 500 | if (CMD_STATUS == 0): 501 | logInstallProgress("OMSA successfully installed\n") 502 | CMD_STATUS = 256 503 | TEMP_CMD = "("+ MY_WORKING_DIR + "/linux/supportscripts/srvadmin-services.sh start 2>&1) >/dev/null" 504 | os.popen(TEMP_CMD) 505 | time.sleep(180) 506 | TEMP_CMD = MY_WORKING_DIR + "/linux/supportscripts/srvadmin-services.sh status" 507 | (CMD_STATUS,INFO) = commands.getstatusoutput(TEMP_CMD) 508 | if (CMD_STATUS == 0): 509 | logInstallProgress("Successfully started OMSA agents\n") 510 | else: 511 | # Inability to start the agents shouldn't fail deployment either 512 | logInstallProgress("Unable to start OMSA agents\n") 513 | logInstallProgress("Configuring firewall for OMSA exception\n") 514 | CMD_STATUS = 256 515 | (CMD_STATUS, INFO) = commands.getstatusoutput("esxcfg-firewall -o 1311,tcp,in,OpenManageRequest") 516 | if (CMD_STATUS == 0): 517 | logInstallProgress("Successfully opened OMSA firewall exception\n") 518 | TRAP_CFG_STATUS = True 519 | TRAP_CFG_STATUS = configOMSAOnESX() 520 | if (TRAP_CFG_STATUS == True): 521 | return True 522 | else: 523 | return False 524 | else: 525 | TEMP_STR = "Unable to open OMSA firewall exception : " + INFO 526 | logInstallProgress(TEMP_STR) 527 | logErrors("267191") 528 | return False 529 | else: 530 | TEMP_STR = "Unable to install OMSA: " + INFO + "\n" 531 | logInstallProgress(TEMP_STR) 532 | logErrors("267184") 533 | return False 534 | else: 535 | TEMP_STR = "Unable to untar OMSA archive..Exiting\n" 536 | logInstallProgress(TEMP_STR) 537 | logErrors("267192") 538 | return False 539 | else: 540 | TEMP_STR = "Unable to make temp directory for OMSA installation\n" 541 | logInstallProgress(TEMP_STR) 542 | logErrors("267193") 543 | return False 544 | else: 545 | TEMP_STR = "Unable to use downloaded file for OMSA install\n" 546 | logInstallProgress(TEMP_STR) 547 | logErrors("267182") 548 | return False 549 | else: 550 | TEMP_STR = "OMSA not downloaded or no permissions to write to /tmp\n" 551 | logInstallProgress(TEMP_STR) 552 | logErrors("267183") 553 | return False 554 | 555 | 556 | def configOMSAOnESX(): 557 | snmpFile = open('/etc/snmp/snmpd.conf', 'a') 558 | if (snmpFile): 559 | snmpFile.write("trapsink public") 560 | snmpFile.close() 561 | (CMD_STATUS,INFO) = commands.getstatusoutput("esxcfg-firewall -e snmpd") 562 | if (CMD_STATUS == 0): 563 | logInstallProgress("Successfully opened SNMP firewall exception\n") 564 | else: 565 | logInstallProgress("Unable to open SNMP firewall exception\n") 566 | # This needn't cause deployment to fail - should be easy to rectify from the 567 | # console if this happens 568 | return True 569 | else: 570 | TEMP_STR = "Unable to configure SNMP trap destination\n" 571 | logInstallProgress(TEMP_STR) 572 | logErrors("267194") 573 | return False 574 | 575 | (CMD_STATUS, MY_HYP_VER) = commands.getstatusoutput("vmware -v | awk '{print \$2 \$3}'") 576 | try: 577 | if (CMD_STATUS == 0): 578 | # Reset the status of the command 579 | CMD_STATUS = 256 580 | # Now check if we can open the firewall for retreiving the file 581 | (CMD_STATUS, OPEN_FIREWALL) = commands.getstatusoutput("esxcfg-firewall -o 443,tcp,in,out,https") 582 | if (CMD_STATUS == 0): 583 | if (MY_HYP_VER == "ESX4.1.0"): 584 | OMSA_INST_STATUS = False 585 | OMSA_INST_STATUS = installOMSAOnESX(1) 586 | if (OMSA_INST_STATUS == True): 587 | ctr = 0 588 | ackRecvd = False 589 | while (ctr < 4 and ackRecvd == False): 590 | ctr += 1 591 | ackRecvd = callbackConsole() 592 | time.sleep(30) 593 | else: 594 | TEMP_STR = "Unsupported ESX version..." + MY_HYP_VER 595 | logInstallProgress(TEMP_STR) 596 | reportErrors("267190") 597 | # Reset command status and close firewall HTTPS exception 598 | CMD_STATUS = 256 599 | (CMD_STATUS, CLOSE_FIREWALL) = commands.getstatusoutput("esxcfg-firewall -c 443,tcp,in,out,https") 600 | if (CMD_STATUS == 0): 601 | TEMP_STR = "Closed firewall for HTTPs requests successfully\n" 602 | logInstallProgress(TEMP_STR) 603 | else: 604 | TEMP_STR = "Unable to close firewall for HTTPs exception:" + CLOSE_FIREWALL + "\n" 605 | logInstallProgress(TEMP_STR) 606 | else: 607 | logInstallProgress("Unable to open firewall for https...not installing OMSA\n") 608 | else: 609 | logInstallProgress("Unable to get hypervisor version...not installing OMSA\n") 610 | except Exception,detail: 611 | TEMP_STR = "Exception occured : " + str(detail) 612 | logInstallProgress(TEMP_STR) 613 | EOFOMSA 614 | cp /etc/rc.d/rc.local /etc/rc.d/rc.local.bak 615 | cat >> /etc/rc.d/rc.local </tmp/daemon.py << EOF1 7 | import sys, os, time, atexit,commands 8 | from signal import SIGTERM 9 | class Daemon: 10 | def __init__(self, pidfile, stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'): 11 | self.stdin = stdin 12 | self.stdout = stdout 13 | self.stderr = stderr 14 | self.pidfile = pidfile 15 | 16 | def daemonize(self): 17 | try: 18 | pid = os.fork() 19 | if pid > 0: 20 | # exit first parent 21 | sys.exit(0) 22 | except OSError, e: 23 | sys.stderr.write("fork #1 failed: %d (%s)\n" % (e.errno, e.strerror)) 24 | sys.exit(1) 25 | 26 | # decouple from parent environment 27 | os.chdir("/") 28 | os.setsid() 29 | os.umask(0) 30 | 31 | # do second fork 32 | try: 33 | pid = os.fork() 34 | if pid > 0: 35 | # exit from second parent 36 | sys.exit(0) 37 | except OSError, e: 38 | sys.stderr.write("fork #2 failed: %d (%s)\n" % (e.errno, e.strerror)) 39 | sys.exit(1) 40 | 41 | # redirect standard file descriptors 42 | sys.stdout.flush() 43 | sys.stderr.flush() 44 | si = file(self.stdin, 'r') 45 | so = file(self.stdout, 'a+') 46 | se = file(self.stderr, 'a+', 0) 47 | os.dup2(si.fileno(), sys.stdin.fileno()) 48 | os.dup2(so.fileno(), sys.stdout.fileno()) 49 | os.dup2(se.fileno(), sys.stderr.fileno()) 50 | 51 | # write pidfile 52 | atexit.register(self.delpid) 53 | pid = str(os.getpid()) 54 | file(self.pidfile,'w+').write("%s\n" % pid) 55 | 56 | def delpid(self): 57 | os.remove(self.pidfile) 58 | 59 | def start(self): 60 | # Check for a pidfile to see if the daemon already runs 61 | try: 62 | pf = file(self.pidfile,'r') 63 | pid = int(pf.read().strip()) 64 | pf.close() 65 | except IOError: 66 | pid = None 67 | 68 | if pid: 69 | message = "pidfile %s already exist. Daemon already running?\n" 70 | sys.stderr.write(message % self.pidfile) 71 | sys.exit(1) 72 | 73 | # Start the daemon 74 | self.daemonize() 75 | self.run() 76 | 77 | def stop(self): 78 | # Get the pid from the pidfile 79 | try: 80 | pf = file(self.pidfile,'r') 81 | pid = int(pf.read().strip()) 82 | pf.close() 83 | except IOError: 84 | pid = None 85 | 86 | if not pid: 87 | message = "pidfile %s does not exist. Daemon not running?\n" 88 | sys.stderr.write(message % self.pidfile) 89 | return # not an error in a restart 90 | 91 | # Try killing the daemon process 92 | try: 93 | MY_OP="" 94 | CTR = 0 95 | while CTR < 10: 96 | CTR += 1 97 | TEMP_CMD="kill -9 " + str(pid) 98 | MY_OP = commands.getoutput(TEMP_CMD) 99 | if (MY_OP.find("No such process")) > 0: 100 | if os.path.exists(self.pidfile): 101 | os.remove(self.pidfile) 102 | time.sleep(2) 103 | except OSError, err: 104 | err = str(err) 105 | if err.find("No such process") > 0: 106 | if os.path.exists(self.pidfile): 107 | os.remove(self.pidfile) 108 | else: 109 | print str(err) 110 | sys.exit(1) 111 | 112 | def restart(self): 113 | self.stop() 114 | self.start() 115 | 116 | def run(self): 117 | message = "hello there..." 118 | EOF1 119 | cat >/tmp/runDaemon.py << EOF2 120 | import sys, time, httplib, string, commands 121 | from xml.dom.minidom import parseString 122 | from daemon import Daemon 123 | class MyDaemon(Daemon): 124 | def run(self): 125 | MY_SVCTAG =commands.getoutput("esxcfg-info -w | grep -i serial | sed 's/[^a-zA-Z0-9]*\./ /g' | awk '{print \$3}'") 126 | ERR_MSG = [] 127 | ERR_MSG_STR = '' 128 | ERR_CODE = '267195' 129 | CTR = 0 130 | errorFound = False 131 | while (CTR < 40 and errorFound == False): 132 | time.sleep(30) 133 | CTR += 1 134 | f=open('/var/log/esxi_install.log','r') 135 | if (f): 136 | LINES = f.readlines() 137 | f.close() 138 | for i in range(len(LINES)): 139 | if ((string.find(LINES[i],"ERROR") != -1) and (string.find(LINES[i],"DEBUG") == -1)): 140 | TEMP_STR = LINES[i].rstrip('\n') 141 | ERR_MSG.append(TEMP_STR) 142 | errorFound = True 143 | if (len(ERR_MSG) > 0): 144 | for MSG in ERR_MSG: 145 | ERR_MSG_STR += MSG 146 | 147 | if (len(MY_SVCTAG) == 7 and len(ERR_MSG_STR) > 0): 148 | defNS="http://pg.dell.com/spectre/deploymentprogress/ws" 149 | envelope_template = """""" 150 | envelope_template += """""" 151 | envelope_template += """""" 152 | envelope_template += """""" 153 | envelope_template += """""" + MY_SVCTAG + """""" 154 | envelope_template += """""" + ERR_CODE + """""" 155 | envelope_template += """""" + ERR_MSG_STR + """""" 156 | envelope_template += """""" 157 | envelope_template += """""" 158 | envelope_template += """""" 159 | try: 160 | envlen = len(envelope_template) 161 | _post = 'http:///Spectre/DeploymentProgressService' 162 | _host = '' 163 | _port = 443 164 | http_conn = httplib.HTTPSConnection(_host,_port) 165 | http_conn.putrequest('POST', _post) 166 | http_conn.putheader('Host', _host) 167 | http_conn.putheader('Content-Type', 'text/xml; charset="utf-8"') 168 | http_conn.putheader('Content-Length', str(envlen)) 169 | http_conn.putheader('SOAPAction', 'http://pg.dell.com/spectre/deploymentprogress/ws/SetInstallationError') 170 | http_conn.endheaders() 171 | http_conn.send(envelope_template) 172 | httpresponse = http_conn.getresponse() 173 | response = httpresponse.read() 174 | http_conn.close() 175 | idResponseBlob = parseString(response) 176 | idResponseBlob.unlink() 177 | daemon.stop() 178 | except Exception,detail: 179 | TEMP_STR="logger Exception:" + str(detail) 180 | print TEMP_STR 181 | daemon.stop() 182 | 183 | if __name__ == "__main__": 184 | daemon = MyDaemon('/tmp/daemon-example.pid') 185 | if len(sys.argv) == 2: 186 | if 'start' == sys.argv[1]: 187 | daemon.start() 188 | elif 'stop' == sys.argv[1]: 189 | daemon.stop() 190 | elif 'restart' == sys.argv[1]: 191 | daemon.restart() 192 | else: 193 | print "Unknown command" 194 | #sys.exit(2) 195 | sys.exit(0) 196 | else: 197 | print "usage: %s start|stop|restart" % sys.argv[0] 198 | EOF2 199 | cat > /tmp/getIdentity.py <""" 214 | envelope_template += """""" 215 | envelope_template += """""" 216 | envelope_template += """""" 217 | envelope_template += """""" + MY_SVCTAG + """""" 218 | envelope_template += """""" + MY_MAC + """""" 219 | envelope_template += """""" 220 | envelope_template += """""" 221 | envelope_template += """""" 222 | try: 223 | envlen = len(envelope_template) 224 | _post = 'http:///Spectre/DeploymentProgressService' 225 | _host = '' 226 | _port = 443 227 | http_conn = httplib.HTTPSConnection(_host,_port) 228 | http_conn.putrequest('POST', _post) 229 | http_conn.putheader('Host', _host) 230 | http_conn.putheader('Content-Type', 'text/xml; charset="utf-8"') 231 | http_conn.putheader('Content-Length', str(envlen)) 232 | http_conn.putheader('SOAPAction', 'http://pg.dell.com/spectre/deploymentprogress/ws/GetIdentity') 233 | http_conn.endheaders() 234 | http_conn.send(envelope_template) 235 | httpresponse = http_conn.getresponse() 236 | response = httpresponse.read() 237 | http_conn.close() 238 | idResponseBlob = parseString(response) 239 | serverDetailsNodeList = idResponseBlob.getElementsByTagNameNS(defNS,'ServerDetails') 240 | if (serverDetailsNodeList == None or serverDetailsNodeList.length <= 0): 241 | print "ERROR: Unable to get server detail info from Dell Plugin" 242 | else: 243 | for serverDetailsNode in serverDetailsNodeList.item(0).childNodes: 244 | if (serverDetailsNode and serverDetailsNode.hasChildNodes()): 245 | tempNodeVal = serverDetailsNode.childNodes.item(0).nodeValue 246 | if (serverDetailsNode.localName == "password" and tempNodeVal != None): 247 | ksOutput += "rootpw --iscrypted " + tempNodeVal + "\n" 248 | elif (serverDetailsNode.localName == "NetworkDetails"): 249 | networkDetailsChildren = serverDetailsNode.childNodes 250 | if (networkDetailsChildren and networkDetailsChildren.length > 0): 251 | for networkDetailNode in networkDetailsChildren: 252 | tempNodeName = networkDetailNode.localName 253 | if (networkDetailNode.hasChildNodes()): 254 | tempNodeVal = networkDetailNode.childNodes.item(0).nodeValue 255 | if (tempNodeVal != None): 256 | if (tempNodeName == "ipAddress" and tempNodeVal !=None): 257 | ipAddrToken = tempNodeVal 258 | useStaticIP = True 259 | if (tempNodeName == "macAddress" and tempNodeVal != None): 260 | macAddrToken = tempNodeVal 261 | if (tempNodeName == "vLanId" and tempNodeVal != None and tempNodeVal != "-1"): 262 | vlanidToken = tempNodeVal 263 | if (useStaticIP == False): 264 | ksOutput += "network --bootproto=dhcp" 265 | if (macAddrToken and len(macAddrToken) > 0): 266 | ksOutput += " --device=" + macAddrToken 267 | if (vlanidToken and len(vlanidToken) > 0): 268 | ksOutput += " --vlanid=" + vlanidToken 269 | ksOutput += "\n" 270 | else: 271 | ksOutput += "network --bootproto=static" 272 | if (vlanidToken and len(vlanidToken) > 0): 273 | ksOutput += " --vlanid=" + vlanidToken 274 | if (ipAddrToken and len(ipAddrToken) > 0): 275 | ksOutput += " --ip=" + ipAddrToken 276 | if (macAddrToken and len(macAddrToken) > 0): 277 | ksOutput += " --device=" + macAddrToken 278 | for networkDetailNode in networkDetailsChildren: 279 | tempNodeName = networkDetailNode.localName 280 | if (networkDetailNode.hasChildNodes()): 281 | tempNodeVal = networkDetailNode.childNodes.item(0).nodeValue 282 | if (tempNodeVal != None): 283 | if (tempNodeName == "defaultGateway"): 284 | ksOutput += " --gateway=" + tempNodeVal 285 | if (tempNodeName == "subnetMask"): 286 | ksOutput += " --netmask=" + tempNodeVal 287 | if (tempNodeName == "preferredDns"): 288 | dnsServers = tempNodeVal 289 | if (tempNodeName == "alternateDns"): 290 | dnsServers += "," + tempNodeVal 291 | if (tempNodeName == "hostName"): 292 | ksOutput += " --hostname=" + tempNodeVal 293 | if (dnsServers and len(dnsServers) > 0): 294 | ksOutput += " --nameserver=" + dnsServers 295 | ksOutput += "\n" 296 | else: 297 | commands.getoutput("logger Unable to derive network details") 298 | else: 299 | continue 300 | # Run and parse the first available virtual disk 301 | cmdStatus = 256 302 | cmdOutput = None 303 | tmpCmd = "esxcfg-scsidevs -l > /tmp/diskResponse.txt" 304 | (status, cmdoutput) = commands.getstatusoutput(tmpCmd) 305 | if (status != 0): 306 | ksOutput += "clearpart --firstdisk --overwritevmfs" 307 | ksOutput += "\n" 308 | ksOutput += "autopart --firstdisk --overwritevmfs" 309 | ksOutput += "\n" 310 | else: 311 | devfsStr = ".*Devfs Path:*" 312 | virtualDiskStr = ".*Model: Virtual Disk*" 313 | devfsExp = re.compile(devfsStr, re.IGNORECASE) 314 | virtualDiskExp = re.compile(virtualDiskStr, re.IGNORECASE) 315 | isOpSuccess = 0 316 | matchObj = None 317 | devFsPath = [] 318 | displayLines = [] 319 | opFileHdl = open('/tmp/diskResponse.txt', 'r') 320 | if (opFileHdl): 321 | displayLines = opFileHdl.readlines() 322 | opFileHdl.close() 323 | if (displayLines and len(displayLines) > 0): 324 | for line in displayLines: 325 | matchObj = devfsExp.match(line) 326 | if (matchObj): 327 | devFsPath = None 328 | devFsPath = line.split(':') 329 | continue 330 | matchObj = virtualDiskExp.match(line) 331 | if (matchObj): 332 | if (devFsPath and len(devFsPath) > 1): 333 | isOpSuccess = 1 334 | break; 335 | if(isOpSuccess == 1): 336 | ksOutput += "clearpart --drives=" + devFsPath[1].strip() + " --overwritevmfs" 337 | ksOutput += "\n" 338 | ksOutput += "autopart --drive=" + devFsPath[1].strip() + " --overwritevmfs" 339 | ksOutput += "\n" 340 | else: 341 | ksOutput += "clearpart --firstdisk --overwritevmfs" 342 | ksOutput += "\n" 343 | ksOutput += "autopart --firstdisk --overwritevmfs" 344 | ksOutput += "\n" 345 | # Completed parsing all nodes - time to dump output into /tmp/rootpw.cfg 346 | fileHdl = open('/tmp/rootpw.cfg', 'w') 347 | if (fileHdl): 348 | fileHdl.write(ksOutput) 349 | fileHdl.close() 350 | idResponseBlob.unlink() 351 | except Exception,detail: 352 | TEMP_CMD="logger Exception:" + str(detail) 353 | print TEMP_CMD 354 | EOF3 355 | python /tmp/runDaemon.py start 356 | python /tmp/getIdentity.py 357 | %post --unsupported --interpreter=busybox 358 | python /tmp/runDaemon.py stop 359 | %firstboot --unsupported --interpreter=python --level=999 360 | import urllib,commands,os,time,string 361 | from stat import ST_SIZE 362 | from xml.dom.minidom import parseString 363 | CMD_STATUS = 256 364 | OMSA_NAME = "omsa_esxi41_vib.zip" 365 | 366 | MY_ESXI_URL = "https:///omsa/" + OMSA_NAME 367 | MY_TEMP_FILE = "/tmp/" + OMSA_NAME 368 | 369 | CMD_STATUS = 256 370 | MY_IPADDR =commands.getoutput("esxcfg-vmknic -l | grep -vi Interface | awk '{print $5}'") 371 | ctr = 0 372 | time.sleep(60) 373 | while (MY_IPADDR == "0.0.0.0" and ctr < 5): 374 | time.sleep(20) 375 | ctr += 1 376 | MY_IPADDR =commands.getoutput("esxcfg-vmknic -l | grep -vi Interface | awk '{print $5}'") 377 | 378 | def logInstallProgress(progressData): 379 | try: 380 | logFile = open('/store/dell_postinstall.log','a') 381 | if (logFile and progressData and len(progressData) > 0): 382 | currTime = time.strftime("%d %b %y %H:%M:%S",time.gmtime()) 383 | TEMP_STR = currTime + " " + progressData + "\n" 384 | print TEMP_STR 385 | logFile.write(TEMP_STR) 386 | logFile.close() 387 | except Exception,detail: 388 | TEMP_CMD="logger Exception:" + str(detail) 389 | print TEMP_CMD 390 | 391 | def configureDNSOnESXi(): 392 | MY_VIRT_NIC = "" 393 | MY_DHCP_STR = "" 394 | STATUS = 0 395 | try: 396 | logInstallProgress("Configuring DNS on ESXi........") 397 | (STATUS, OUTPUTSTR) = commands.getstatusoutput("esxcfg-vmknic -l | grep -vi Interface") 398 | if (STATUS == 0): 399 | VMKNICARR = OUTPUTSTR.split() 400 | MY_VIRT_NIC = VMKNICARR[0] 401 | MY_DHCP_STR = VMKNICARR[11] 402 | logInstallProgress("Virtual NIC device name is " + MY_VIRT_NIC) 403 | logInstallProgress("DHCP status on system is "+MY_DHCP_STR) 404 | if (MY_DHCP_STR == "DHCP"): 405 | logInstallProgress("System is set with DHCP ..configuring DNS") 406 | TEMP_STR = "vim-cmd hostsvc/net/dns_set --dhcp=true --dhcp-virtualnic=" + MY_VIRT_NIC 407 | (STATUS,OUTPUTSTR) = commands.getstatusoutput(TEMP_STR) 408 | if (STATUS == 0): 409 | logInstallProgress("Successfully set dns entries") 410 | commands.getoutput("vim-cmd hostsvc/net/refresh") 411 | else: 412 | logInstallProgress("Unable to set DNS entries") 413 | else: 414 | logInstallProgress("System configured for static IP..Extracting resolv.conf settings") 415 | fileHdl = open('/etc/resolv.conf','r') 416 | if (fileHdl): 417 | resolvFileLines = fileHdl.readlines() 418 | fileHdl.close() 419 | opFileHdl = open('/store/resolv.conf','w') 420 | if (opFileHdl): 421 | resolveFileContents = ''.join(resolvFileLines) 422 | opFileHdl.write(resolveFileContents) 423 | opFileHdl.close() 424 | logInstallProgress("Dumped DNS settings to /store/resolv.conf") 425 | else: 426 | logInstallProgress("Unable to open /store/resolv.conf for writing") 427 | else: 428 | logInstallProgress("Unable to open /etc/resolv.conf for reading") 429 | else: 430 | logInstallProgress("Unable to get esxcfg-vmknic output..exiting") 431 | except Exception,detail: 432 | TEMP_CMD="logger Exception:" + str(detail) 433 | print TEMP_CMD 434 | 435 | def configureOmsaOnESXi(): 436 | snmpOutput = "" 437 | snmpFileLines = [] 438 | try: 439 | fileHdl = open('/etc/vmware/snmp.xml','r') 440 | if (fileHdl): 441 | snmpFileLines = fileHdl.readlines() 442 | fileHdl.close() 443 | else: 444 | logInstallProgress("Unable to open snmp.xml file for parsing...Exiting") 445 | return 446 | snmpFileStr = ''.join(snmpFileLines) 447 | if (snmpFileStr and len(snmpFileStr) > 0): 448 | idResponseBlob = parseString(snmpFileStr) 449 | else: 450 | logInstallProgress("Unable to parse snmp config file ...Exiting") 451 | return 452 | if (idResponseBlob): 453 | configNodeList = idResponseBlob.getElementsByTagName('config') 454 | if (configNodeList and configNodeList.length > 0): 455 | for configNodes in configNodeList.item(0).childNodes: 456 | if (configNodes.localName == "snmpSettings"): 457 | snmpSettingsChildren = configNodes.childNodes 458 | if (snmpSettingsChildren and snmpSettingsChildren.length > 0): 459 | for snmpSetting in snmpSettingsChildren: 460 | tempNode = snmpSetting.localName 461 | if (tempNode == "enable"): 462 | if (snmpSetting.hasChildNodes()): 463 | snmpSetting.childNodes.item(0).nodeValue = "true" 464 | if (tempNode == "communities"): 465 | if (snmpSetting.hasChildNodes()): 466 | if (snmpSetting.childNodes.item(0).nodeValue and snmpSetting.childNodes.item(0).nodeValue != "public"): 467 | snmpSetting.childNodes.item(0).nodeValue += ",public" 468 | else: 469 | tempTextNode = idResponseBlob.createTextNode("public") 470 | snmpSetting.appendChild(tempTextNode) 471 | if (tempNode == "targets"): 472 | if (snmpSetting.hasChildNodes()): 473 | if (snmpSetting.childNodes.item(0).nodeValue): 474 | snmpSetting.childNodes.item(0).nodeValue += ", public" 475 | else: 476 | tempTextNode = idResponseBlob.createTextNode(" public") 477 | snmpSetting.appendChild(tempTextNode) 478 | else: 479 | pass 480 | snmpOutput = idResponseBlob.toxml() 481 | snmpOutput = string.replace(snmpOutput,"","") 482 | fileHdl = open('/etc/vmware/snmp.xml', 'w') 483 | if (fileHdl): 484 | fileHdl.write(snmpOutput) 485 | logInstallProgress("SNMP trap configuration completed successfully") 486 | fileHdl.close() 487 | idResponseBlob.unlink() 488 | except Exception,detail: 489 | TEMP_CMD="logger Exception:" + str(detail) 490 | logInstallProgress(TEMP_CMD) 491 | 492 | configureDNSOnESXi() 493 | logInstallProgress("Downloading OMSA VIB for ESXI 4.1") 494 | urllib.urlretrieve(MY_ESXI_URL, MY_TEMP_FILE) 495 | logInstallProgress("Completed download of OMSA VIB for ESXI 4.1") 496 | if (os.path.exists(MY_TEMP_FILE)): 497 | fileSize = os.stat(MY_TEMP_FILE)[ST_SIZE] 498 | if (fileSize > 32768): 499 | logInstallProgress("Configuring OMSA trap destination") 500 | configureOmsaOnESXi() 501 | 502 | %firstboot --unsupported --interpreter=busybox --level=1099 503 | cat > /store/installomsa.py < 0): 517 | currTime = time.strftime("%d %b %y %H:%M:%S",time.gmtime()) 518 | TEMP_STR = currTime + " " + progressData + "\n" 519 | print TEMP_STR 520 | logFile.write(TEMP_STR) 521 | logFile.close() 522 | except Exception,detail: 523 | TEMP_CMD="logger Exception:" + str(detail) 524 | print TEMP_CMD 525 | 526 | def reportErrors(ERR_MSG_STR): 527 | MY_SVCTAG =commands.getoutput("esxcfg-info -w | grep -i serial | sed 's/[^a-zA-Z0-9]*\./ /g' | awk '{print \$3}'") 528 | ERR_DTL = '' 529 | if (len(MY_SVCTAG) == 7 and len(ERR_MSG_STR) > 0): 530 | defNS="http://pg.dell.com/spectre/deploymentprogress/ws" 531 | envelope_template = """""" 532 | envelope_template += """""" 533 | envelope_template += """""" 534 | envelope_template += """""" 535 | envelope_template += """""" + MY_SVCTAG + """""" 536 | envelope_template += """""" + ERR_MSG_STR + """""" 537 | envelope_template += """""" + ERR_DTL + """""" 538 | envelope_template += """""" 539 | envelope_template += """""" 540 | envelope_template += """""" 541 | try: 542 | envlen = len(envelope_template) 543 | _post = 'http:///Spectre/DeploymentProgressService' 544 | _host = '' 545 | _port = 443 546 | http_conn = httplib.HTTPSConnection(_host,_port) 547 | http_conn.putrequest('POST', _post) 548 | http_conn.putheader('Host', _host) 549 | http_conn.putheader('Content-Type', 'text/xml; charset="utf-8"') 550 | http_conn.putheader('Content-Length', str(envlen)) 551 | http_conn.putheader('SOAPAction', 'http://pg.dell.com/spectre/deploymentprogress/ws/SetInstallationError') 552 | http_conn.endheaders() 553 | http_conn.send(envelope_template) 554 | httpresponse = http_conn.getresponse() 555 | response = httpresponse.read() 556 | http_conn.close() 557 | idResponseBlob = parseString(response) 558 | idResponseBlob.unlink() 559 | except Exception,detail: 560 | TEMP_STR="logger Exception:" + str(detail) 561 | logInstallProgress(TEMP_STR) 562 | 563 | def restoreBootbank(): 564 | fp = open('/vmfs/volumes/Hypervisor2/boot.cfg') 565 | lines = fp.readlines() 566 | fp.close() 567 | 568 | # erase the onetime.tgz file 569 | fp = open('/vmfs/volumes/Hypervisor2/boot.cfg', 'w') 570 | verification = '' 571 | for line in lines: 572 | if line.startswith('modules='): 573 | line = line.replace(' --- onetime.tgz', '') 574 | fp.write(line) 575 | verification += line 576 | fp.close() 577 | 578 | # verify file write in case of failed USB writes 579 | fp = open('/vmfs/volumes/Hypervisor2/boot.cfg') 580 | contents = fp.read() 581 | fp.close() 582 | if contents != verification: 583 | logInstallProgress("Restore Bootbank failed") 584 | else: 585 | logInstallProgress("Restore Bootbank successful") 586 | 587 | try: 588 | if (os.path.exists(MY_TEMP_FILE)): 589 | fileSize = os.stat(MY_TEMP_FILE)[ST_SIZE] 590 | if (fileSize > 32768): 591 | logInstallProgress("Installing OMSA vib for ESXi 4.1") 592 | CMD_STATUS = commands.getoutput(MY_UPDATE_CMD) 593 | CMD_STATUS = 256 594 | (CMD_STATUS,OP) = commands.getstatusoutput("esxupdate query") 595 | if (CMD_STATUS == 0): 596 | if (string.find(OP,"OpenManage") != -1 or string.find(OP,"Dell-Configuration-VIB") != -1): 597 | logInstallProgress("Installed OMSA successfully") 598 | restoreBootbank() 599 | else: 600 | TEMP_STR = "Unable to install OMSA...Error" 601 | logInstallProgress(TEMP_STR) 602 | reportErrors("267184") 603 | else: 604 | logInstallProgress("Unable to determine OMSA install status...") 605 | else: 606 | TEMP_STR="Unable to use downloaded file for install..Error" 607 | logInstallProgress(TEMP_STR) 608 | reportErrors("267182") 609 | else: 610 | TEMP_STR="File not downloaded or no permissions to write to /tmp..Exiting" 611 | logInstallProgress(TEMP_STR) 612 | reportErrors("267183") 613 | except Exception,detail: 614 | TEMP_STR="logger Exception:" + str(detail) 615 | logInstallProgress(TEMP_STR) 616 | EOF1 617 | cat > /store/firstboot.py < 0): 625 | currTime = time.strftime("%d %b %y %H:%M:%S",time.gmtime()) 626 | TEMP_STR = currTime + " " + progressData + "\n" 627 | print TEMP_STR 628 | logFile.write(TEMP_STR) 629 | logFile.close() 630 | except Exception,detail: 631 | TEMP_CMD="logger Exception:" + str(detail) 632 | print TEMP_CMD 633 | 634 | def configureDNSOnESXi(): 635 | MY_VIRT_NIC = "" 636 | MY_DHCP_STR = "" 637 | STATUS = 0 638 | try: 639 | logInstallProgress("Configuring DNS on ESXi........") 640 | (STATUS, OUTPUTSTR) = commands.getstatusoutput("esxcfg-vmknic -l | grep -vi Interface") 641 | if (STATUS == 0): 642 | VMKNICARR = OUTPUTSTR.split() 643 | MY_VIRT_NIC = VMKNICARR[0] 644 | MY_DHCP_STR = VMKNICARR[11] 645 | logInstallProgress("Virtual NIC device name is " + MY_VIRT_NIC) 646 | logInstallProgress("DHCP status on system is "+MY_DHCP_STR) 647 | if (MY_DHCP_STR == "DHCP"): 648 | logInstallProgress("System is set with DHCP ..configuring DNS") 649 | TEMP_STR = "vim-cmd hostsvc/net/dns_set --dhcp=true --dhcp-virtualnic=" + MY_VIRT_NIC 650 | (STATUS,OUTPUTSTR) = commands.getstatusoutput(TEMP_STR) 651 | if (STATUS == 0): 652 | logInstallProgress("Successfully set dns entries") 653 | commands.getoutput("vim-cmd hostsvc/net/refresh") 654 | else: 655 | logInstallProgress("Unable to set DNS entries") 656 | else: 657 | logInstallProgress("System configured for static IP..Extracting saved DNS config") 658 | fileHdl = open('/store/resolv.conf','r') 659 | if (fileHdl): 660 | resolvFileLines = fileHdl.readlines() 661 | logInstallProgress("Extracted saved DNS config") 662 | fileHdl.close() 663 | opFileHdl = open('/etc/resolv.conf','a') 664 | if (opFileHdl): 665 | resolveFileContents = ''.join(resolvFileLines) 666 | opFileHdl.write(resolveFileContents) 667 | opFileHdl.close() 668 | commands.getoutput("vim-cmd hostsvc/net/refresh") 669 | logInstallProgress("Dumped saved DNS config to /etc/resolv.conf") 670 | else: 671 | logInstallProgress("Unable to open /etc/resolv.conf for writing") 672 | else: 673 | logInstallProgress("Unable to open /store/resolv.conf for reading") 674 | else: 675 | logInstallProgress("Unable to get esxcfg-vmknic output..exiting") 676 | except Exception,detail: 677 | TEMP_STR="logger Exception:" + str(detail) 678 | logInstallProgress(TEMP_STR) 679 | 680 | def callbackConsole(): 681 | MY_SVCTAG =commands.getoutput("esxcfg-info -w | grep -i serial | sed 's/[^a-zA-Z0-9]*\./ /g' | awk '{print \$3}'") 682 | MY_IPADDR =commands.getoutput("esxcfg-vmknic -l | grep -vi Interface | awk '{print \$5}'") 683 | logInstallProgress("Firstboot:Initial IP address is " + MY_IPADDR) 684 | ctr = 0 685 | while (MY_IPADDR == "0.0.0.0" and ctr < 5): 686 | time.sleep(60) 687 | ctr += 1 688 | MY_IPADDR =commands.getoutput("esxcfg-vmknic -l | grep -vi Interface | awk '{print \$5}'") 689 | logInstallProgress("Resolved IP address is " + MY_IPADDR) 690 | 691 | defNS="http://pg.dell.com/spectre/deploymentprogress/ws" 692 | envelope_template = """""" 693 | envelope_template += """""" 694 | envelope_template += """""" 695 | envelope_template += """""" 696 | envelope_template += """""" + MY_SVCTAG + """""" 697 | envelope_template += """""" + MY_IPADDR + """""" 698 | envelope_template += """""" 699 | envelope_template += """""" 700 | envelope_template += """""" 701 | try: 702 | envlen = len(envelope_template) 703 | _post = 'http:///Spectre/DeploymentProgressService' 704 | _host = '' 705 | _port = 443 706 | logInstallProgress("Initiated connection for updatehost") 707 | http_conn = httplib.HTTPSConnection(_host,_port) 708 | http_conn.putrequest('POST', _post) 709 | http_conn.putheader('Host', _host) 710 | http_conn.putheader('Content-Type', 'text/xml; charset="utf-8"') 711 | http_conn.putheader('Content-Length', str(envlen)) 712 | http_conn.putheader('SOAPAction', 'http://pg.dell.com/spectre/deploymentprogress/ws/UpdateHostDetails') 713 | http_conn.endheaders() 714 | http_conn.send(envelope_template) 715 | httpresponse = http_conn.getresponse() 716 | response = httpresponse.read() 717 | http_conn.close() 718 | idResponseBlob = parseString(response) 719 | logInstallProgress(idResponseBlob.toprettyxml()) 720 | updateResponseNode = idResponseBlob.getElementsByTagNameNS(defNS,'UpdateHostDetailsResponse') 721 | if (updateResponseNode == None or updateResponseNode.length <= 0): 722 | logInstallProgress("No update response node in ack from console...potential fault") 723 | idResponseBlob.unlink() 724 | return False 725 | else: 726 | logInstallProgress("Found update response node in ack from console...Exiting") 727 | idResponseBlob.unlink() 728 | return True 729 | except Exception,detail: 730 | TEMP_STR="logger Exception:" + str(detail) 731 | logInstallProgress(TEMP_STR) 732 | return False 733 | 734 | CMD_STATUS = 256 735 | (CMD_STATUS,OP) = commands.getstatusoutput("esxupdate query") 736 | if (CMD_STATUS == 0): 737 | if (string.find(OP,"OpenManage") != -1 or string.find(OP,"Dell-Configuration-VIB") != -1): 738 | ackRecvd = False 739 | ctr = 0 740 | configureDNSOnESXi() 741 | while (ctr < 4 and ackRecvd == False): 742 | ctr += 1 743 | ackRecvd = callbackConsole() 744 | time.sleep(30) 745 | else: 746 | logInstallProgress("OMSA VIB not installed..not calling console") 747 | else: 748 | logInstallProgress("Unable to determine if OMSA is installed") 749 | EOF2 750 | 751 | cat > /store/oemProviderEnabled.py < 0): 759 | currTime = time.strftime("%d %b %y %H:%M:%S",time.gmtime()) 760 | TEMP_STR = currTime + " " + progressData + "\n" 761 | print TEMP_STR 762 | logFile.write(TEMP_STR) 763 | logFile.close() 764 | except Exception,detail: 765 | TEMP_CMD="logger Exception:" + str(detail) 766 | print TEMP_CMD 767 | 768 | def isConfigureOEMProvider(): 769 | try: 770 | logInstallProgress("In isConfigureOEMProvider") 771 | tempStatus = 256 772 | tempCmdOut = "" 773 | (tempStatus, tempCmdOut) = commands.getstatusoutput("esxcfg-advcfg -l | grep -i UserVars/CIMoem") 774 | if (tempStatus == 0): 775 | tempStatus = 256 776 | varList = tempCmdOut.split("\n") 777 | if (varList != None): 778 | for var in varList: 779 | tempVars = var.split("[") 780 | if (tempVars != None and tempVars[0] != None): 781 | strVar = str(tempVars[0]).strip() 782 | tempStatus = 256 783 | tempCmdOut = "" 784 | (tempStatus, tempCmdOut) = commands.getstatusoutput("esxcfg-advcfg -s 1 " + strVar) 785 | logInstallProgress("CIMoemProvider variable is: " + strVar) 786 | else: 787 | pass 788 | else: 789 | pass 790 | else: 791 | pass 792 | 793 | logInstallProgress("CIMoemProviderEnabled:status is " + tempCmdOut) 794 | return tempCmdOut 795 | except Exception,detail: 796 | TEMP_CMD="logger Exception:" + str(detail) 797 | logInstallProgress(TEMP_CMD) 798 | return "" 799 | 800 | def enableoemProviderEnabledAndDuplicateImageDetection(): 801 | MY_SVCTAG =commands.getoutput("esxcfg-info -w | grep -i serial | sed 's/[^a-zA-Z0-9]*\./ /g' | awk '{print \$3}'") 802 | MY_IPADDR =commands.getoutput("esxcfg-vmknic -l | grep -vi Interface | awk '{print \$5}'") 803 | logInstallProgress("CIMoemProviderEnabled:Initial IP address is " + MY_IPADDR) 804 | ctr = 0 805 | while (MY_IPADDR == "0.0.0.0" and ctr < 5): 806 | time.sleep(60) 807 | ctr += 1 808 | MY_IPADDR =commands.getoutput("esxcfg-vmknic -l | grep -vi Interface | awk '{print \$5}'") 809 | logInstallProgress("Resolved IP address is " + MY_IPADDR) 810 | MY_COMMAND = isConfigureOEMProvider() 811 | logInstallProgress("CIMoemProviderEnabled:status is " + MY_COMMAND) 812 | MY_COMMAND = commands.getoutput("esxcfg-advcfg -k TRUE overrideDuplicateImageDetection") 813 | logInstallProgress("overrideDuplicateImageDetection is " + MY_COMMAND) 814 | MY_COMMAND =commands.getoutput("esxcfg-advcfg -j overrideDuplicateImageDetection") 815 | logInstallProgress("overrideDuplicateImageDetection is " + MY_COMMAND) 816 | 817 | enableoemProviderEnabledAndDuplicateImageDetection() 818 | EOFG 819 | 820 | cp /etc/rc.local /store/rc.local.orig 821 | cp /etc/rc.local /store/rc.local.bak 822 | 823 | echo "export PYTHONHOME=$PYTHONHOME" >> /store/rc.local.bak 824 | echo "export PYTHONPATH=$PYTHONPATH" >> /store/rc.local.bak 825 | cat >> /store/rc.local.bak <&1 828 | echo "firstboot is executed" 829 | sleep 30s 830 | rm -f /store/installomsa.py 831 | rm -f /store/firstboot.py 832 | rm -f /store/oemProviderEnabled.py 833 | mv -f /store/rc.local.orig /etc/rc.local 834 | /sbin/auto-backup.sh 835 | EOF4 836 | 837 | echo "export PYTHONHOME=$PYTHONHOME" >> /etc/rc.local 838 | echo "export PYTHONPATH=$PYTHONPATH" >> /etc/rc.local 839 | cat >> /etc/rc.local <&1 842 | echo "CIMoemProviderEnabled is executed" 843 | sleep 30s 844 | mv -f /store/rc.local.bak /etc/rc.local 845 | /sbin/auto-backup.sh 846 | reboot 847 | EOFR 848 | 849 | echo "Backing up system settings...." 850 | /sbin/auto-backup.sh 851 | %firstboot --unsupported --interpreter=busybox --level=9999 852 | python /store/installomsa.py 853 | echo "Completed OMSA install" 854 | sleep 30s 855 | reboot 856 | -------------------------------------------------------------------------------- /src/main/resources/deployment/ksESXI5.cfg: -------------------------------------------------------------------------------- 1 | vmaccepteula 2 | %include /tmp/rootpw.cfg 3 | reboot 4 | %pre --interpreter=busybox 5 | cat >/tmp/daemon.py << EOF1 6 | import sys, os, time, atexit,commands 7 | from signal import SIGTERM 8 | class Daemon: 9 | def __init__(self, pidfile, stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'): 10 | self.stdin = stdin 11 | self.stdout = stdout 12 | self.stderr = stderr 13 | self.pidfile = pidfile 14 | 15 | def daemonize(self): 16 | try: 17 | pid = os.fork() 18 | if pid > 0: 19 | # exit first parent 20 | sys.exit(0) 21 | except OSError, e: 22 | sys.stderr.write("fork #1 failed: %d (%s)\n" % (e.errno, e.strerror)) 23 | sys.exit(1) 24 | 25 | # decouple from parent environment 26 | os.chdir("/") 27 | os.setsid() 28 | os.umask(0) 29 | 30 | # do second fork 31 | try: 32 | pid = os.fork() 33 | if pid > 0: 34 | # exit from second parent 35 | sys.exit(0) 36 | except OSError, e: 37 | sys.stderr.write("fork #2 failed: %d (%s)\n" % (e.errno, e.strerror)) 38 | sys.exit(1) 39 | 40 | # redirect standard file descriptors 41 | sys.stdout.flush() 42 | sys.stderr.flush() 43 | si = file(self.stdin, 'r') 44 | so = file(self.stdout, 'a+') 45 | se = file(self.stderr, 'a+', 0) 46 | os.dup2(si.fileno(), sys.stdin.fileno()) 47 | os.dup2(so.fileno(), sys.stdout.fileno()) 48 | os.dup2(se.fileno(), sys.stderr.fileno()) 49 | 50 | # write pidfile 51 | atexit.register(self.delpid) 52 | pid = str(os.getpid()) 53 | file(self.pidfile,'w+').write("%s\n" % pid) 54 | 55 | def delpid(self): 56 | os.remove(self.pidfile) 57 | 58 | def start(self): 59 | # Check for a pidfile to see if the daemon already runs 60 | try: 61 | pf = file(self.pidfile,'r') 62 | pid = int(pf.read().strip()) 63 | pf.close() 64 | except IOError: 65 | pid = None 66 | 67 | if pid: 68 | message = "pidfile %s already exist. Daemon already running?\n" 69 | sys.stderr.write(message % self.pidfile) 70 | sys.exit(1) 71 | 72 | # Start the daemon 73 | self.daemonize() 74 | self.run() 75 | 76 | def stop(self): 77 | # Get the pid from the pidfile 78 | try: 79 | pf = file(self.pidfile,'r') 80 | pid = int(pf.read().strip()) 81 | pf.close() 82 | except IOError: 83 | pid = None 84 | 85 | if not pid: 86 | message = "pidfile %s does not exist. Daemon not running?\n" 87 | sys.stderr.write(message % self.pidfile) 88 | return # not an error in a restart 89 | 90 | # Try killing the daemon process 91 | try: 92 | MY_OP="" 93 | CTR = 0 94 | while CTR < 10: 95 | CTR += 1 96 | TEMP_CMD="kill -9 " + str(pid) 97 | MY_OP = commands.getoutput(TEMP_CMD) 98 | if (MY_OP.find("No such process")) > 0: 99 | if os.path.exists(self.pidfile): 100 | os.remove(self.pidfile) 101 | time.sleep(2) 102 | except OSError, err: 103 | err = str(err) 104 | if err.find("No such process") > 0: 105 | if os.path.exists(self.pidfile): 106 | os.remove(self.pidfile) 107 | else: 108 | print str(err) 109 | sys.exit(1) 110 | 111 | def restart(self): 112 | self.stop() 113 | self.start() 114 | 115 | def run(self): 116 | message = "hello there..." 117 | EOF1 118 | cat >/tmp/runDaemon.py << EOF2 119 | import sys, time, httplib, string, commands 120 | from xml.dom.minidom import parseString 121 | from daemon import Daemon 122 | class MyDaemon(Daemon): 123 | def run(self): 124 | MY_SVCTAG =commands.getoutput("esxcfg-info -w | grep -i 'serial number' | sed 's/[^a-zA-Z0-9]*\./ /g' | awk '{printf \$3}'") 125 | ERR_MSG = [] 126 | ERR_MSG_STR = '' 127 | ERR_CODE = '267195' 128 | CTR = 0 129 | errorFound = False 130 | while (CTR < 40 and errorFound == False): 131 | time.sleep(30) 132 | CTR += 1 133 | f=open('/var/log/esxi_install.log','r') 134 | if (f): 135 | LINES = f.readlines() 136 | f.close() 137 | for i in range(len(LINES)): 138 | if ((string.find(LINES[i],"ERROR") != -1) and (string.find(LINES[i],"DEBUG") == -1)): 139 | TEMP_STR = LINES[i].rstrip('\n') 140 | ERR_MSG.append(TEMP_STR) 141 | errorFound = True 142 | if (len(ERR_MSG) > 0): 143 | for MSG in ERR_MSG: 144 | ERR_MSG_STR += MSG 145 | 146 | if (len(MY_SVCTAG) == 7 and len(ERR_MSG_STR) > 0): 147 | defNS="http://pg.dell.com/spectre/deploymentprogress/ws" 148 | envelope_template = """""" 149 | envelope_template += """""" 150 | envelope_template += """""" 151 | envelope_template += """""" 152 | envelope_template += """""" + MY_SVCTAG + """""" 153 | envelope_template += """""" + ERR_CODE + """""" 154 | envelope_template += """""" + ERR_MSG_STR + """""" 155 | envelope_template += """""" 156 | envelope_template += """""" 157 | envelope_template += """""" 158 | try: 159 | envlen = len(envelope_template) 160 | _post = 'http:///Spectre/DeploymentProgressService' 161 | _host = '' 162 | _port = 443 163 | http_conn = httplib.HTTPSConnection(_host,_port) 164 | http_conn.putrequest('POST', _post) 165 | http_conn.putheader('Host', _host) 166 | http_conn.putheader('Content-Type', 'text/xml; charset="utf-8"') 167 | http_conn.putheader('Content-Length', str(envlen)) 168 | http_conn.putheader('SOAPAction', 'http://pg.dell.com/spectre/deploymentprogress/ws/SetInstallationError') 169 | http_conn.endheaders() 170 | http_conn.send(envelope_template) 171 | httpresponse = http_conn.getresponse() 172 | response = httpresponse.read() 173 | http_conn.close() 174 | idResponseBlob = parseString(response) 175 | idResponseBlob.unlink() 176 | daemon.stop() 177 | except Exception,detail: 178 | TEMP_STR="logger Exception:" + str(detail) 179 | print TEMP_STR 180 | daemon.stop() 181 | 182 | if __name__ == "__main__": 183 | daemon = MyDaemon('/tmp/daemon-example.pid') 184 | if len(sys.argv) == 2: 185 | if 'start' == sys.argv[1]: 186 | daemon.start() 187 | elif 'stop' == sys.argv[1]: 188 | daemon.stop() 189 | elif 'restart' == sys.argv[1]: 190 | daemon.restart() 191 | else: 192 | print "Unknown command" 193 | #sys.exit(2) 194 | sys.exit(0) 195 | else: 196 | print "usage: %s start|stop|restart" % sys.argv[0] 197 | EOF2 198 | cat > /tmp/getIdentity.py <""" 239 | envelope_template += """""" 240 | envelope_template += """""" 241 | envelope_template += """""" 242 | envelope_template += """""" + MY_SVCTAG + """""" 243 | envelope_template += """""" + MY_MAC + """""" 244 | envelope_template += """""" 245 | envelope_template += """""" 246 | envelope_template += """""" 247 | try: 248 | envlen = len(envelope_template) 249 | _post = 'http:///Spectre/DeploymentProgressService' 250 | _host = '' 251 | _port = 443 252 | http_conn = httplib.HTTPSConnection(_host,_port) 253 | http_conn.putrequest('POST', _post) 254 | http_conn.putheader('Host', _host) 255 | http_conn.putheader('Content-Type', 'text/xml; charset="utf-8"') 256 | http_conn.putheader('Content-Length', str(envlen)) 257 | http_conn.putheader('SOAPAction', 'http://pg.dell.com/spectre/deploymentprogress/ws/GetIdentity') 258 | http_conn.endheaders() 259 | http_conn.send(envelope_template) 260 | httpresponse = http_conn.getresponse() 261 | response = httpresponse.read() 262 | http_conn.close() 263 | idResponseBlob = parseString(response) 264 | serverDetailsNodeList = idResponseBlob.getElementsByTagNameNS(defNS,'ServerDetails') 265 | if (serverDetailsNodeList == None or serverDetailsNodeList.length <= 0): 266 | print "ERROR: Unable to get server detail info from Dell Plugin" 267 | else: 268 | for serverDetailsNode in serverDetailsNodeList.item(0).childNodes: 269 | if (serverDetailsNode and serverDetailsNode.hasChildNodes()): 270 | tempNodeVal = serverDetailsNode.childNodes.item(0).nodeValue 271 | if (serverDetailsNode.localName == "password" and tempNodeVal != None): 272 | ksOutput += "rootpw --iscrypted " + tempNodeVal + "\n" 273 | elif (serverDetailsNode.localName == "NetworkDetails"): 274 | networkDetailsChildren = serverDetailsNode.childNodes 275 | if (networkDetailsChildren and networkDetailsChildren.length > 0): 276 | for networkDetailNode in networkDetailsChildren: 277 | tempNodeName = networkDetailNode.localName 278 | if (networkDetailNode.hasChildNodes()): 279 | tempNodeVal = networkDetailNode.childNodes.item(0).nodeValue 280 | if (tempNodeVal != None): 281 | if (tempNodeName == "ipAddress" and tempNodeVal !=None): 282 | ipAddrToken = tempNodeVal 283 | useStaticIP = True 284 | if (tempNodeName == "macAddress" and tempNodeVal != None): 285 | macAddrToken = tempNodeVal 286 | if (tempNodeName == "vLanId" and tempNodeVal != None and tempNodeVal != "-1"): 287 | vlanidToken = tempNodeVal 288 | if (useStaticIP == False): 289 | ksOutput += "network --bootproto=dhcp" 290 | if (macAddrToken and len(macAddrToken) > 0): 291 | ksOutput += " --device=" + macAddrToken 292 | if (vlanidToken and len(vlanidToken) > 0): 293 | ksOutput += " --vlanid=" + vlanidToken 294 | ksOutput += "\n" 295 | else: 296 | ksOutput += "network --bootproto=static" 297 | if (vlanidToken and len(vlanidToken) > 0): 298 | ksOutput += " --vlanid=" + vlanidToken 299 | if (ipAddrToken and len(ipAddrToken) > 0): 300 | ksOutput += " --ip=" + ipAddrToken 301 | if (macAddrToken and len(macAddrToken) > 0): 302 | ksOutput += " --device=" + macAddrToken 303 | for networkDetailNode in networkDetailsChildren: 304 | tempNodeName = networkDetailNode.localName 305 | if (networkDetailNode.hasChildNodes()): 306 | tempNodeVal = networkDetailNode.childNodes.item(0).nodeValue 307 | if (tempNodeVal != None): 308 | if (tempNodeName == "defaultGateway"): 309 | ksOutput += " --gateway=" + tempNodeVal 310 | if (tempNodeName == "subnetMask"): 311 | ksOutput += " --netmask=" + tempNodeVal 312 | if (tempNodeName == "preferredDns"): 313 | dnsServers = tempNodeVal 314 | if (tempNodeName == "alternateDns"): 315 | dnsServers += "," + tempNodeVal 316 | if (tempNodeName == "hostName"): 317 | ksOutput += " --hostname=" + tempNodeVal 318 | if (dnsServers and len(dnsServers) > 0): 319 | ksOutput += " --nameserver=" + dnsServers 320 | ksOutput += "\n" 321 | else: 322 | commands.getoutput("logger Unable to derive network details") 323 | else: 324 | continue 325 | #Clean up response from soap request and return output to write 326 | #into the kickstart include 327 | idResponseBlob.unlink() 328 | except Exception,detail: 329 | TEMP_CMD="logger Exception:" + str(detail) 330 | print TEMP_CMD 331 | 332 | return ksOutput 333 | 334 | def getVirtualDiskInfo(): 335 | ksOutput = "" 336 | try: 337 | # Run and parse the first available virtual disk 338 | cmdStatus = 256 339 | cmdOutput = None 340 | tmpCmd = "esxcfg-scsidevs -l > /tmp/diskResponse.txt" 341 | (status, cmdoutput) = commands.getstatusoutput(tmpCmd) 342 | if (status != 0): 343 | ksOutput += "clearpart --firstdisk --overwritevmfs" 344 | ksOutput += "\n" 345 | ksOutput += "install --firstdisk --overwritevmfs" 346 | ksOutput += "\n" 347 | else: 348 | devfsStr = ".*Devfs Path:*" 349 | virtualDiskStr = ".*Model: Virtual Disk*" 350 | devfsExp = re.compile(devfsStr, re.IGNORECASE) 351 | virtualDiskExp = re.compile(virtualDiskStr, re.IGNORECASE) 352 | isOpSuccess = 0 353 | matchObj = None 354 | devFsPath = [] 355 | displayLines = [] 356 | opFileHdl = open('/tmp/diskResponse.txt', 'r') 357 | if (opFileHdl): 358 | displayLines = opFileHdl.readlines() 359 | opFileHdl.close() 360 | if (displayLines and len(displayLines) > 0): 361 | for line in displayLines: 362 | matchObj = devfsExp.match(line) 363 | if (matchObj): 364 | devFsPath = None 365 | devFsPath = line.split(':') 366 | continue 367 | matchObj = virtualDiskExp.match(line) 368 | if (matchObj): 369 | if (devFsPath and len(devFsPath) > 1): 370 | isOpSuccess = 1 371 | break; 372 | if(isOpSuccess == 1): 373 | ksOutput += "clearpart --drives=" + devFsPath[1].strip() + " --overwritevmfs" 374 | ksOutput += "\n" 375 | ksOutput += "install --drive=" + devFsPath[1].strip() + " --overwritevmfs" 376 | ksOutput += "\n" 377 | else: 378 | ksOutput += "clearpart --firstdisk --overwritevmfs" 379 | ksOutput += "\n" 380 | ksOutput += "install --firstdisk --overwritevmfs" 381 | ksOutput += "\n" 382 | except Exception,detail: 383 | TEMP_CMD="logger Exception:" + str(detail) 384 | print TEMP_CMD 385 | 386 | return ksOutput 387 | 388 | def parseRipsDiskData(): 389 | diskObjects = [] 390 | try: 391 | xmlBlob = None 392 | status = 256 393 | OUTPUTSTR = "" 394 | (status,OUTPUTSTR) = commands.getstatusoutput("esxcfg-info -s -F xml > /tmp/storageinfo.xml") 395 | if (status == 0): 396 | xmlBlob = parse('/tmp/storageinfo.xml') 397 | 398 | if (xmlBlob): 399 | lunNodes = xmlBlob.getElementsByTagName('lun') 400 | if (lunNodes != None and lunNodes.length > 0): 401 | numChildNodes = lunNodes.length 402 | for ctr in range(numChildNodes): 403 | diskObj = DiskObject() 404 | lunChildNodes = lunNodes[ctr] 405 | if (lunChildNodes.hasChildNodes()): 406 | for lunChild in lunChildNodes.childNodes: 407 | if (lunChild != None and lunChild.attributes != None): 408 | if "name" in lunChild.attributes.keys(): 409 | model = None 410 | size = None 411 | devPath = None 412 | tempVal = None; 413 | attrInst = lunChild.attributes["name"] 414 | if (lunChild.hasChildNodes()): 415 | tempVal = lunChild.firstChild.nodeValue 416 | else: 417 | tempVal = lunChild.nodeValue 418 | if attrInst.value.lower() == "vendor": 419 | diskObj.vendor = tempVal 420 | if attrInst.value.lower() == "model": 421 | diskObj.model = tempVal 422 | if attrInst.value.lower() == "size": 423 | diskObj.size = tempVal 424 | if attrInst.value.lower() == "name": 425 | diskObj.diskPath = tempVal 426 | diskObjects.append(diskObj); 427 | except Exception,detail: 428 | TEMP_CMD="logger Exception:" + str(detail) 429 | print TEMP_CMD 430 | 431 | return diskObjects 432 | 433 | def getRipsObject(): 434 | ripsDisk = None 435 | retDisk = None 436 | diskList = parseRipsDiskData() 437 | if (diskList != None and len(diskList) > 0): 438 | for ripsDisk in diskList: 439 | if ( (ripsDisk.model.lower() == "internal dual sd") or (ripsDisk.model.lower() == "idsdm") ): 440 | retDisk = ripsDisk 441 | break 442 | return retDisk 443 | 444 | def getDiskInfo(): 445 | installCondition = "" 446 | ripsDisk = None 447 | ksOutput = "" 448 | try: 449 | if (installCondition == "sd_only" or installCondition == "first_sd_then_hd"): 450 | ripsDisk = getRipsObject() 451 | if (ripsDisk != None): 452 | ksOutput = "clearpart --drives=" + ripsDisk.diskPath + " --overwritevmfs\n" 453 | ksOutput += "install --drive=" + ripsDisk.diskPath + " --overwritevmfs --novmfsondisk\n" 454 | else: 455 | if (installCondition == "sd_only"): 456 | TEMP_STR = "Unable to find SD card...Error" 457 | logInstallProgress(TEMP_STR) 458 | reportErrors("267179") 459 | else: 460 | ksOutput = getVirtualDiskInfo() 461 | TEMP_STR = "Unable to find SD card, now installing to HD...Warning" 462 | logInstallProgress(TEMP_STR) 463 | else: 464 | ksOutput = getVirtualDiskInfo() 465 | except Exception,detail: 466 | TEMP_CMD="logger Exception:" + str(detail) 467 | print TEMP_CMD 468 | return ksOutput 469 | 470 | # Get network and disk information into 471 | # the file included by kickstart 472 | rootPwOut = getNetworkInfo() 473 | rootPwOut += getDiskInfo() 474 | writeIncludeOutput() 475 | EOF3 476 | python /tmp/runDaemon.py start 477 | python /tmp/getIdentity.py 478 | %post --interpreter=busybox 479 | python /tmp/runDaemon.py stop 480 | %firstboot --interpreter=python 481 | import urllib,commands,os,time,string 482 | from stat import ST_SIZE 483 | from xml.dom.minidom import parseString 484 | CMD_STATUS = 256 485 | OMSA_NAME = "" 486 | (CMD_STATUS, CMD_OUT) = commands.getstatusoutput("vmware -l") 487 | if (CMD_STATUS == 0 and CMD_OUT != None and ("esxi 5.0.0") in CMD_OUT.lower()): 488 | OMSA_NAME = "omsa_esxi50_vib.zip" 489 | elif (CMD_STATUS == 0 and CMD_OUT != None and ("esxi 5.1.0") in CMD_OUT.lower()): 490 | OMSA_NAME = "omsa_esxi51_vib.zip" 491 | elif (CMD_STATUS == 0 and CMD_OUT != None and ("esxi 5.5.0 update 1") in CMD_OUT.lower()): 492 | OMSA_NAME = "" 493 | elif (CMD_STATUS == 0 and CMD_OUT != None and ("esxi 5.5.0 update 2") in CMD_OUT.lower()): 494 | OMSA_NAME = "" 495 | elif (CMD_STATUS == 0 and CMD_OUT != None and ("esxi 5.5.0") in CMD_OUT.lower()): 496 | OMSA_NAME = "omsa_esxi55_vib.zip" 497 | else: 498 | OMSA_NAME = "omsa_esxi55_vib.zip" 499 | 500 | MY_ESXI_URL = "https:///omsa/" + OMSA_NAME 501 | CMD_STATUS = 256 502 | MY_TEMP_FILE = "/tmp/" + OMSA_NAME 503 | MY_IPADDR =commands.getoutput("esxcfg-vmknic -l | grep -vi Interface | awk '{print $5}'") 504 | ctr = 0 505 | time.sleep(60) 506 | while (MY_IPADDR == "0.0.0.0" and ctr < 5): 507 | time.sleep(20) 508 | ctr += 1 509 | MY_IPADDR =commands.getoutput("esxcfg-vmknic -l | grep -vi Interface | awk '{print $5}'") 510 | 511 | def logInstallProgress(progressData): 512 | try: 513 | logFile = open('/store/dell_postinstall.log','a') 514 | if (logFile and progressData and len(progressData) > 0): 515 | currTime = time.strftime("%d %b %y %H:%M:%S",time.gmtime()) 516 | TEMP_STR = currTime + " " + progressData + "\n" 517 | print TEMP_STR 518 | logFile.write(TEMP_STR) 519 | logFile.close() 520 | except Exception,detail: 521 | TEMP_CMD="logger Exception:" + str(detail) 522 | print TEMP_CMD 523 | 524 | def configureDNSOnESXi(): 525 | MY_VIRT_NIC = "" 526 | MY_DHCP_STR = "" 527 | STATUS = 0 528 | try: 529 | logInstallProgress("Configuring DNS on ESXi........") 530 | (STATUS, OUTPUTSTR) = commands.getstatusoutput("esxcfg-vmknic -l | grep -vi Interface") 531 | if (STATUS == 0): 532 | VMKNICARR = OUTPUTSTR.split() 533 | MY_VIRT_NIC = VMKNICARR[0] 534 | MY_DHCP_STR = VMKNICARR[11] 535 | logInstallProgress("Virtual NIC device name is " + MY_VIRT_NIC) 536 | logInstallProgress("DHCP status on system is "+MY_DHCP_STR) 537 | if (MY_DHCP_STR == "DHCP"): 538 | logInstallProgress("System is set with DHCP ..configuring DNS") 539 | TEMP_STR = "vim-cmd hostsvc/net/dns_set --dhcp=true --dhcp-virtualnic=" + MY_VIRT_NIC 540 | (STATUS,OUTPUTSTR) = commands.getstatusoutput(TEMP_STR) 541 | if (STATUS == 0): 542 | logInstallProgress("Successfully set dns entries") 543 | commands.getoutput("vim-cmd hostsvc/net/refresh") 544 | else: 545 | logInstallProgress("Unable to set DNS entries") 546 | else: 547 | logInstallProgress("System configured for static IP..Extracting resolv.conf settings") 548 | fileHdl = open('/etc/resolv.conf','r') 549 | if (fileHdl): 550 | resolvFileLines = fileHdl.readlines() 551 | fileHdl.close() 552 | opFileHdl = open('/store/resolv.conf','w') 553 | if (opFileHdl): 554 | resolveFileContents = ''.join(resolvFileLines) 555 | opFileHdl.write(resolveFileContents) 556 | opFileHdl.close() 557 | logInstallProgress("Dumped DNS settings to /store/resolv.conf") 558 | else: 559 | logInstallProgress("Unable to open /store/resolv.conf for writing") 560 | else: 561 | logInstallProgress("Unable to open /etc/resolv.conf for reading") 562 | else: 563 | logInstallProgress("Unable to get esxcfg-vmknic output..exiting") 564 | except Exception,detail: 565 | TEMP_CMD="logger Exception:" + str(detail) 566 | print TEMP_CMD 567 | 568 | def configureOmsaOnESXi(): 569 | snmpOutput = "" 570 | snmpFileLines = [] 571 | try: 572 | fileHdl = open('/etc/vmware/snmp.xml','r') 573 | if (fileHdl): 574 | snmpFileLines = fileHdl.readlines() 575 | fileHdl.close() 576 | else: 577 | logInstallProgress("Unable to open snmp.xml file for parsing...Exiting") 578 | return 579 | snmpFileStr = ''.join(snmpFileLines) 580 | if (snmpFileStr and len(snmpFileStr) > 0): 581 | idResponseBlob = parseString(snmpFileStr) 582 | else: 583 | logInstallProgress("Unable to parse snmp config file ...Exiting") 584 | return 585 | if (idResponseBlob): 586 | configNodeList = idResponseBlob.getElementsByTagName('config') 587 | if (configNodeList and configNodeList.length > 0): 588 | for configNodes in configNodeList.item(0).childNodes: 589 | if (configNodes.localName == "snmpSettings"): 590 | snmpSettingsChildren = configNodes.childNodes 591 | if (snmpSettingsChildren and snmpSettingsChildren.length > 0): 592 | for snmpSetting in snmpSettingsChildren: 593 | tempNode = snmpSetting.localName 594 | if (tempNode == "enable"): 595 | if (snmpSetting.hasChildNodes()): 596 | snmpSetting.childNodes.item(0).nodeValue = "true" 597 | if (tempNode == "communities"): 598 | if (snmpSetting.hasChildNodes()): 599 | if (snmpSetting.childNodes.item(0).nodeValue and snmpSetting.childNodes.item(0).nodeValue != "public"): 600 | snmpSetting.childNodes.item(0).nodeValue += ",public" 601 | else: 602 | tempTextNode = idResponseBlob.createTextNode("public") 603 | snmpSetting.appendChild(tempTextNode) 604 | if (tempNode == "targets"): 605 | if (snmpSetting.hasChildNodes()): 606 | if (snmpSetting.childNodes.item(0).nodeValue): 607 | snmpSetting.childNodes.item(0).nodeValue += ", public" 608 | else: 609 | tempTextNode = idResponseBlob.createTextNode(" public") 610 | snmpSetting.appendChild(tempTextNode) 611 | else: 612 | pass 613 | snmpOutput = idResponseBlob.toxml() 614 | snmpOutput = string.replace(snmpOutput,"","") 615 | fileHdl = open('/etc/vmware/snmp.xml', 'w') 616 | if (fileHdl): 617 | fileHdl.write(snmpOutput) 618 | logInstallProgress("SNMP trap configuration completed successfully") 619 | fileHdl.close() 620 | idResponseBlob.unlink() 621 | except Exception,detail: 622 | TEMP_CMD="logger Exception:" + str(detail) 623 | logInstallProgress(TEMP_CMD) 624 | 625 | configureDNSOnESXi() 626 | logInstallProgress("Downloading OMSA VIB for ESXI 5") 627 | urllib.urlretrieve(MY_ESXI_URL, MY_TEMP_FILE) 628 | logInstallProgress("Completed download of OMSA VIB for ESXI 5 under: " + MY_TEMP_FILE) 629 | if (os.path.exists(MY_TEMP_FILE)): 630 | fileSize = os.stat(MY_TEMP_FILE)[ST_SIZE] 631 | if (fileSize > 32768): 632 | logInstallProgress("Configuring OMSA trap destination") 633 | configureOmsaOnESXi() 634 | else: 635 | if (len(OMSA_NAME) == 0): 636 | TEMP_STR="OMSA support not available for this hypervisor..Error" 637 | logInstallProgress(TEMP_STR) 638 | reportErrors("267232") 639 | else: 640 | TEMP_STR="Unable to use downloaded file for install..Error" 641 | logInstallProgress(TEMP_STR) 642 | reportErrors("267182") 643 | 644 | %firstboot --interpreter=busybox 645 | cat > /store/installomsa.py < 0): 674 | currTime = time.strftime("%d %b %y %H:%M:%S",time.gmtime()) 675 | TEMP_STR = currTime + " " + progressData + "\n" 676 | print TEMP_STR 677 | logFile.write(TEMP_STR) 678 | logFile.close() 679 | except Exception,detail: 680 | TEMP_CMD="logger Exception:" + str(detail) 681 | print TEMP_CMD 682 | 683 | def reportErrors(ERR_MSG_STR): 684 | MY_SVCTAG =commands.getoutput("esxcfg-info -w | grep -i 'serial number' | sed 's/[^a-zA-Z0-9]*\./ /g' | awk '{printf \$3}'") 685 | ERR_DTL = '' 686 | if (len(MY_SVCTAG) == 7 and len(ERR_MSG_STR) > 0): 687 | defNS="http://pg.dell.com/spectre/deploymentprogress/ws" 688 | envelope_template = """""" 689 | envelope_template += """""" 690 | envelope_template += """""" 691 | envelope_template += """""" 692 | envelope_template += """""" + MY_SVCTAG + """""" 693 | envelope_template += """""" + ERR_MSG_STR + """""" 694 | envelope_template += """""" + ERR_DTL + """""" 695 | envelope_template += """""" 696 | envelope_template += """""" 697 | envelope_template += """""" 698 | try: 699 | envlen = len(envelope_template) 700 | _post = 'http:///Spectre/DeploymentProgressService' 701 | _host = '' 702 | _port = 443 703 | http_conn = httplib.HTTPSConnection(_host,_port) 704 | http_conn.putrequest('POST', _post) 705 | http_conn.putheader('Host', _host) 706 | http_conn.putheader('Content-Type', 'text/xml; charset="utf-8"') 707 | http_conn.putheader('Content-Length', str(envlen)) 708 | http_conn.putheader('SOAPAction', 'http://pg.dell.com/spectre/deploymentprogress/ws/SetInstallationError') 709 | http_conn.endheaders() 710 | http_conn.send(envelope_template) 711 | httpresponse = http_conn.getresponse() 712 | response = httpresponse.read() 713 | http_conn.close() 714 | idResponseBlob = parseString(response) 715 | idResponseBlob.unlink() 716 | except Exception,detail: 717 | TEMP_STR="logger Exception:" + str(detail) 718 | logInstallProgress(TEMP_STR) 719 | 720 | try: 721 | if (os.path.exists(MY_TEMP_FILE)): 722 | fileSize = os.stat(MY_TEMP_FILE)[ST_SIZE] 723 | if (fileSize > 32768): 724 | logInstallProgress("Installing OMSA vib for ESXi 5") 725 | (CMD_STATUS,OP) = commands.getstatusoutput(MY_UPDATE_CMD) 726 | logInstallProgress(OP) 727 | if (CMD_STATUS == 0): 728 | logInstallProgress("OMSA vib installed successfully.") 729 | else: 730 | TEMP_STR = "Unable to install OMSA...Error" 731 | logInstallProgress(TEMP_STR) 732 | reportErrors("267184") 733 | else: 734 | if (len(OMSA_NAME) == 0): 735 | TEMP_STR="OMSA support not available for this hypervisor..Error" 736 | logInstallProgress(TEMP_STR) 737 | reportErrors("267232") 738 | else: 739 | TEMP_STR="Unable to use downloaded file for install..Error" 740 | logInstallProgress(TEMP_STR) 741 | reportErrors("267182") 742 | else: 743 | TEMP_STR="File not downloaded or no permissions to write to /tmp..Exiting" 744 | logInstallProgress(TEMP_STR) 745 | reportErrors("267183") 746 | except Exception,detail: 747 | TEMP_STR="logger Exception:" + str(detail) 748 | logInstallProgress(TEMP_STR) 749 | EOF1 750 | 751 | cat > /store/firstboot.py < 0): 759 | currTime = time.strftime("%d %b %y %H:%M:%S",time.gmtime()) 760 | TEMP_STR = currTime + " " + progressData + "\n" 761 | print TEMP_STR 762 | logFile.write(TEMP_STR) 763 | logFile.close() 764 | except Exception,detail: 765 | TEMP_CMD="logger Exception:" + str(detail) 766 | print TEMP_CMD 767 | 768 | def configureDNSOnESXi(): 769 | MY_VIRT_NIC = "" 770 | MY_DHCP_STR = "" 771 | STATUS = 0 772 | try: 773 | logInstallProgress("Configuring DNS on ESXi........") 774 | (STATUS, OUTPUTSTR) = commands.getstatusoutput("esxcfg-vmknic -l | grep -vi Interface") 775 | if (STATUS == 0): 776 | VMKNICARR = OUTPUTSTR.split() 777 | MY_VIRT_NIC = VMKNICARR[0] 778 | MY_DHCP_STR = VMKNICARR[11] 779 | logInstallProgress("Virtual NIC device name is " + MY_VIRT_NIC) 780 | logInstallProgress("DHCP status on system is "+MY_DHCP_STR) 781 | if (MY_DHCP_STR == "DHCP"): 782 | logInstallProgress("System is set with DHCP ..configuring DNS") 783 | TEMP_STR = "vim-cmd hostsvc/net/dns_set --dhcp=true --dhcp-virtualnic=" + MY_VIRT_NIC 784 | (STATUS,OUTPUTSTR) = commands.getstatusoutput(TEMP_STR) 785 | if (STATUS == 0): 786 | logInstallProgress("Successfully set dns entries") 787 | commands.getoutput("vim-cmd hostsvc/net/refresh") 788 | else: 789 | logInstallProgress("Unable to set DNS entries") 790 | else: 791 | logInstallProgress("System configured for static IP..Extracting saved DNS config") 792 | fileHdl = open('/store/resolv.conf','r') 793 | if (fileHdl): 794 | resolvFileLines = fileHdl.readlines() 795 | logInstallProgress("Extracted saved DNS config") 796 | fileHdl.close() 797 | opFileHdl = open('/etc/resolv.conf','a') 798 | if (opFileHdl): 799 | resolveFileContents = ''.join(resolvFileLines) 800 | opFileHdl.write(resolveFileContents) 801 | opFileHdl.close() 802 | commands.getoutput("vim-cmd hostsvc/net/refresh") 803 | logInstallProgress("Dumped saved DNS config to /etc/resolv.conf") 804 | else: 805 | logInstallProgress("Unable to open /etc/resolv.conf for writing") 806 | else: 807 | logInstallProgress("Unable to open /store/resolv.conf for reading") 808 | else: 809 | logInstallProgress("Unable to get esxcfg-vmknic output..exiting") 810 | except Exception,detail: 811 | TEMP_STR="logger Exception:" + str(detail) 812 | logInstallProgress(TEMP_STR) 813 | 814 | def callbackConsole(): 815 | MY_SVCTAG =commands.getoutput("esxcfg-info -w | grep -i 'serial number' | sed 's/[^a-zA-Z0-9]*\./ /g' | awk '{printf \$3}'") 816 | MY_IPADDR =commands.getoutput("esxcfg-vmknic -l | grep -i IPv4 | awk '{print \$5}'") 817 | logInstallProgress("Firstboot:Initial IP address is " + MY_IPADDR) 818 | ctr = 0 819 | while (MY_IPADDR == "0.0.0.0" and ctr < 5): 820 | time.sleep(60) 821 | ctr += 1 822 | MY_IPADDR =commands.getoutput("esxcfg-vmknic -l | grep -i IPv4 | awk '{print \$5}'") 823 | logInstallProgress("Resolved IP address is " + MY_IPADDR) 824 | 825 | MY_COMMAND =commands.getoutput("esxcfg-advcfg -j overrideDuplicateImageDetection") 826 | logInstallProgress("overrideDuplicateImageDetection is " + MY_COMMAND) 827 | 828 | defNS="http://pg.dell.com/spectre/deploymentprogress/ws" 829 | envelope_template = """""" 830 | envelope_template += """""" 831 | envelope_template += """""" 832 | envelope_template += """""" 833 | envelope_template += """""" + MY_SVCTAG + """""" 834 | envelope_template += """""" + MY_IPADDR + """""" 835 | envelope_template += """""" 836 | envelope_template += """""" 837 | envelope_template += """""" 838 | try: 839 | envlen = len(envelope_template) 840 | _post = 'http:///Spectre/DeploymentProgressService' 841 | _host = '' 842 | _port = 443 843 | logInstallProgress("Initiated connection for updatehost") 844 | http_conn = httplib.HTTPSConnection(_host,_port) 845 | http_conn.putrequest('POST', _post) 846 | http_conn.putheader('Host', _host) 847 | http_conn.putheader('Content-Type', 'text/xml; charset="utf-8"') 848 | http_conn.putheader('Content-Length', str(envlen)) 849 | http_conn.putheader('SOAPAction', 'http://pg.dell.com/spectre/deploymentprogress/ws/UpdateHostDetails') 850 | http_conn.endheaders() 851 | http_conn.send(envelope_template) 852 | httpresponse = http_conn.getresponse() 853 | response = httpresponse.read() 854 | http_conn.close() 855 | idResponseBlob = parseString(response) 856 | logInstallProgress(idResponseBlob.toprettyxml()) 857 | updateResponseNode = idResponseBlob.getElementsByTagNameNS(defNS,'UpdateHostDetailsResponse') 858 | if (updateResponseNode == None or updateResponseNode.length <= 0): 859 | logInstallProgress("No update response node in ack from console...potential fault") 860 | idResponseBlob.unlink() 861 | return False 862 | else: 863 | logInstallProgress("Found update response node in ack from console...Exiting") 864 | idResponseBlob.unlink() 865 | return True 866 | except Exception,detail: 867 | TEMP_STR="logger Exception:" + str(detail) 868 | logInstallProgress(TEMP_STR) 869 | return False 870 | 871 | CMD_STATUS = 256 872 | logInstallProgress("In firstboot.py") 873 | (CMD_STATUS,OP) = commands.getstatusoutput("esxcli software vib list") 874 | logInstallProgress(CMD_STATUS) 875 | if (CMD_STATUS == 0): 876 | if (string.find(OP,"OpenManage") != -1 or string.find(OP,"Dell-Configuration-VIB") != -1): 877 | ackRecvd = False 878 | ctr = 0 879 | configureDNSOnESXi() 880 | while (ctr < 4 and ackRecvd == False): 881 | ctr += 1 882 | ackRecvd = callbackConsole() 883 | time.sleep(30) 884 | else: 885 | logInstallProgress("OMSA VIB not installed..not calling console") 886 | else: 887 | logInstallProgress("Unable to determine if OMSA is installed") 888 | EOF2 889 | 890 | cat > /store/duplicateImageDetection.py < 0): 898 | currTime = time.strftime("%d %b %y %H:%M:%S",time.gmtime()) 899 | TEMP_STR = currTime + " " + progressData + "\n" 900 | print TEMP_STR 901 | logFile.write(TEMP_STR) 902 | logFile.close() 903 | except Exception,detail: 904 | TEMP_CMD="logger Exception:" + str(detail) 905 | print TEMP_CMD 906 | 907 | def enableDuplicateImageDetection(): 908 | MY_SVCTAG =commands.getoutput("esxcfg-info -w | grep -i 'serial number' | sed 's/[^a-zA-Z0-9]*\./ /g' | awk '{print \$3}'") 909 | MY_IPADDR =commands.getoutput("esxcfg-vmknic -l | grep -vi Interface | awk '{print \$5}'") 910 | logInstallProgress("overrideDuplicateImageDetection:Initial IP address is " + MY_IPADDR) 911 | ctr = 0 912 | while (MY_IPADDR == "0.0.0.0" and ctr < 5): 913 | time.sleep(60) 914 | ctr += 1 915 | MY_IPADDR =commands.getoutput("esxcfg-vmknic -l | grep -vi Interface | awk '{print \$5}'") 916 | logInstallProgress("Resolved IP address is " + MY_IPADDR) 917 | MY_COMMAND = commands.getoutput("esxcfg-advcfg -k TRUE overrideDuplicateImageDetection") 918 | logInstallProgress("overrideDuplicateImageDetection is " + MY_COMMAND) 919 | MY_COMMAND =commands.getoutput("esxcfg-advcfg -j overrideDuplicateImageDetection") 920 | logInstallProgress("overrideDuplicateImageDetection is " + MY_COMMAND) 921 | 922 | enableDuplicateImageDetection() 923 | EOFG 924 | 925 | # ------- backkup rc.local --------------------- 926 | # files will be restored by the createRc.py 927 | 928 | chmod +wt /etc/rc.local 929 | cp /etc/rc.local /store/rc.local.orig 930 | 931 | if [ -f /etc/rc.local.d/local.sh ] 932 | then 933 | cp /etc/rc.local.d/local.sh /store/local.sh.orig 934 | fi 935 | 936 | #-------- start createRc.py ---------------------- 937 | # this section creates a file called createRc.py 938 | cat > /store/createRc.py < 0): 947 | currTime = time.strftime("%d %b %y %H:%M:%S",time.gmtime()) 948 | TEMP_STR = currTime + " " + progressData + "\n" 949 | print TEMP_STR 950 | logFile.write(TEMP_STR) 951 | logFile.close() 952 | except Exception,detail: 953 | TEMP_CMD="logger Exception:" + str(detail) 954 | print TEMP_CMD 955 | 956 | 957 | fileName="" 958 | fileMode="" 959 | CMD_STATUS = 256 960 | OMSA_NAME = "" 961 | (CMD_STATUS, CMD_OUT) = commands.getstatusoutput("vmware -l") 962 | if (CMD_STATUS == 0 and CMD_OUT != None and ( (("esxi 5.0") in CMD_OUT.lower()) or (("esxi 5.1") in CMD_OUT.lower() and ("esxi 5.1.0 update 2") not in CMD_OUT.lower()) ) ): 963 | fileName = "/etc/rc.local" 964 | fileMode = "a" 965 | else: 966 | fileName = "/etc/rc.local.d/local.sh" 967 | fileMode = "w" 968 | 969 | logInstallProgress("createRc filename=" + fileName) 970 | scriptFile = open(fileName, fileMode) 971 | 972 | (CMD_STATUS, pythonHome) = commands.getstatusoutput("echo ${PYTHONHOME:=/}") 973 | if(CMD_STATUS == 0): 974 | scriptFile.write("export PYTHONHOME=" + pythonHome + "\n") 975 | else: 976 | logInstallProgress("Failed to get python home") 977 | 978 | (CMD_STATUS, pythonPath) = commands.getstatusoutput("echo ${PYTHONPATH:=/bin}") 979 | if(CMD_STATUS == 0): 980 | scriptFile.write("export PYTHONPATH=" + pythonPath + "\n") 981 | else: 982 | logInstallProgress("Failed to get python path") 983 | 984 | 985 | logInstallProgress("createRc pythonHome=" + pythonHome) 986 | logInstallProgress("createRc pythonPath=" + pythonPath) 987 | 988 | scriptFile.write("sleep 120s\n") 989 | scriptFile.write("echo \"before firstboot\"\n") 990 | scriptFile.write("python /store/firstboot.py 2>&1\n") 991 | scriptFile.write("echo \"firstboot is executed\"\n") 992 | scriptFile.write("sleep 30s\n") 993 | scriptFile.write("rm -f /store/installomsa.py\n") 994 | scriptFile.write("rm -f /store/firstboot.py\n") 995 | scriptFile.write("rm -f /store/createRc.py\n") 996 | scriptFile.write("rm -f /store/duplicateImageDetection.py\n") 997 | 998 | 999 | if("local.sh" in fileName.lower()): 1000 | scriptFile.write("mv -f /store/local.sh.orig /etc/rc.local.d/local.sh\n") 1001 | scriptFile.write("rm -f /store/rc.local.orig\n") 1002 | scriptFile.write("/sbin/auto-backup.sh\n") 1003 | scriptFile.write("exit 0\n") 1004 | else: 1005 | scriptFile.write("mv -f /store/rc.local.orig /etc/rc.local\n") 1006 | scriptFile.write("rm -f /store/local.sh.orig\n") 1007 | scriptFile.write("/sbin/auto-backup.sh\n") 1008 | 1009 | scriptFile.close() 1010 | 1011 | logInstallProgress("Exiting createRc") 1012 | EOF3 1013 | #-------- end createRc.py ---------------------- 1014 | 1015 | echo "Modifying rc.local script....." 1016 | python /store/createRc.py 2>&1 1017 | echo "Backing up system settings...." 1018 | /sbin/auto-backup.sh 1019 | %firstboot --interpreter=busybox 1020 | python /store/installomsa.py 1021 | echo "Completed OMSA install" 1022 | python /store/duplicateImageDetection.py 2>&1 1023 | echo "Completed Duplicate Image Detection" 1024 | esxcli storage nfs remove --volume-name=remote-install-location 1025 | sleep 30s 1026 | reboot 1027 | --------------------------------------------------------------------------------