Example #1
0
    def _add_server(self):
        ilo_address = self.module.params['server_ipAddress']

        # Creates a JSON body for adding an iLo.
        ilo_body = {
            'ipAddress': ilo_address,
            'username': self.module.params['server_username'],
            'password': self.module.params['server_password'],
            'port': self.module.params['server_port']
        }

        job_monitor = hpICsp.jobs(self.connection)
        servers_service = hpICsp.servers(self.connection)

        # Monitor_execution is a utility method to watch job progress on the command line.
        add_server_job = servers_service.add_server(ilo_body)
        hpICsp.common.monitor_execution(add_server_job, job_monitor)

        # Python bindings throw an Exception when the status != ok
        # So if we got this far, the job execution finished as expected

        # gets the target server added to ICsp to return on ansible facts
        target_server = self.__get_server_by_ilo_address(ilo_address)
        return self.module.exit_json(
            changed=True,
            msg=SERVER_CREATED.format(target_server['uri']),
            ansible_facts=dict(target_server=target_server))
Example #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()
Example #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()
    def _add_server(self):
        ilo_address = self.module.params['server_ipAddress']

        # Creates a JSON body for adding an iLo.
        ilo_body = {'ipAddress': ilo_address,
                    'username': self.module.params['server_username'],
                    'password': self.module.params['server_password'],
                    'port': self.module.params['server_port']}

        job_monitor = hpICsp.jobs(self.connection)
        servers_service = hpICsp.servers(self.connection)

        # Monitor_execution is a utility method to watch job progress on the command line.
        add_server_job = servers_service.add_server(ilo_body)
        hpICsp.common.monitor_execution(add_server_job, job_monitor)

        # Python bindings throw an Exception when the status != ok
        # So if we got this far, the job execution finished as expected

        # gets the target server added to ICsp to return on ansible facts
        target_server = self.__get_server_by_ilo_address(ilo_address)
        return self.module.exit_json(changed=True,
                                     msg=self.SERVER_CREATED.format(target_server['uri']),
                                     ansible_facts=dict(target_server=target_server))
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})
Example #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 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})
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 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})
Example #10
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})