Esempio n. 1
0
    def handle_create(self):
        LOG.info("----------------------Heat engine is starting to deploy Server------------------------------")
        

        '''
        qingcloud_image_id = self.PROPERTIES.get(self.IMAGE_ID)
        qingcloud_login_mode = self.PROPERTIES.get(LOGIN_MODE)
        qingcloud_login_passwd = self.PROPERTIES.get(LOGIN_PASSWD)
        zone = self.PROPERTIES.get(self.ZONE)
        '''
        qingcloud_image_id = self.properties['image_id']
        qingcloud_login_mode = self.properties['login_mode']
        qingcloud_login_passwd = self.properties['login_passwd']
        zone = self.properties['zone']

        '''
        Connect to QingCloud API
        zzxwill
        9/3/2015
        '''
        api_connection = API_Connection()
        conn = api_connection.get_connection(zone)

        self._conn = conn

        ret = conn.run_instances(
                             image_id=qingcloud_image_id,        
                             cpu=1,        
                             memory=1024,        
                             vxnets=['vxnet-0'],
                             login_mode= qingcloud_login_mode,        
                             login_passwd= qingcloud_login_passwd)

        '''
        A sample of returned strings
        {u'action': u'RunInstancesResponse', u'instances': [u'i-kbvq1jio'], u'job_id': u'j-91chniph', u'ret_code': 0}
        '''

        self._return_instance_dict = ret
        global _return_instance_dict_test
        _return_instance_dict_test = ret

        LOG.debug("ret: run_instance: %s" % ret)

        if 'ret_code' in ret.keys():
            return_code = ret['ret_code']
            LOG.info("return code or instance provisioning is: %s" % ret)
            if return_code == 0:
                return True
            else:   # else can be elaborated later per https://docs.qingcloud.com/api/common/error_code.html
                return False



        return ret
Esempio n. 2
0
    def handle_delete(self):
        zone = self.properties['zone']
        LOG.debug("zone: %s" % zone)

        api_connection = API_Connection()
        conn = api_connection.get_connection(zone)
        LOG.debug("_return_instance_dict: %s" % self._return_instance_dict)
        LOG.debug("_return_instance_dict_test: %s" % _return_instance_dict_test)
        #ret = conn.terminate_instances(self._return_instance_dict['instances'])
        ret = conn.terminate_instances(_return_instance_dict_test['instances'])

        self._return_instance_dict_delete = ret
        LOG.debug("return of terminate_instances: %s" % ret)
        return
Esempio n. 3
0
    def handle_create(self):
        LOG.info(
            "----------------------Heat engine is starting to deploy Server------------------------------"
        )
        '''
        qingcloud_image_id = self.PROPERTIES.get(self.IMAGE_ID)
        qingcloud_login_mode = self.PROPERTIES.get(LOGIN_MODE)
        qingcloud_login_passwd = self.PROPERTIES.get(LOGIN_PASSWD)
        zone = self.PROPERTIES.get(self.ZONE)
        '''
        qingcloud_image_id = self.properties['image_id']
        qingcloud_login_mode = self.properties['login_mode']
        qingcloud_login_passwd = self.properties['login_passwd']
        zone = self.properties['zone']
        '''
        Connect to QingCloud API
        zzxwill
        9/3/2015
        '''
        api_connection = API_Connection()
        conn = api_connection.get_connection(zone)

        self._conn = conn

        ret = conn.run_instances(image_id=qingcloud_image_id,
                                 cpu=1,
                                 memory=1024,
                                 vxnets=['vxnet-0'],
                                 login_mode=qingcloud_login_mode,
                                 login_passwd=qingcloud_login_passwd)
        '''
        A sample of returned strings
        {u'action': u'RunInstancesResponse', u'instances': [u'i-kbvq1jio'], u'job_id': u'j-91chniph', u'ret_code': 0}
        '''

        self._return_instance_dict = ret
        global _return_instance_dict_test
        _return_instance_dict_test = ret

        LOG.debug("ret: run_instance: %s" % ret)

        if 'ret_code' in ret.keys():
            return_code = ret['ret_code']
            LOG.info("return code or instance provisioning is: %s" % ret)
            if return_code == 0:
                return True
            else:  # else can be elaborated later per https://docs.qingcloud.com/api/common/error_code.html
                return False

        return ret
