python3 is required for R6 release
Change-Id: I94decf6ead79119f90f5fa70578b4cea8a3e58b7
Issue-ID: CCSDK-1893
Signed-off-by: Taka Cho <takamune.cho@att.com>
COPY ansible-server/requirements.txt ansible-server/requirements.txt
RUN apk add --no-cache curl \
COPY ansible-server/requirements.txt ansible-server/requirements.txt
RUN apk add --no-cache curl \
apk add --no-cache --virtual .build-deps build-base \
libffi-dev \
openssl-dev \
apk add --no-cache --virtual .build-deps build-base \
libffi-dev \
openssl-dev \
- python2-dev &&\
- pip install --no-cache-dir --upgrade pip==$PIP_TAG && \
- pip install --no-cache-dir -r ansible-server/requirements.txt &&\
+ python3-dev &&\
+ pip3 install --no-cache-dir --upgrade pip==$PIP_TAG && \
+ pip3 install --no-cache-dir -r ansible-server/requirements.txt &&\
apk del .build-deps
RUN addgroup -S ansible && adduser -S ansible -G ansible
apk del .build-deps
RUN addgroup -S ansible && adduser -S ansible -G ansible
COPY --chown=ansible:ansible ansible-server ansible-server
COPY --chown=ansible:ansible configuration/ansible.cfg /etc/ansible/ansible.cfg
COPY --chown=ansible:ansible ansible-server ansible-server
COPY --chown=ansible:ansible configuration/ansible.cfg /etc/ansible/ansible.cfg
WORKDIR /opt/ansible-server
RUN mkdir /opt/onap ; ln -s /opt/ansible-server /opt/onap/ccsdk
WORKDIR /opt/ansible-server
RUN mkdir /opt/onap ; ln -s /opt/ansible-server /opt/onap/ccsdk
log.append (line)
else:
for line in stdout_value: # p.stdout.readlines():
log.append (line)
else:
for line in stdout_value: # p.stdout.readlines():
if ParseFlag and len(line.strip())>0:
ip_address = line.split(':')[0].strip()
ok_flag = line.split(':')[1].strip().split('=')[1].split('changed')[0].strip()
if ParseFlag and len(line.strip())>0:
ip_address = line.split(':')[0].strip()
ok_flag = line.split(':')[1].strip().split('=')[1].split('changed')[0].strip()
p = Process(nodelist=ansible_call, args=('ansible_module_config', playbook_file, nodelist,d, ))
p.start()
p = Process(nodelist=ansible_call, args=('ansible_module_config', playbook_file, nodelist,d, ))
p.start()
- print "Process running"
- print d
+ print("Process running")
+ print(d)
self.cur.execute(myquery)
self.db.commit()
results = self.cur.fetchall()
self.cur.execute(myquery)
self.db.commit()
results = self.cur.fetchall()
results = repr(e)
return results
results = repr(e)
return results
- print "***> in AnsibleSql.readPlaybook"
+ print("***> in AnsibleSql.readPlaybook")
if not version:
query = "SELECT MAX(version) FROM playbook WHERE name like'" + value + "%'"
if not version:
query = "SELECT MAX(version) FROM playbook WHERE name like'" + value + "%'"
+ print(" Query:", query)
results = sqlintf.Query (query)
version = results[0][0]
results = sqlintf.Query (query)
version = results[0][0]
- print " Provided playbook name:", value
- print " Used version:", version
+ print(" Provided playbook name:", value)
+ print(" Used version:", version)
results = []
if version:
query = "SELECT value,type FROM playbook WHERE name='" + value + "@" + version + "'"
results = sqlintf.Query (query)
results = []
if version:
query = "SELECT value,type FROM playbook WHERE name='" + value + "@" + version + "'"
results = sqlintf.Query (query)
- print "Query:", query
- print "Results:", results
+ print("Query:", query)
+ print("Results:", results)
if len(results) == 0:
errorCode = 1
if len(results) == 0:
errorCode = 1
- print "***> in AnsibleSql.readCredential"
+ print("***> in AnsibleSql.readCredential")
rec +"'"
results = sqlintf.Query (query)
rec +"'"
results = sqlintf.Query (query)
- print " Query:", query
- print " Results:", len(results), results
+ print(" Query:", query)
+ print(" Results:", len(results), results)
if len(results) == 0:
errorCode = 1
if len(results) == 0:
errorCode = 1
- print "Loading playbooks"
+ print("Loading playbooks")
for file in onlyfiles:
if "yml" in file:
name = file.split (".yml")[0]
for file in onlyfiles:
if "yml" in file:
name = file.split (".yml")[0]
- print " Loading:", name
+ print(" Loading:", name)
version = name.split("@")[1]
errorCode, diag = loadPlaybook (sqlintf, name, version, '.yml')
if errorCode:
version = name.split("@")[1]
errorCode, diag = loadPlaybook (sqlintf, name, version, '.yml')
if errorCode:
- print " Results: Failed - ", diag
+ print(" Results: Failed - ", diag)
- print " Results: Success"
+ print(" Results: Success")
- print "\nLoading inventory"
+ print("\nLoading inventory")
file.close()
for hostgroup in inv:
file.close()
for hostgroup in inv:
- print " Loading:", hostgroup
+ print(" Loading:", hostgroup)
hostfqdn = ''
cred = ''
for hostname in inv[hostgroup]:
cred = inv[hostgroup][hostname]
errorCode, diag = loadCredentials (sqlintf, hostgroup, hostname, cred)
if errorCode:
hostfqdn = ''
cred = ''
for hostname in inv[hostgroup]:
cred = inv[hostgroup][hostname]
errorCode, diag = loadCredentials (sqlintf, hostgroup, hostname, cred)
if errorCode:
- print " Results: Failed - ", diag
+ print(" Results: Failed - ", diag)
- print " Results: Success"
+ print(" Results: Success")
- print "\nReading playbook"
+ print("\nReading playbook")
# Read playbook
if not sqlintf.con:
# Read playbook
if not sqlintf.con:
- print "Cannot connect to MySql:", sqlintf.error
+ print("Cannot connect to MySql:", sqlintf.error)
sys.exit()
name = "ansible_sleep"
sys.exit()
name = "ansible_sleep"
- print "Reading playbook:", name
+ print("Reading playbook:", name)
value, version, errorCode, diag = readPlaybook (sqlintf, name)
if errorCode:
value, version, errorCode, diag = readPlaybook (sqlintf, name)
if errorCode:
- print "Results: Failed - ", diag
+ print("Results: Failed - ", diag)
- print "Results: Success"
- print value
- print version
- print diag
+ print("Results: Success")
+ print(value)
+ print(version)
+ print(diag)
- print "\nReading inventory"
+ print("\nReading inventory")
# Read inventory
tag = ["your_inventory_test_group_name"]
# Read inventory
tag = ["your_inventory_test_group_name"]
- print "Reading inventory tag:", tag
+ print("Reading inventory tag:", tag)
errorCode, diag = readCredentials (sqlintf, tag)
if errorCode:
errorCode, diag = readCredentials (sqlintf, tag)
if errorCode:
- print "Results: Failed - ", diag
+ print("Results: Failed - ", diag)
- print "Results: Success"
- print diag
+ print("Results: Success")
+ print(diag)
self.cur.execute(myquery)
self.db.commit()
results = self.cur.fetchall()
self.cur.execute(myquery)
self.db.commit()
results = self.cur.fetchall()
error = str (e)
return results, error
error = str (e)
return results, error
query = "SELECT hostname,hostgroup FROM inventory WHERE hostname='" + hostname +"'"
results = sqlintf.Query (query)
query = "SELECT hostname,hostgroup FROM inventory WHERE hostname='" + hostname +"'"
results = sqlintf.Query (query)
if hostname in str(results):
if hostname in str(results):
sqlintf = mySql (host, user, passwd, db)
# Load playbooks
sqlintf = mySql (host, user, passwd, db)
# Load playbooks
- print "Loading playbooks"
+ print("Loading playbooks")
for file in onlyfiles:
if "yml" in file:
name = file.split (".yml")[0]
for file in onlyfiles:
if "yml" in file:
name = file.split (".yml")[0]
- print " Loading:", name
+ print(" Loading:", name)
version = name.split("@")[1]
errorCode, diag = loadPlaybook (name, version)
if errorCode:
version = name.split("@")[1]
errorCode, diag = loadPlaybook (name, version)
if errorCode:
- print " Results: Failed - ", diag
+ print(" Results: Failed - ", diag)
- print " Results: Success"
+ print(" Results: Success")
if "tar.gz" in file:
name = file.split (".tar.gz")[0]
if "tar.gz" in file:
name = file.split (".tar.gz")[0]
- print " Loading:", name
+ print(" Loading:", name)
version = name.split("@")[1]
errorCode, diag = loadPlaybook (name, version, ".tar.gz")
version = name.split("@")[1]
errorCode, diag = loadPlaybook (name, version, ".tar.gz")
- print "\nLoading inventory"
+ print("\nLoading inventory")
# Load inventory
hostgroup = None
# Load inventory
hostgroup = None
file.close()
for hostgroup in inv:
file.close()
for hostgroup in inv:
- print " Loading:", hostgroup
+ print(" Loading:", hostgroup)
hostfqdn = ''
cred = ''
for hostname in inv[hostgroup]:
cred = inv[hostgroup][hostname]
errorCode, diag = loadCredentials (hostgroup, hostname, cred)
if errorCode:
hostfqdn = ''
cred = ''
for hostname in inv[hostgroup]:
cred = inv[hostgroup][hostname]
errorCode, diag = loadCredentials (hostgroup, hostname, cred)
if errorCode:
- print " Results: Failed - ", diag
+ print(" Results: Failed - ", diag)
- print " Results: Success"
+ print(" Results: Success")
cherrypy.log("LocalParameters: " + str(local_parms))
f = open(playbook_path + "/vars/defaults.yml", "a")
cherrypy.log("LocalParameters: " + str(local_parms))
f = open(playbook_path + "/vars/defaults.yml", "a")
- for key, value in local_parms.items():
+ for key, value in list(local_parms.items()):
f.write(key + "=" + value + "\n")
f.close()
# ##################################################
f.write(key + "=" + value + "\n")
f.close()
# ##################################################
# Just a debug to dump any records
if 'GetStatus' in input_data['Type']:
cherrypy.log("******** Dump Records **********")
# Just a debug to dump any records
if 'GetStatus' in input_data['Type']:
cherrypy.log("******** Dump Records **********")
- if TestRecord.items():
- for id, record in TestRecord.items():
+ if list(TestRecord.items()):
+ for id, record in list(TestRecord.items()):
cherrypy.log(" Id: " + id)
cherrypy.log("Record: " + str(record))
else:
cherrypy.log(" Id: " + id)
cherrypy.log("Record: " + str(record))
else:
return out_obj
elif 'GetStatus' in input_data['Type']:
cherrypy.log(" Dump Records")
return out_obj
elif 'GetStatus' in input_data['Type']:
cherrypy.log(" Dump Records")
- for id, record in TestRecord.items():
+ for id, record in list(TestRecord.items()):
cherrypy.log(" id: " + id)
cherrypy.log(" Record:" + str(record))
elif 'GetTheOutput' in input_data['Type'] or 'GetOutput' in input_data['Type']:
cherrypy.log(" id: " + id)
cherrypy.log(" Record:" + str(record))
elif 'GetTheOutput' in input_data['Type'] or 'GetOutput' in input_data['Type']:
if 'ansible_inv' in config_line:
ANSIBLE_INV = config_line.split(':')[1].strip()
if not os.path.exists(ANSIBLE_PATH + "/" + ANSIBLE_INV):
if 'ansible_inv' in config_line:
ANSIBLE_INV = config_line.split(':')[1].strip()
if not os.path.exists(ANSIBLE_PATH + "/" + ANSIBLE_INV):
- print '[INFO] The ansible_inv file does not exist'
+ print('[INFO] The ansible_inv file does not exist')
sys.exit(0)
if 'ansible_temp' in config_line:
ANSIBLE_TEMP = config_line.split(':')[1].strip()
sys.exit(0)
if 'ansible_temp' in config_line:
ANSIBLE_TEMP = config_line.split(':')[1].strip()
def callback (Id, Result, Output, Log, returncode):
def callback (Id, Result, Output, Log, returncode):
- print "***> in RestServer.callback"
+ print("***> in RestServer.callback")
if Id in TestRecord:
time_now = datetime.datetime.utcnow()
if Id in TestRecord:
time_now = datetime.datetime.utcnow()
if key in TestRecord[Id]['Output']['Output']:
data["Results"][key]["Output"] = TestRecord[Id]['Output']['Output'][key]
if key in TestRecord[Id]['Output']['Output']:
data["Results"][key]["Output"] = TestRecord[Id]['Output']['Output'][key]
- print " Posting to", TestRecord[Id]['CallBack']
+ print(" Posting to", TestRecord[Id]['CallBack'])
s = requests.Session()
r = s.post(TestRecord[Id]['CallBack'], data = json.dumps(data),
headers = {'content-type': 'application/json'})
s = requests.Session()
r = s.post(TestRecord[Id]['CallBack'], data = json.dumps(data),
headers = {'content-type': 'application/json'})
- print " Response", r.status_code, r.text
+ print(" Response", r.status_code, r.text)
def RunAnsible_Playbook (callback, Id, Inventory, Playbook, NodeList, TestRecord,
Path, ArchiveFlag):
def RunAnsible_Playbook (callback, Id, Inventory, Playbook, NodeList, TestRecord,
Path, ArchiveFlag):
- print "***> in RestServer.RunAnsible_Playbook"
+ print("***> in RestServer.RunAnsible_Playbook")
# Run test in playbook for given target
Result = ''
# Run test in playbook for given target
Result = ''
# PAP
f = open(playbook_path + "/vars/defaults.yml","a")
#for id, record in TestRecord.items():
# PAP
f = open(playbook_path + "/vars/defaults.yml","a")
#for id, record in TestRecord.items():
- print TestRecord[Id]['LocalParameters']
+ print(TestRecord[Id]['LocalParameters'])
local_parms = TestRecord[Id]['LocalParameters']
local_parms = TestRecord[Id]['LocalParameters']
- for key, value in local_parms.items():
+ for key, value in list(local_parms.items()):
f.write(key +"=" + value + "\n");
f.close()
###################################################
f.write(key +"=" + value + "\n");
f.close()
###################################################
f.close()
f = open(playbook_path + "/JsonRequest.txt", "w")
#f.write(str(input_json))
f.close()
f = open(playbook_path + "/JsonRequest.txt", "w")
#f.write(str(input_json))
- print( json.dumps(input_json, indent=4, sort_keys=True))
+ print(( json.dumps(input_json, indent=4, sort_keys=True)))
f.write( json.dumps(input_json, indent=4, sort_keys=True))
f.close()
f.write( json.dumps(input_json, indent=4, sort_keys=True))
f.close()
# Just a debug to dump any records
if 'GetStatus' in input_data['Type']:
cherrypy.log( "******** Dump Records **********")
# Just a debug to dump any records
if 'GetStatus' in input_data['Type']:
cherrypy.log( "******** Dump Records **********")
- if TestRecord.items():
- for id, record in TestRecord.items():
+ if list(TestRecord.items()):
+ for id, record in list(TestRecord.items()):
cherrypy.log( " Id: " + id)
cherrypy.log( "Record: " + str(record))
else:
cherrypy.log( " Id: " + id)
cherrypy.log( "Record: " + str(record))
else:
return out_obj
elif 'GetStatus' in input_data['Type']:
return out_obj
elif 'GetStatus' in input_data['Type']:
for id, record in TestRecord,items():
for id, record in TestRecord,items():
- print " id: " + id
- print " Record:" + str(reecord)
+ print(" id: " + id)
+ print(" Record:" + str(reecord))
elif 'GetOutput' in input_data['Type']:
elif 'GetOutput' in input_data['Type']:
config_file_path = "RestServer_config"
if not os.path.exists(config_file_path):
config_file_path = "RestServer_config"
if not os.path.exists(config_file_path):
- print '[INFO] The config file does not exist'
+ print('[INFO] The config file does not exist')
# Point to certificate files
if not os.path.exists(pub):
# Point to certificate files
if not os.path.exists(pub):
- print '[INFO] The public certificate does not exist'
+ print('[INFO] The public certificate does not exist')
sys.exit(0)
if not os.path.exists(priv):
sys.exit(0)
if not os.path.exists(priv):
- print '[INFO] The private key does not exist'
+ print('[INFO] The private key does not exist')
sys.exit(0)
if not os.path.exists(intermediate):
sys.exit(0)
if not os.path.exists(intermediate):
- print '[INFO] The intermediate certificate does not exist'
+ print('[INFO] The intermediate certificate does not exist')
if auth:
# Read in and build user dictionary
if not os.path.exists(users):
if auth:
# Read in and build user dictionary
if not os.path.exists(users):
- print '[INFO] The users file does not exist: ' + users
+ print('[INFO] The users file does not exist: ' + users)
sys.exit(0)
userpassdict = {}
user_file = open(users, 'r')
sys.exit(0)
userpassdict = {}
user_file = open(users, 'r')
exec &> >(tee -a "/var/log/ansible-server.log")
cd /opt/onap/ccsdk
exec &> >(tee -a "/var/log/ansible-server.log")
cd /opt/onap/ccsdk
-exec /usr/bin/python RestServer.py
+exec /usr/bin/python3 RestServer.py
+++ /dev/null
-# Base ubuntu with added packages needed for open ecomp
-FROM onap/ccsdk-alpine-image:${ccsdk.distribution.version}
-
-LABEL maintainer="SDN-C Team (sdnc@lists.openecomp.org)"
-
-#ENV http_proxy=http://anonymous:password@one.proxy.att.com:8080
-#ENV https_proxy=http://anonymous:password@one.proxy.att.com:8080
-
-## add more pkgs
-RUN apk update
-RUN apk add vim
-RUN apk add curl
-RUN apk add ansible
-
-
-# copy files needed
-COPY opt /opt/
-
-WORKDIR /opt/onap/ccsdk
-
-#ENTRYPOINT exec startAnsibleServer.sh
-#CMD ["/bin/bash"]
-EXPOSE 8000
-