コード例 #1
0
def main():
    # Creates a connection with the appliance.
    con = hpICsp.connection(parentIP)
    # Create objects for all necessary resources.
    st = hpICsp.settings(con)

    # Login into master/parent appliance.
    credential = {'userName': parentUser, 'password': parentPassword}
    con.login(credential)

    # Export appliance content
    bytesContent = st.export_content()
    # Write content to a zip file and set appropriate permissions.
    newFile = open("content.zip", "wb")
    newFile.write(bytesContent)
    os.chmod("content.zip", stat.S_IRWXO | stat.S_IRWXG | stat.S_IRWXU)
    newFile.close()
    # Logout of parent appliance.
    con.logout()

    # For each child appliance, create a connection, log in, import the master's content, and log out.
    for x in range(0, len(childIPs)):
        con = hpICsp.connection(childIPs[x])
        credential = {'userName': childUsers[x], 'password': childPasswords[x]}
        con.login(credential)
        st = hpICsp.settings(con)
        st.import_content("content.zip")
        con.logout()
コード例 #2
0
def main():
    # Creates a connection with the appliance.
    con = hpICsp.connection(parentIP)
    # Create objects for all necessary resources.
    st = hpICsp.settings(con)

    # Login into master/parent appliance.
    credential = {'userName': parentUser, 'password': parentPassword}
    con.login(credential)

    # Export appliance content
    bytesContent = st.export_content()
    # Write content to a zip file and set appropriate permissions.
    newFile = open("content.zip", "wb")
    newFile.write(bytesContent)
    os.chmod("content.zip", stat.S_IRWXO | stat.S_IRWXG | stat.S_IRWXU)
    newFile.close()
    # Logout of parent appliance.
    con.logout()

    # For each child appliance, create a connection, log in, import the master's content, and log out.
    for x in range(0, len(childIPs)):
        con = hpICsp.connection(childIPs[x])
        credential = {'userName': childUsers[x], 'password': childPasswords[x]}
        con.login(credential)
        st = hpICsp.settings(con)
        st.import_content("content.zip")
        con.logout()
コード例 #3
0
def main():
    #Creates a connection with the appliance.
    con=hpICsp.connection(applianceIP)
	#Create objects for all necessary resources.
    bp=hpICsp.buildPlans(con)
    jb=hpICsp.jobs(con)
    sv=hpICsp.servers(con)

    #Login using parsed login information
    credential = {'userName': applianceUser, 'password': appliancePassword}
    con.login(credential)


    #Add server by iLo credentials.
	#Monitor_execution is a utility method to watch job progress on the command line.
	#Pass in the method which starts a job as well as a job resource object.
    status=hpICsp.common.monitor_execution(sv.add_server(iLoBody),jb)
	
	#Parse the job output to retrieve the ServerID and create a JSON body with it.
    serverID=status['jobResult'][0]['jobResultLogDetails'].split('ServerRef:')[1].split(')')[0]
    buildPlanBody={"osbpUris":[buildPlanURI],"serverData":[{"serverUri":"/rest/os-deployment-servers/" + serverID}]}
	
    #Monitor the execution of a build plan which installs RedHat 6.4 on the server just added.
    hpICsp.common.monitor_execution(jb.add_job(buildPlanBody),jb)

 	#Generate a JSON body for some post network configuration.
    networkConfig = {"serverData":[{"serverUri":'/rest/os-deployment-servers/' + serverID,"personalityData":{"hostName":hostName,"displayName":displayName}}]}
	
	#Monitor the execution of a nework personalization job.
    hpICsp.common.monitor_execution(jb.add_job(networkConfig),jb)

    #Logout when everything has completed.
    con.logout()