Esempio n. 4
0
    def handle_delete(self):
        zone = self.properties['zone']
        LOG.debug("zone: %s" % zone)

        api_connection = API_Connection()
        conn = api_connection.get_connection(zone)
        LOG.debug("_return_instance_dict: %s" % self._return_instance_dict)
        LOG.debug("_return_instance_dict_test: %s" %
                  _return_instance_dict_test)
        #ret = conn.terminate_instances(self._return_instance_dict['instances'])
        ret = conn.terminate_instances(_return_instance_dict_test['instances'])

        self._return_instance_dict_delete = ret
        LOG.debug("return of terminate_instances: %s" % ret)
        return
Esempio n. 5
0
    def handle_create(self):
        '''
        To attach a key pair to an instance
        '''
        LOG.info("Heat engine is starting to associate an IP to an instance")
        #import pdb
        #pdb.set_trace()

        eip_id = self.properties['eip_id']
        instance_id = self.properties['instance_id']
        zone = self.properties['zone']
        conn = API_Connection().get_connection(zone)
        self._conn = conn

        ret = conn.associate_eip(eip=eip_id, instance=instance_id)

        LOG.debug("KeyAttachment--return of associate_eip: %s)" % ret)
        '''
        A sample

        '''
        if 'ret_code' not in ret.keys():
            exc = exception.Error(
                _("Associating an IP to an instance failed without unknown reasons"
                  ))
            raise exc

        ret_code = ret['ret_code']
        if ret_code == 0:
            return True
        else:
            message = None
            if 'message' in ret.keys():
                message = ret['message']
            if not message:
                exc = exception.Error(
                    _(
                        "Associating an IP to an instance failed with reason: %s, code: %s"
                        % message, ret_code))
                raise exc
            else:
                exc = exception.Error(
                    _("Associating an IP to an instance failed with reason: %s"
                      % ret_code))
                raise exc
            return False
Esempio n. 6
0
    def handle_create(self):
        '''
        To attach a key pair to an instance
        '''
        LOG.info("Heat engine is starting to attach a key pair to an instance")
        #import pdb
        #pdb.set_trace()

        key_pair_id = self.properties['key_pair_id']
        instance_id = self.properties['instance_id']
        zone = self.properties['zone']
        conn = API_Connection().get_connection(zone)
        self._conn = conn

        ret = conn.attach_keypairs([key_pair_id], [instance_id])
        LOG.debug("KeyAttachment--return of attach_keypairs: %s)" % ret)
        '''
        A sample
        {u'action': u'AttachKeyPairsResponse', u'job_id': u'j-fd1ww6nr', u'ret_code': 0}
        '''
        if 'ret_code' not in ret.keys():
            exc = exception.Error(
                _("Attachment of key pair to an instance failed without unknown reasons"
                  ))
            raise exc

        ret_code = ret['ret_code']
        if ret_code == 0:
            return True
        else:
            message = None
            if 'message' in ret.keys():
                message = ret['message']
            if not message:
                exc = exception.Error(
                    _(
                        "Attachment of key pair to an instance failed with reason: %s, code: %s"
                        % message, ret_code))
                raise exc
            else:
                exc = exception.Error(
                    _("Attachment of key pair to an instance failed with reason: %s"
                      % ret_code))
                raise exc
            return False
    def handle_create(self):
        """
        To attach a key pair to an instance
        """
        LOG.info("Heat engine is starting to associate an IP to an instance")
        # import pdb
        # pdb.set_trace()

        eip_id = self.properties["eip_id"]
        instance_id = self.properties["instance_id"]
        zone = self.properties["zone"]
        conn = API_Connection().get_connection(zone)
        self._conn = conn

        ret = conn.associate_eip(eip=eip_id, instance=instance_id)

        LOG.debug("KeyAttachment--return of associate_eip: %s)" % ret)

        """
        A sample

        """
        if "ret_code" not in ret.keys():
            exc = exception.Error(_("Associating an IP to an instance failed without unknown reasons"))
            raise exc

        ret_code = ret["ret_code"]
        if ret_code == 0:
            return True
        else:
            message = None
            if "message" in ret.keys():
                message = ret["message"]
            if not message:
                exc = exception.Error(
                    _("Associating an IP to an instance failed with reason: %s, code: %s" % message, ret_code)
                )
                raise exc
            else:
                exc = exception.Error(_("Associating an IP to an instance failed with reason: %s" % ret_code))
                raise exc
            return False
