def _setup_cico_connection(self):
     '''
     Populates self.api with the environment variables that we have. self.api will then
     be used to communicate with Duffy: requesting nodes, releasing nodes, ...
     '''
     if self.api is not None:
         return
     self.api = CicoWrapper(endpoint=os.environ['CICO_ENDPOINT'],
                            api_key=os.environ['CICO_API_KEY'])
Exemplo n.º 2
0
    def take_action(self, parsed_args):
        api = CicoWrapper(endpoint=self.app.options.endpoint,
                          api_key=self.app.options.api_key)

        inventory = api.inventory(all=parsed_args.all, ssid=parsed_args.ssid)

        columns = ('host_id', 'hostname', 'ip_address', 'chassis',
                   'used_count', 'current_state', 'comment', 'distro', 'rel',
                   'centos_version', 'architecture', 'node_pool',
                   'console_port', 'flavor')

        return (columns, (utils.get_dict_properties(inventory[host], columns)
                          for host in inventory))
Exemplo n.º 3
0
    def take_action(self, parsed_args):
        api = CicoWrapper(
            endpoint=self.app.options.endpoint,
            api_key=self.app.options.api_key
        )

        hosts = api.node_done(ssid=parsed_args.ssid)

        columns = ('host_id', 'hostname', 'ip_address', 'chassis',
                   'used_count', 'current_state', 'comment', 'distro',
                   'rel', 'centos_version', 'architecture', 'node_pool')

        return (columns,
                (utils.get_dict_properties(hosts[host], columns)
                 for host in hosts))
Exemplo n.º 4
0
    def take_action(self, parsed_args):
        api = CicoWrapper(endpoint=self.app.options.endpoint,
                          api_key=self.app.options.api_key)

        hosts, ssid = api.node_get(arch=parsed_args.arch,
                                   ver=parsed_args.release,
                                   count=parsed_args.count,
                                   retry_count=parsed_args.retry_count,
                                   retry_interval=parsed_args.retry_interval,
                                   flavor=parsed_args.flavor)

        columns = ('host_id', 'hostname', 'ip_address', 'chassis',
                   'used_count', 'current_state', 'comment', 'distro', 'rel',
                   'centos_version', 'architecture', 'node_pool',
                   'console_port', 'flavor')

        return (columns, (utils.get_dict_properties(hosts[host], columns)
                          for host in hosts))
def get_host(api_key, version):
    i = 0
    while True:
        api = CicoWrapper(endpoint="http://admin.ci.centos.org:8080/",
                          api_key=api_key)
        hosts = None

        try:
            hosts, ssid = api.node_get(ver=version, retry_count=1)
        except:
            pass

        if hosts == None:
            i = i + 1
            if i > 60:
                return (None, None)
            time.sleep(i)
            continue

        for host in hosts:
            return (host, ssid)