コード例 #4
0
ファイル: Add_Server.py プロジェクト: mansinga1/DeployESXi
def main():
    #Creates a connection with the appliance.
    con=hpICsp.connection(applianceIP)
	#Create objects for all necessary resources.
    bp=hpICsp.buildPlans(con)
    jb=hpICsp.jobs(con)
    sv=hpICsp.servers(con)

    #Login using parsed login information
    credential = {'userName': applianceUser, 'password': appliancePassword}
    con.login(credential)


    #Add server by iLo credentials.
	#Monitor_execution is a utility method to watch job progress on the command line.
	#Pass in the method which starts a job as well as a job resource object.
    status=hpICsp.common.monitor_execution(sv.add_server(iLoBody),jb)
	
	#Parse the job output to retrieve the ServerID and create a JSON body with it.
    serverID=status['jobResult'][0]['jobResultLogDetails'].split('ServerRef:')[1].split(')')[0]
    buildPlanBody={"osbpUris":[buildPlanURI],"serverData":[{"serverUri":"/rest/os-deployment-servers/" + serverID}]}
	
    #Monitor the execution of a build plan which installs RedHat 6.4 on the server just added.
    hpICsp.common.monitor_execution(jb.add_job(buildPlanBody),jb)

 	#Generate a JSON body for some post network configuration.
    networkConfig = {"serverData":[{"serverUri":'/rest/os-deployment-servers/' + serverID,"personalityData":{"hostName":hostName,"displayName":displayName}}]}
	
	#Monitor the execution of a nework personalization job.
    hpICsp.common.monitor_execution(jb.add_job(networkConfig),jb)

    #Logout when everything has completed.
    con.logout()
コード例 #5
0
    def __authenticate(self):
        # Credentials
        icsp_host = self.module.params['icsp_host']
        username = self.module.params['username']
        password = self.module.params['password']

        con = hpICsp.connection(icsp_host)

        credential = {'userName': username, 'password': password}
        con.login(credential)
        return con
コード例 #6
0
    def __authenticate(self):
        # Credentials
        icsp_host = self.module.params['icsp_host']
        icsp_api_version = self.module.params['api_version']
        username = self.module.params['username']
        password = self.module.params['password']

        con = hpICsp.connection(icsp_host, icsp_api_version)

        credential = {'userName': username, 'password': password}
        con.login(credential)
        return con
コード例 #7
0
def main():
    parser = argparse.ArgumentParser(add_help=True, description='Usage')
    parser.add_argument('-a', '--appliance', dest='host', required=True,
                        help='HP ICsp Appliance hostname or IP')
    parser.add_argument('-u', '--user', dest='user', required=True,
                        help='HP ICsp Username')
    parser.add_argument('-p', '--pass', dest='passwd', required=True,
                        help='HP ICsp Password')
    parser.add_argument('-c', '--certificate', dest='cert', required=False,
                        help='Trusted SSL Certificate Bundle in PEM '
                        '(Base64 Encoded DER) Format')
    parser.add_argument('-r', '--proxy', dest='proxy', required=False,
                        help='Proxy (host:port format')
    args = parser.parse_args()
    con = connection(args.host)
    if args.proxy:
        con.set_proxy(args.proxy.split(':')[0], args.proxy.split(':')[1])
    if args.cert:
        con.set_trusted_ssl_bundle(args.cert)
    credential = {'userName': args.user, 'password': args.passwd}
    con.login(credential)
    con.logout()
コード例 #8
0
def main():
    # Creates a connection with the appliance.
    con = hpICsp.connection(applianceIP)
    # Create objects for all necessary resources.
    st = hpICsp.settings(con)

    # Login using parsed login information
    credential = {'userName': applianceUser, 'password': appliancePassword}
    con.login(credential)

    # Export appliance content
    bytesContent = st.export_content()

    # Write content to zip file containing current time.
    name = ("Backup " + time.strftime("%c") + ".zip")
    newFile = open(name, "wb")
    newFile.write(bytesContent)
    os.chmod(name, stat.S_IRWXO | stat.S_IRWXG | stat.S_IRWXU)
    newFile.close()

    # Logout of appliance
    con.logout()
