AttributeError: 'NoneType' object has no attribute '_product'

0

I'm trying to do a project with Python and Docker, but I'm having some programming problems. I have 2 files with error that are ProvisionOps.py and DockerOps.py.

Follow ProvisionOps.py

    #!/usr/bin/python
    # -*- coding: UTF-8 -*-
    #ProvisionOps.py

    from Service import Service as ServiceClass
    from ServiceDao import ServiceDao
    from DockerOps import DockerOps

  class ProvisionOps:

  _id = ""

def __init__(self,id):
    self._id = id

def InstallService(self):
    service = ServiceClass()
    service._id = self._id

    sd = ServiceDao(service)
    service = sd.get()

    print "Sera instalado o Produto ( %s ) para o Client ( %s )"%(service._product._name,service._client._name)
    docker = DockerOps()
    res = docker.createContainer(service._id,service._product._image)

def RemoveService():
    pass

And DockerOps.py

   #!/usr/bin/python
   # -*- coding: UTF-8 -*-
  #DockerOps.py

  from SshOps import SshOps

  class DockerOps:

def __init__(self):
    pass

def createContainer(self,id,image):
    command = "docker run -d -ti --name %s %s"%("%s_%s"%(image,id),'debian')
    ssh = SshOps()
    res = ssh.runCommand(command)
    if res['status'] == 1:
        print res['message']
    else:
        command = "docker exec %s apt-get update %s"%(id,image)
        res = ssh.runCommand(command)

def removeContainer(self,id,image):
    command = "docker stop %s"%("%s_%s"%(image,id))
    ssh = SshOps()
    res = ssh.runCommand(command)
    if res['status'] == 1:
        print res['message']

    command = "docker rm %s"%("%s_%s"%(image,id))
    res = ssh.runCommand(command)
    if res['status'] == 1:
        print res['message']
    else:
        print res['message']

And when I run the main file it gives this error

  python DevOps.py 
  Existem 11 servicos na fila 
  Instalando servico:  3
  Sera instalado o Produto ( Backup ) para o Client ( XPTO2 )
  /usr/lib/python2.7/dist-packages/Crypto/Cipher/blockalgo.py:141:       FutureWarning: CTR mode needs counter parameter, not IV
    self._cipher = factory.new(key, *args, **kwargs)
        docker: Error response from daemon: Conflict. The container name       "/backup_3" is already in use by container "36fdfa851993eb5f8dba38b3b3edbe423a4a46aa821ffd4de4c21143a0d78d56". You have       to remove (or rename) that container to be able to reuse that name.
  See 'docker run --help'.

  Instalando servico:  5
  Traceback (most recent call last):
    File "DevOps.py", line 27, in <module>
      Start()
    File "DevOps.py", line 24, in Start
      res = prov.InstallService()
    File "/home/vitor/Documentos/Udemy/Python/Códigos/0 - Projeto       Devops/ProvisionOps.py", line 23, in InstallService
      print "Sera instalado o Produto ( %s ) para o Client ( %s       )"%(service._product._name,service._client._name)
  AttributeError: 'NoneType' object has no attribute '_product'

The file ServiceDao.py

     #!/usr/bin/python
     # -*- coding: UTF-8 -*-
      #ServiceDao.py

   from Service import Service as ServiceClass
   from Client import Client as ClientClass
   from Product import Product as ProductClass
   from Model import Service as ServiceTable,Client,Product, session

   class ServiceDao:

   def __init__(self,service=""):
    self._service = service

   def get(self):
    try:
        service = session.query(ServiceTable,Client,Product).join(Client,Product).filter(ServiceTable.id==self._service._id).first()

        if service is None:
            return None
        else:
            c = ClientClass(service.Client.name,service.Client.cpf,service.Client.segment)
            c._id = service.Client.id

            p = ProductClass(service.Product.name,service.Product.description,service.Product.image)
            p._id = service.Product.id

            s = ServiceClass(service.Service.request_date,service.Service.cancel_date)
            s._id = service.Service.id
            s._client = c
            s._product = p

            return s
    except Exception as e:
        print "Erro: ",e

The error is in this '_product' but I tried to remove change etc but I do not know how to solve this problem.

Would anyone know how to solve this problem?

Hugs

    
asked by anonymous 12.04.2017 / 00:05

0 answers