Example #1
0
def images_custom_list(args, producer_data):
    tenant, token, url = mutate_url_servers_endpoint(producer_data)

    url = url + '/' + 'detail'
    r = do_raw_request(url, token)
    output = r.json()["images"]
    custom_images_list = [custom_images for custom_images in output
                          if custom_images["metadata"].get('user_id', None)]
    temp_image_list = []
    for image in custom_images_list:
        image_temp = ({"status": image["status"],
                       "links": image["links"][0]["href"],
                       "id": image["id"], "name": image["name"]})
        temp_image_list.append(image_temp)
    if len(temp_image_list):
        print json.dumps(
                { "custom-images": temp_image_list }, indent=2)
Example #2
0
def member_add(args, producer_data,
               remove=False, consumer_tenant=None):
    # if called from command line instead of image_share()
    if args.get('consumer_tenantid', None):
        consumer_tenant = args['consumer_tenantid']

    producer_tenant, producer_token, producer_url = producer_data

    uuid = args['uuid']
    url = producer_url + "/" + uuid + "/members"
    json_data = {"member": consumer_tenant}


    if remove:
        print("\nAttempting to remove consumer {}"
              " as member to image {}...".format(consumer_tenant, uuid))
        url = url + "/" + consumer_tenant
        # remove/delete API does not return body
        # so do raw request
        r = do_raw_request(url, producer_token, mode="delete")
        if r.status_code == 204:
            # Delete API does not return anything
            print "Success"
        elif r.status_code == 404:
            print("User {} doesn't exist"
                  " as a member").format(consumer_tenant)
    else:
        print("\nAttempting to add consumer {}"
              " as member to image {}...".format(consumer_tenant, uuid))
        body, status_code = do_request(
            url, producer_token, json_data, mode="post")
        if status_code == 409:
            print "Member already exists!...don't worry...continuing..."
        elif status_code == 404:
            print ("No image found with ID {}." 
                   "\nAre you sure the Producer's image"
                   " resides in region {}?".format(
                       uuid, args["region"]))
            sys.exit()
        else:
            print status_code
            print body
            sys.exit();