コード例 #9
0
def main():
    #Creates a connection with the appliance.
	con=hpICsp.connection(applianceIP)
	#Create objects for all necessary resources.
	st=hpICsp.settings(con)

	#Login using parsed login information
	credential = {'userName': applianceUser, 'password': appliancePassword}
	con.login(credential)
	
	#Export appliance content 
	bytesContent=st.export_content()
	
	#Write content to zip file containing current time.
	name=("Backup " + time.strftime("%c") + ".zip")
	newFile = open (name, "wb")
	newFile.write(bytesContent)
	os.chmod(name, stat.S_IRWXO | stat.S_IRWXG | stat.S_IRWXU)
	newFile.close()
	
	#Logout of appliance
	con.logout()
コード例 #10
0
def main():
    parser = argparse.ArgumentParser(add_help=True, description='Usage')
    parser.add_argument('-a',
                        '--appliance',
                        dest='host',
                        required=True,
                        help='HP ICsp Appliance hostname or IP')
    parser.add_argument('-u',
                        '--user',
                        dest='user',
                        required=True,
                        help='HP ICsp Username')
    parser.add_argument('-p',
                        '--pass',
                        dest='passwd',
                        required=True,
                        help='HP ICsp Password')
    parser.add_argument('-c',
                        '--certificate',
                        dest='cert',
                        required=False,
                        help='Trusted SSL Certificate Bundle in PEM '
                        '(Base64 Encoded DER) Format')
    parser.add_argument('-r',
                        '--proxy',
                        dest='proxy',
                        required=False,
                        help='Proxy (host:port format')
    args = parser.parse_args()
    con = connection(args.host)
    if args.proxy:
        con.set_proxy(args.proxy.split(':')[0], args.proxy.split(':')[1])
    if args.cert:
        con.set_trusted_ssl_bundle(args.cert)
    credential = {'userName': args.user, 'password': args.passwd}
    con.login(credential)
    con.logout()
コード例 #11
0
def deploy_server(module):
    # Credentials
    icsp_host = module.params['icsp_host']
    icsp_api_version = module.params['api_version']
    username = module.params['username']
    password = module.params['password']

    # Build Plan Options
    server_id = module.params['server_id']
    os_build_plan = module.params['os_build_plan']
    custom_attributes = module.params['custom_attributes']
    personality_data = module.params['personality_data']
    con = hpICsp.connection(icsp_host, icsp_api_version)

    # Create objects for all necessary resources.
    credential = {'userName': username, 'password': password}
    con.login(credential)

    bp = hpICsp.buildPlans(con)
    jb = hpICsp.jobs(con)
    sv = hpICsp.servers(con)

    bp = get_build_plan(con, os_build_plan)

    if bp is None:
        return module.fail_json(msg='Cannot find OS Build plan: ' + os_build_plan)

    timeout = 600
    while True:
        server = get_server_by_serial(con, server_id)
        if server:
            break
        if timeout < 0:
            module.fail_json(msg='Cannot find server in ICSP.')
            return
        timeout -= 30
        time.sleep(30)

    server = sv.get_server(server['uri'])
    if server['state'] == 'OK':
        return module.exit_json(changed=False, msg="Server already deployed.", ansible_facts={'icsp_server': server})

    if custom_attributes:
        ca_list = []

        for ca in custom_attributes:
            ca_list.append({
                'key': list(ca.keys())[0],
                'values': [{'scope': 'server', 'value': str(list(ca.values())[0])}]})

        ca_list.extend(server['customAttributes'])
        server['customAttributes'] = ca_list
        sv.update_server(server)

    server_data = {"serverUri": server['uri'], "personalityData": None}

    build_plan_body = {"osbpUris": [bp['uri']], "serverData": [server_data], "stepNo": 1}

    hpICsp.common.monitor_execution(jb.add_job(build_plan_body), jb)

    # If the playbook included network personalization, update the server to include it
    if personality_data:
        server_data['personalityData'] = personality_data
        network_config = {"serverData": [server_data]}
        # Monitor the execution of a nework personalization job.
        hpICsp.common.monitor_execution(jb.add_job(network_config), jb)

    server = sv.get_server(server['uri'])
    return module.exit_json(changed=True, msg='OS Deployed Successfully.', ansible_facts={'icsp_server': server})
