Project

Profile

Help

Story #5238 ยป populate_collection_data_repo_distribution.sh

bmbouter, 08/09/2019 04:31 PM

 
1
#!/bin/bash
2

    
3
export BASE_HREF=localhost:24817
4

    
5
wait_for_pulp() {
6
  unset CREATED_RESOURCE
7
  local task_url=$1
8
  while [ -z "$CREATED_RESOURCE" ]
9

    
10
  do
11
    sleep 1
12
    export CREATED_RESOURCE=$(http $BASE_ADDR$task_url | jq -r '.created_resources | first')
13
  done
14
}
15

    
16

    
17

    
18

    
19
# Start by creating a new repository named "foo":
20
http POST $BASE_ADDR/pulp/api/v3/repositories/ name=foo
21

    
22
# If you want to copy/paste your way through the guide,
23
# create an environment variable for the repository URI.
24
export REPO_HREF=$(http $BASE_ADDR/pulp/api/v3/repositories/ | \
25
  jq -r '.results[] | select(.name == "foo") | ._href')
26

    
27
# Lets inspect our newly created repository.
28
http $BASE_ADDR$REPO_HREF
29

    
30

    
31

    
32

    
33

    
34
# Create a remote that syncs some versions of django into your repository.
35
http POST $BASE_ADDR/pulp/api/v3/remotes/ansible/collection/ \
36
    name='bar' \
37
    url='https://galaxy-dev.ansible.com/api/v2/collections/testing/ansible_testing_content'
38

    
39
sleep 1
40

    
41
# Export an environment variable for the new remote URI.
42
export REMOTE_HREF=$(http $BASE_ADDR/pulp/api/v3/remotes/ansible/collection/ | jq -r '.results[] | select(.name == "bar") | ._href')
43

    
44
# Lets inspect our newly created Remote
45
http $BASE_ADDR$REMOTE_HREF
46

    
47

    
48

    
49

    
50

    
51

    
52
# Distributions are created asynchronously. Create one, and specify the publication that will
53
# be served at the base path specified.
54
export TASK_URL=$(http POST $BASE_ADDR/pulp/api/v3/distributions/ansible/ansible/ \
55
  name='baz' \
56
  base_path='foo' \
57
  repository=${REPO_HREF} | jq -r '.task')
58

    
59
# Poll the task (here we use a function defined in docs/_scripts/base.sh)
60
# When the task is complete, it gives us the href for our new Distribution
61
wait_for_pulp $TASK_URL
62
export DIST_PATH=${CREATED_RESOURCE[0]}
63

    
64
# Lets inspect the Distribution
65
http $BASE_ADDR$DIST_PATH
    (1-1/1)