RedHatSatellite / satellite-clone

Utility to assist cloning an existing Satellite 6 server to a new host
GNU General Public License v3.0
37 stars 31 forks source link

Capsule disassociation failed with regular clone scenario of rhel7 sat 6.2 #175

Open sthirugn opened 7 years ago

sthirugn commented 7 years ago
TASK [satellite-clone : Disassociate capsules with lifecycle environments (to avoid the cloned Satellite server talking with live capsules)] ***
Friday 07 April 2017  12:58:35 -0400 (0:00:00.026)       0:56:25.277 ********** 
changed: [localhost]

stdout: All Capsules are unassociated with any lifecycle environments. This is to avoid any syncing errors with your original Satellite and any interference with existing infrastructure. To reverse these changes, run the following commands, making sure to replace the credentials with your own.
hammer -u admin -p changeme --csv capsule content add-lifecycle-environment --id 2 --environment QE --organization "S?o Paulo"
hammer -u admin -p changeme --csv capsule content add-lifecycle-environment --id 3 --environment QE --organization "S?o Paulo"

Additional info:

hammer -u admin -p changeme organization list
---|----------------------|--------------------------------------|----------------------------
ID | NAME                 | LABEL                                | DESCRIPTION                
---|----------------------|--------------------------------------|----------------------------
1  | Default Organization | Default_Organization                 |                            
3  | São Paulo            | e9db3daa-5c32-4a41-881d-3fa3a828a5c1 | The São Paulo organization.
---|----------------------|--------------------------------------|----------------------------

hammer> lifecycle-environment list --organization-id=1
---|---------|--------
ID | NAME    | PRIOR  
---|---------|--------
3  | QE      | DEV    
1  | Library |        
2  | DEV     | Library
---|---------|--------

hammer> lifecycle-environment list --organization-id=3
---|---------|--------
ID | NAME    | PRIOR  
---|---------|--------
5  | Today   | Library
4  | Library |        
6  | Amanhã  | Library
---|---------|--------
johnpmitsch commented 7 years ago

Looks like the script won't handle special characters well. Unfortunately capsule info only returns capsule info by name

We can maybe use --json and parse that

akofink commented 7 years ago

While parsing json is one solution, I would be interested in where the special characters are not supported. During preliminary testing in IRB, it seems that Ruby 2.3 can parse special characters returned from hammer and pass them back to hammer as options in a subsequent command. Other things to try:

If all else fails, then json parsing it is!

rplevka commented 7 years ago

Constructing the hammer command and parsing its output may go wrong on many levels. Why don't we use the API straight away and use json module to parse the response? We can operate solely on the ids.

Also, shouldn't we have the credentials parametrized? This script statically relies on admin:changeme

import json
import requests
from requests.auth import HTTPBasicAuth

sat = 'sat6-server.domain.com'
usr = 'admin'
pwd = 'changeme'

capsule_get = requests.get(
    'https://{0}/api/capsules'.format(sat),                                                                                                       
    auth=HTTPBasicAuth(usr, pwd),
    verify=False
)
capsules = json.loads(capsule_get.text)
In [17]: capsules
Out[17]: 
{u'page': 1,
 u'per_page': 20,
 u'results': [{u'created_at': u'2017-07-24 11:42:05 UTC',
   u'features': [{u'id': 2, u'name': u'Pulp'},
    {u'id': 4, u'name': u'TFTP'},
    {u'id': 5, u'name': u'DNS'},
    {u'id': 6, u'name': u'DHCP'},
    {u'id': 7, u'name': u'Puppet'},
    {u'id': 8, u'name': u'Puppet CA'},
    {u'id': 13, u'name': u'Dynflow'},
    {u'id': 14, u'name': u'Discovery'},
    {u'id': 15, u'name': u'Openscap'},
    {u'id': 16, u'name': u'SSH'}],
   u'id': 1,
   u'name': u'sat6-server.domain.com',
   u'updated_at': u'2017-07-24 11:42:06 UTC',
   u'url': u'https://sat6-server.domain.com:9090'}],
 u'search': None,
 u'sort': {u'by': None, u'order': None},
 u'subtotal': 1,
 u'total': 1}