コード例 #12
0
def main():

    icsp_host = 'icsp.vse.rdlabs.hpecorp.net'
    username = '******'
    password = '******'
    server_id = ''
    os_build_plan = ''
    #args = module.params['args']

    con = hpICsp.connection(icsp_host)
    #Create objects for all necessary resources.
    bp = hpICsp.buildPlans(con)
    jb = hpICsp.jobs(con)

    credential = {'userName': username, 'password': password}
    con.login(credential)
    #try:
    #bp = get_build_plan(con, "CHEF - RHEL 7.0 x64")
    #print bp
    #print str(bp)

    #except Exception , e:
    #    print e.message
    #    raise
    #'uri': u'/rest/os-deployment-build-plans/1340001'

    sv = hpICsp.servers(con)
    server = get_server_by_serial(con, "VCGUS6O00W")
    server = sv.get_server(server['uri'])
    print server
    #'uri': u'/rest/os-deployment-servers/2050001'

    existing_ca_list = server['customAttributes']
    print "existing"
    print existing_ca_list

    print "after"
    existing_ca_list = [{
        'key':
        ca.keys()[0],
        'values': [{
            'scope': 'server',
            'value': ca.values()[0]
        }]
    } for ca in existing_ca_list if ca['key'] not in ['hpsa_netconfig']]
    print existing_ca_list
    #print bp
    #print server
    #buildPlanBody={"osbpUris":[bp['uri']],"serverData":[{"serverUri":server['uri']}]}
    #hpICsp.common.monitor_execution(jb.add_job(buildPlanBody),jb)

    return

    #Parse the job output to retrieve the ServerID and create a JSON body with it.
    serverID = status['jobResult'][0]['jobResultLogDetails'].split(
        'ServerRef:')[1].split(')')[0]
    buildPlanBody = {
        "osbpUris": [buildPlanURI],
        "serverData": [{
            "serverUri": "/rest/os-deployment-servers/" + serverID
        }]
    }

    #Monitor the execution of a build plan which installs RedHat 6.4 on the server just added.
    hpICsp.common.monitor_execution(jb.add_job(buildPlanBody), jb)

    #Generate a JSON body for some post network configuration.
    networkConfig = {
        "serverData": [{
            "serverUri": '/rest/os-deployment-servers/' + serverID,
            "personalityData": {
                "hostName": hostName,
                "displayName": displayName
            }
        }]
    }

    #Monitor the execution of a nework personalization job.
    hpICsp.common.monitor_execution(jb.add_job(networkConfig), jb)
コード例 #13
0
def deploy_server(module):
    # Credentials
    icsp_host = module.params['icsp_host']
    icsp_api_version = module.params['api_version']
    username = module.params['username']
    password = module.params['password']

    # Build Plan Options
    server_id = module.params['server_id']
    os_build_plan = module.params['os_build_plan']
    custom_attributes = module.params['custom_attributes']
    personality_data = module.params['personality_data']
    ilo_address = module.params['server_ipAddress']

    if ilo_address is None and server_id is None:
        return module.fail_json(
            msg=
            'No server information provided. Param \"server_id\" or \"server_ipAddress\" must be specified.'
        )

    con = hpICsp.connection(icsp_host, icsp_api_version)
    icsphelper = ICspHelper(con)

    # Create objects for all necessary resources.
    credential = {'userName': username, 'password': password}
    con.login(credential)

    jb = hpICsp.jobs(con)
    sv = hpICsp.servers(con)

    bp = icsphelper.get_build_plan(os_build_plan)

    if bp is None:
        return module.fail_json(msg='Cannot find OS Build plan: ' +
                                os_build_plan)

    timeout = 600
    while True:
        if ilo_address:
            server = icsphelper.get_server_by_ilo_address(ilo_address)
        else:
            server = icsphelper.get_server_by_serial(server_id)
        if server:
            break
        if timeout < 0:
            module.fail_json(msg='Cannot find server in ICSP.')
            return
        timeout -= 30
        time.sleep(30)

    server = sv.get_server(server['uri'])
    if server['state'] == 'OK':
        return module.exit_json(changed=False,
                                msg="Server already deployed.",
                                ansible_facts={'icsp_server': server})

    if custom_attributes:
        ca_list = []

        for ca in custom_attributes:
            ca_list.append({
                'key':
                list(ca.keys())[0],
                'values': [{
                    'scope': 'server',
                    'value': str(list(ca.values())[0])
                }]
            })

        ca_list.extend(server['customAttributes'])
        server['customAttributes'] = ca_list
        sv.update_server(server)

    server_data = {"serverUri": server['uri'], "personalityData": None}

    build_plan_body = {
        "osbpUris": [bp['uri']],
        "serverData": [server_data],
        "stepNo": 1
    }

    hpICsp.common.monitor_execution(jb.add_job(build_plan_body), jb)

    # If the playbook included network personalization, update the server to include it
    if personality_data:
        server_data['personalityData'] = personality_data
        network_config = {"serverData": [server_data]}
        # Monitor the execution of a nework personalization job.
        hpICsp.common.monitor_execution(jb.add_job(network_config), jb)

    server = sv.get_server(server['uri'])
    return module.exit_json(changed=True,
                            msg='OS Deployed Successfully.',
                            ansible_facts={'icsp_server': server})