Esempio n. 8
0
    def handle_create(self):
        LOG.info("----------------------Heat engine is starting to create a key pair------------------------------")
        zone = self.properties['zone']
        name = self.properties['name']
        private_key_file = self.properties['private_key_file']

        conn = API_Connection().get_connection(zone)
        self._conn = conn

        ret = conn.create_keypair(name)
        LOG.debug("Key--create_keypair():%s)" % ret)
        '''
        {u'action': u'CreateKeyPairResponse',
        u'private_key': u'-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEAuwKg9F+ms+7QzmKefCVTpgutkz/XUHWUpOqQyBXbN5KHsSbb\nHNTeOY7cowM7kzdbYh+ohcqry9uf7JFg8o7V+kIM9SswWJKTtaM+WPLv4RXoN49L\ner+0KqH2OgmYU4IpdBaaUeXspCU0l7Xy8XK84HbXsuoFB7AtxxlplbTDu64SvzkF\nQNi5MY/L+yCTSrnXVduYIQEMHaFPhMPwHivNWuNCod+cxlFdi584DBfJrduCmR/g\nbWX8abYVNby2wCle5NPiykwWm+nHXrd8Mf+NhA4X1UM+CWxO76FWri9SLr9d11LF\nmNNo4eIb99kUx1lDPtoRbkte8Ab/pQgF//aSGQIDAQABAoIBAB078vdgwImeSqwI\nxKe5mhL5/l9nenxMdTk2pf1xVTyhvm6W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+SfCYjMjBClDcnhypWJt8qged1hXZmZrAMIM8Ix+X2qdtbrVmtj82yWLzdnL9\nUGc9MZYgqnDPsyQTdS/HLrhytDaiwGzorFY+8LnzLe8W2oHwz5laJA==\n-----END RSA PRIVATE KEY-----\n',
        u'keypair_id': u'kp-1kaua86u',
        u'ret_code': 0})
        '''
        if 'ret_code' not in ret.keys() or 'keypair_id' not in ret.keys():
            exc = exception.Error(_("Creation of key pair failed  without unknown reasons"))
            raise exc

        ret_code = ret['ret_code']
        if ret_code == 0:
            if 'private_key' in ret.keys():
                global private_key
                private_key = ret['private_key']
                key_file = open(private_key_file, 'w')
                key_file.write(private_key)
                key_file.close()

            global _key_pair_id
            _key_pair_id = ret['keypair_id']
            return _key_pair_id
        else:
            if 'message' in ret.keys():
                message = ret['message']
            if not message:
                exc = exception.Error(_("Creation of key pair failed  failed to provision with reason: %s, code: %s" % message, ret_code))
                raise exc
            else:
                exc = exception.Error(_("Creation of key pair failed  failed to provision with reason: %s" % ret_code))
                raise exc
    def handle_create(self):
        '''
        To attach a key pair to an instance
        '''
        LOG.info("Heat engine is starting to attach a key pair to an instance")
        #import pdb
        #pdb.set_trace()

        key_pair_id = self.properties['key_pair_id']
        instance_id = self.properties['instance_id']
        zone = self.properties['zone']
        conn = API_Connection().get_connection(zone)
        self._conn = conn

        ret = conn.attach_keypairs([key_pair_id], [instance_id])
        LOG.debug("KeyAttachment--return of attach_keypairs: %s)" % ret)

        '''
        A sample
        {u'action': u'AttachKeyPairsResponse', u'job_id': u'j-fd1ww6nr', u'ret_code': 0}
        '''
        if 'ret_code' not in ret.keys():
            exc = exception.Error(_("Attachment of key pair to an instance failed without unknown reasons"))
            raise exc

        ret_code = ret['ret_code']
        if ret_code == 0:
            return True
        else:
            message = None
            if 'message' in ret.keys():
                message = ret['message']
            if not message:
                exc = exception.Error(_("Attachment of key pair to an instance failed with reason: %s, code: %s" % message, ret_code))
                raise exc
            else:
                exc = exception.Error(_("Attachment of key pair to an instance failed with reason: %s" % ret_code))
                raise exc
            return False