示例#1
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()
示例#2
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()
示例#3
0
def get_build_plan(con, bp_name):
    #search_uri='/rest/index/resources?category=osdbuildplan&query=\'osbuildplanname:\"'+urllib.quote_plus(bp_name)+'\"\''
    #search_result = con.get(search_uri)
    #print search_result
    #if search_result['count'] > 0 and search_result['members'][0]['attributes']['name'] == bp_name:
    #    osbp_uri = search_result['members'][0]['attributes']['uri']
    #    bp=hpICsp.buildPlans(con)
    #    return bp.get_build_plans(osbp_uri)

    #return None
    bp = hpICsp.buildPlans(con)

    build_plans = bp.get_build_plans()['members']
    return next((bp for bp in build_plans if bp['name'] == bp_name), None)
def get_build_plan(con, bp_name):
    #search_uri='/rest/index/resources?category=osdbuildplan&query=\'osbuildplanname:\"'+urllib.quote_plus(bp_name)+'\"\''
    #search_result = con.get(search_uri)
    #print search_result
    #if search_result['count'] > 0 and search_result['members'][0]['attributes']['name'] == bp_name:
    #    osbp_uri = search_result['members'][0]['attributes']['uri']
    #    bp=hpICsp.buildPlans(con)
    #    return bp.get_build_plans(osbp_uri)


    #return None
    bp=hpICsp.buildPlans(con)

    build_plans = bp.get_build_plans()['members']
    return next((bp  for bp in build_plans if bp['name'] == bp_name), None)
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})
示例#6
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)
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)
示例#8
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})
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})
示例#10
0
def get_build_plan(con, bp_name):
    bp = hpICsp.buildPlans(con)
    build_plans = bp.get_build_plans()["members"]
    return next((bp for bp in build_plans if bp["name"] == bp_name), None)
示例#11
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})
示例#12
0
def get_build_plan(con, bp_name):
    bp = hpICsp.buildPlans(con)
    build_plans = bp.get_build_plans()['members']
    return next((bp for bp in build_plans if bp['name'] == bp_name), None)