コード例 #14
0
def main():

    icsp_host = 'icsp.vse.rdlabs.hpecorp.net'
    username = '******'
    password = '******'
    server_id = ''
    os_build_plan = ''
    #args = module.params['args']

    con=hpICsp.connection(icsp_host)
    #Create objects for all necessary resources.
    bp=hpICsp.buildPlans(con)
    jb=hpICsp.jobs(con)


    credential = {'userName': username, 'password': password}
    con.login(credential)
    #try:
        #bp = get_build_plan(con, "CHEF - RHEL 7.0 x64")
        #print bp
        #print str(bp)

    #except Exception , e:
    #    print e.message
    #    raise
    #'uri': u'/rest/os-deployment-build-plans/1340001'

    sv=hpICsp.servers(con)
    server = get_server_by_serial(con, "VCGUS6O00W")
    server = sv.get_server(server['uri'])
    print server
    #'uri': u'/rest/os-deployment-servers/2050001'


    existing_ca_list = server['customAttributes']
    print "existing"
    print existing_ca_list

    print "after"
    existing_ca_list = [ {'key':ca.keys()[0], 'values':[{'scope': 'server', 'value':ca.values()[0]}]} for ca in existing_ca_list if ca['key'] not in ['hpsa_netconfig'] ]
    print existing_ca_list
    #print bp
    #print server
    #buildPlanBody={"osbpUris":[bp['uri']],"serverData":[{"serverUri":server['uri']}]}
    #hpICsp.common.monitor_execution(jb.add_job(buildPlanBody),jb)

    return


    #Parse the job output to retrieve the ServerID and create a JSON body with it.
    serverID=status['jobResult'][0]['jobResultLogDetails'].split('ServerRef:')[1].split(')')[0]
    buildPlanBody={"osbpUris":[buildPlanURI],"serverData":[{"serverUri":"/rest/os-deployment-servers/" + serverID}]}

    #Monitor the execution of a build plan which installs RedHat 6.4 on the server just added.
    hpICsp.common.monitor_execution(jb.add_job(buildPlanBody),jb)

    #Generate a JSON body for some post network configuration.
    networkConfig = {"serverData":[{"serverUri":'/rest/os-deployment-servers/' + serverID,"personalityData":{"hostName":hostName,"displayName":displayName}}]}

    #Monitor the execution of a nework personalization job.
    hpICsp.common.monitor_execution(jb.add_job(networkConfig),jb)