Exemplo n.º 6
0
def main():
    argument_spec = dict(
        action=dict(required=True, choices=['get', 'done', 'list']),
        arch=dict(default='x86_64', choices=['i386', 'x86_64', 'aarch64',
                                             'ppc64le']),
        flavor=dict(default='small', choices=['tiny', 'small', 'medium',
                                              'lram.tiny', 'lram.small',
                                              'xram.tiny', 'xram.small',
                                              'xram.medium', 'xram.large']),
        release=dict(default='7', choices=['5', '6', '7']),
        count=dict(default=1, type='int'),
        retry_count=dict(default=1, type='int'),
        retry_interval=dict(default=10, type='int'),
        endpoint=dict(default='http://admin.ci.centos.org:8080/'),
        api_key=dict(default=None, no_log=True),
        ssid=dict(default=None),
    )
    module = AnsibleModule(argument_spec)

    if not HAS_CICO:
        module.fail_json(msg='cicoclient is required for this module.')

    action = module.params['action']
    arch = module.params['arch']
    release = module.params['release']
    count = module.params['count']
    retry_count = module.params['retry_count']
    retry_interval = module.params['retry_interval']
    endpoint = module.params['endpoint']
    api_key = module.params['api_key']
    ssid = module.params['ssid']
    flavor = module.params['flavor']

    if action == 'done' and ssid is None:
        module.fail_json(msg='A SSID is required when releasing nodes.')

    try:
        api = CicoWrapper(
            endpoint=endpoint,
            api_key=api_key
        )

        if api.api_key is None:
            module.fail_json(msg='An API key is required for this module.')

        if action == 'get':
            hosts, new_ssid = api.node_get(arch=arch, ver=release, count=count,
                                           retry_count=retry_count,
                                           retry_interval=retry_interval,
                                           flavor=flavor)
            data = {
                'message': 'Requested servers successfully',
                'hosts': hosts,
                'ssid': new_ssid
            }
            module.exit_json(changed=True, results=data)

        if action == 'done':
            hosts = api.node_done(ssid=ssid)
            data = {
                'message': 'Released servers successfully',
                'hosts': hosts
            }
            module.exit_json(changed=True, results=data)

        if action == 'list':
            hosts = api.inventory(ssid=ssid)

            data = {
                'message': 'Listed servers successfully',
                'hosts': hosts
            }
            module.exit_json(changed=True, results=data)

    except Exception as e:
        module.fail_json(msg=e.message)
def all_hosts_done(api_key):
    api = CicoWrapper(endpoint="http://admin.ci.centos.org:8080/",
                      api_key=api_key)
    hosts = api.inventory()
    for host in hosts:
        host_done(api_key, hosts[host].get('comment'))
def host_done(api_key, ssid):
    api = CicoWrapper(endpoint="http://admin.ci.centos.org:8080/",
                      api_key=api_key)
    api.node_done(ssid=ssid)
    eprint("Duffy: Host with ssid %s marked as done" % ssid)
Exemplo n.º 9
0
def main():
    argument_spec = dict(
        action=dict(required=True, choices=['get', 'done', 'list']),
        arch=dict(default='x86_64', choices=['i386', 'x86_64']),
        release=dict(default='7', choices=['5', '6', '7']),
        count=dict(default='1'),
        retry_count=dict(default='1'),
        retry_interval=dict(default='10'),
        endpoint=dict(default='http://admin.ci.centos.org:8080/'),
        api_key=dict(default=os.getenv('CICO_API_KEY', None)),
        ssid=dict(default=None),
    )
    module = AnsibleModule(argument_spec)

    if not HAS_CICO:
        module.fail_json(msg='cicoclient is required for this module.')

    action = module.params['action']
    arch = module.params['arch']
    release = module.params['release']
    count = module.params['count']
    retry_count = module.params['retry_count']
    retry_interval = module.params['retry_interval']
    endpoint = module.params['endpoint']
    api_key = module.params['api_key']
    ssid = module.params['ssid']

    # Pre-flight validation
    if api_key is None:
        module.fail_json(msg='An API key is required for this module.')

    if action == 'done' and ssid is None:
        module.fail_json(msg='A SSID is required when releasing nodes.')

    try:
        api = CicoWrapper(
            endpoint=endpoint,
            api_key=api_key
        )

        if action == 'get':
            hosts, new_ssid = api.node_get(arch=arch, ver=release, count=count,
                                           retry_count=retry_count,
                                           retry_interval=retry_interval)
            data = {
                'message': 'Requested servers successfully',
                'hosts': hosts,
                'ssid': new_ssid
            }
            module.exit_json(changed=True, results=data)

        if action == 'done':
            hosts = api.node_done(ssid=ssid)
            data = {
                'message': 'Released servers successfully',
                'hosts': hosts
            }
            module.exit_json(changed=True, results=data)

        if action == 'list':
            hosts = api.inventory(ssid=ssid)

            data = {
                'message': 'Listed servers successfully',
                'hosts': hosts
            }
            module.exit_json(changed=True, results=data)

    except Exception as e:
        module.fail_json(msg=e.message)