Пример #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))
Пример #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 __configure_network(self, target_server):
        personality_data = self.module.params.get('server_personality_data')

        if not personality_data:
            return self.module.fail_json(msg=SERVER_PERSONALITY_DATA_REQUIRED)

        # check if server exists
        if not target_server:
            return self.module.exit_json(changed=False, msg=SERVER_NOT_FOUND)

        server_data = {
            "serverUri": target_server['uri'],
            "personalityData": personality_data,
            "skipReboot": True
        }
        network_config = {
            "serverData": [server_data],
            "failMode": None,
            "osbpUris": []
        }

        # Save nework personalization attribute, without running the job
        self.__add_write_only_job(network_config)

        servers_service = hpICsp.servers(self.connection)
        server = servers_service.get_server(target_server['uri'])
        return self.module.exit_json(changed=True,
                                     msg=CUSTOM_ATTR_NETWORK_UPDATED,
                                     ansible_facts={'target_server': server})
Пример #4
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()
Пример #5
0
def get_server(con, serial_number):
    sv = hpICsp.servers(con)

    servers = sv.get_server()['members']
    return next(
        (server
         for server in servers if server['serialNumber'] == serial_number),
        None)
Пример #6
0
    def __absent(self, target_server):
        # check if server exists
        if not target_server:
            return self.module.exit_json(changed=False, msg=self.SERVER_ALREADY_ABSENT)

        server_uri = target_server['uri']
        servers_service = hpICsp.servers(self.connection)

        try:
            servers_service.delete_server(server_uri)
            return self.module.exit_json(changed=True,
                                         msg=self.SERVER_REMOVED.format(server_uri))

        except HPICspException as icsp_exe:
            self.module.fail_json(msg=json.dumps(icsp_exe.__dict__))

        except Exception as exception:
            self.module.fail_json(msg='; '.join(str(e) for e in exception.args))
Пример #7
0
    def __absent(self, target_server):
        # check if server exists
        if not target_server:
            return self.module.exit_json(changed=False,
                                         msg=SERVER_ALREADY_ABSENT)

        server_uri = target_server['uri']
        servers_service = hpICsp.servers(self.connection)

        try:
            servers_service.delete_server(server_uri)
            return self.module.exit_json(changed=True,
                                         msg=SERVER_REMOVED.format(server_uri))

        except HPICspException as icsp_exe:
            self.module.fail_json(msg=json.dumps(icsp_exe.__dict__))

        except Exception as exception:
            self.module.fail_json(msg='; '.join(
                str(e) for e in exception.args))
Пример #8
0
    def __configure_network(self, target_server):
        personality_data = self.module.params.get('server_personality_data')

        if not personality_data:
            return self.module.fail_json(msg=self.SERVER_PERSONALITY_DATA_REQUIRED)

        # check if server exists
        if not target_server:
            return self.module.exit_json(changed=False, msg=self.SERVER_NOT_FOUND)

        server_data = {"serverUri": target_server['uri'], "personalityData": personality_data, "skipReboot": True}
        network_config = {"serverData": [server_data], "failMode": None, "osbpUris": []}

        # Save nework personalization attribute, without running the job
        self.__add_write_only_job(network_config)

        servers_service = hpICsp.servers(self.connection)
        server = servers_service.get_server(target_server['uri'])
        return self.module.exit_json(changed=True,
                                     msg=self.CUSTOM_ATTR_NETWORK_UPDATED,
                                     ansible_facts={'target_server': server})
Пример #9
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=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})
Пример #11
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 get_server(con, serial_number):
    sv=hpICsp.servers(con)

    servers = sv.get_server()['members']
    return next((server for server in servers if server['serialNumber'] == serial_number), None)
Пример #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
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})