コード例 #15
0
def deploy_server(module):
    icsp_host = module.params["icsp_host"]
    username = module.params["username"]
    password = module.params["password"]
    server_id = module.params["server_id"]
    os_build_plan = module.params["os_build_plan"]
    custom_attributes = module.params["custom_attributes"]
    personality_data = module.params["personality_data"]
    con = hpICsp.connection(icsp_host)
    # Create objects for all necessary resources.

    credential = {"userName": username, "password": password}
    con.login(credential)

    bp = hpICsp.buildPlans(con)
    jb = hpICsp.jobs(con)
    sv = hpICsp.servers(con)

    bp = get_build_plan(con, os_build_plan)

    if bp is None:
        module.fail_json(msg="Cannot find OS Build plan " + os_build_plan)

    timeout = 600
    while True:
        server = get_server_by_serial(con, server_id)
        if server:
            break
        if timeout < 0:
            module.fail_json(msg="Cannot find server in ICSP")
        timeout -= 30
        time.sleep(30)

    server = sv.get_server(server["uri"])
    if server["state"] == "OK":
        module.exit_json(changed=False, msg="Server already deployed", ansible_facts={"icsp_server": server})

    if custom_attributes:
        ca_list = [
            {"key": ca.keys()[0], "values": [{"scope": "server", "value": str(ca.values()[0])}]}
            for ca in custom_attributes
        ]

        ca_list.extend(server["customAttributes"])
        server["customAttributes"] = ca_list
        sv.update_server(server)

    server_data = {"serverUri": server["uri"]}

    buildPlanBody = {"osbpUris": [bp["uri"]], "serverData": [server_data]}

    hpICsp.common.monitor_execution(jb.add_job(buildPlanBody), jb)

    if personality_data:
        server_data["personalityData"] = personality_data

    networkConfig = {"serverData": [server_data]}

    # Monitor the execution of a nework personalization job.
    hpICsp.common.monitor_execution(jb.add_job(networkConfig), jb)

    server = sv.get_server(server["uri"])
    module.exit_json(changed=True, msg="Deployed OS", ansible_facts={"icsp_server": server})
コード例 #16
0
ファイル: hpe_icsp.py プロジェクト: DPrince87/oneview-ansible
def deploy_server(module):
    icsp_host = module.params['icsp_host']
    username = module.params['username']
    password = module.params['password']
    server_id = module.params['server_id']
    os_build_plan = module.params['os_build_plan']
    custom_attributes = module.params['custom_attributes']
    personality_data = module.params['personality_data']
    con = hpICsp.connection(icsp_host)
    # Create objects for all necessary resources.

    credential = {'userName': username, 'password': password}
    con.login(credential)

    bp = hpICsp.buildPlans(con)
    jb = hpICsp.jobs(con)
    sv = hpICsp.servers(con)

    bp = get_build_plan(con, os_build_plan)

    if bp is None:
        module.fail_json(msg='Cannot find OS Build plan ' + os_build_plan)

    timeout = 600
    while True:
        server = get_server_by_serial(con, server_id)
        if server:
            break
        if timeout < 0:
            module.fail_json(msg='Cannot find server in ICSP')
        timeout -= 30
        time.sleep(30)

    server = sv.get_server(server['uri'])
    if server['state'] == 'OK':
        module.exit_json(changed=False,
                         msg="Server already deployed",
                         ansible_facts={'icsp_server': server})

    if custom_attributes:
        ca_list = [{
            'key':
            ca.keys()[0],
            'values': [{
                'scope': 'server',
                'value': str(ca.values()[0])
            }]
        } for ca in custom_attributes]

        ca_list.extend(server['customAttributes'])
        server['customAttributes'] = ca_list
        sv.update_server(server)

    server_data = {"serverUri": server['uri']}

    buildPlanBody = {"osbpUris": [bp['uri']], "serverData": [server_data]}

    hpICsp.common.monitor_execution(jb.add_job(buildPlanBody), jb)

    if personality_data:
        server_data['personalityData'] = personality_data

    networkConfig = {"serverData": [server_data]}

    # Monitor the execution of a nework personalization job.
    hpICsp.common.monitor_execution(jb.add_job(networkConfig), jb)

    server = sv.get_server(server['uri'])
    module.exit_json(changed=True,
                     msg='Deployed OS',
                     ansible_facts={'icsp_server': server})