def configureListeners(self, farmNo, loadBalancerNo) :
        table = self.conn.getTable("LOAD_BALANCER_LISTENER")
        listeners = self.conn.select(table.select(table.c.LOAD_BALANCER_NO==loadBalancerNo))

        # リスナーの起動・停止処理
        for listener in listeners :
            status = self.getStatusString(listener["STATUS"])
            if isBit(listener["ENABLED"]):
                if status == self.STOPPED :
                    # 有効で停止しているリスナーは処理対象
                    self.startListener(farmNo, loadBalancerNo, listener["LOAD_BALANCER_PORT"])
                elif status == self.RUNNING:
                    # 有効で起動しているリスナーの場合、処理を行わずにフラグを変更する
                    if isBit(listener["CONFIGURE"]):
                        listener["CONFIGURE"] = "0"
                        sql = table.update(and_(table.c.LOAD_BALANCER_NO ==listener["LOAD_BALANCER_NO"], table.c.LOAD_BALANCER_PORT == listener["LOAD_BALANCER_PORT"]), values=listener)
                        self.conn.execute(sql)

            else :
                if (status == self.RUNNING or status == self.WARNING) :
                    # 無効で起動または異常なリスナーは処理対象
                    self.stopListener(farmNo, loadBalancerNo, listener["LOAD_BALANCER_PORT"])
                elif (status == self.STOPPED) :
                    # 無効で停止しているリスナーの場合、処理を行わずにフラグを変更する
                    if isBit(listener["CONFIGURE"]):
                        listener["CONFIGURE"] = "0"
                        sql = table.update(and_(table.c.LOAD_BALANCER_NO ==loadBalancerNo, table.c.LOAD_BALANCER_PORT == listener["LOAD_BALANCER_PORT"]), values=listener)
                        self.conn.execute(sql)
    def configureListeners(self, farmNo, loadBalancerNo) :
        table = self.conn.getTable("LOAD_BALANCER_LISTENER")
        listeners = self.conn.select(table.select(table.c.LOAD_BALANCER_NO==loadBalancerNo))

        # リスナーの起動・停止処理
        for listener in listeners :
            status = self.getStatusString(listener["STATUS"])
            if isBit(listener["ENABLED"]):
                if status == self.STOPPED :
                    # 有効で停止しているリスナーは処理対象
                    self.startListener(farmNo, loadBalancerNo, listener["LOAD_BALANCER_PORT"])
                elif status == self.RUNNING:
                    # 有効で起動しているリスナーの場合、処理を行わずにフラグを変更する
                    if isBit(listener["CONFIGURE"]):
                        listener["CONFIGURE"] = "0"
                        sql = table.update(and_(table.c.LOAD_BALANCER_NO ==listener["LOAD_BALANCER_NO"], table.c.LOAD_BALANCER_PORT == listener["LOAD_BALANCER_PORT"]), values=listener)
                        self.conn.execute(sql)

            else :
                if (status == self.RUNNING or status == self.WARNING) :
                    # 無効で起動または異常なリスナーは処理対象
                    self.stopListener(farmNo, loadBalancerNo, listener["LOAD_BALANCER_PORT"])
                elif (status == self.STOPPED) :
                    # 無効で停止しているリスナーの場合、処理を行わずにフラグを変更する
                    if isBit(listener["CONFIGURE"]):
                        listener["CONFIGURE"] = "0"
                        sql = table.update(and_(table.c.LOAD_BALANCER_NO ==loadBalancerNo, table.c.LOAD_BALANCER_PORT == listener["LOAD_BALANCER_PORT"]), values=listener)
                        self.conn.execute(sql)
    def configureLoadBalancer(self, loadBalancerNo):
        table = self.conn.getTable("LOAD_BALANCER")
        loadBalancer = self.conn.selectOne(table.select(table.c.LOAD_BALANCER_NO==loadBalancerNo))

        # リスナーの設定
        try :
            self.loadBalancercontroller.configureListeners(loadBalancer["FARM_NO"], loadBalancerNo)
        except Exception:
            self.logger.error(traceback.format_exc())
            # ロードバランサが無効な場合は例外を握りつぶす
            if isBit(loadBalancer["ENABLED"]):
                raise

        # ヘルスチェックの設定
        try :
            self.loadBalancercontroller.configureHealthCheck(loadBalancer["FARM_NO"], loadBalancerNo)
        except Exception:
            self.logger.error(traceback.format_exc())
            # ロードバランサが無効な場合は例外を握りつぶす
            if isBit(loadBalancer["ENABLED"]):
                raise

        # セキュリティグループの設定
        try :
            # サブネットID
            subnets = self.client.describeSubnets()

            # セキュリティグループ
            groups = self.client.describeSecurityGroups()
            groupmap = {}
            for group in groups:
                if group.vpcId is not None:
                    key = group.groupName+group.vpcId
                    groupmap.update({key:group.groupId})

            self.loadBalancercontroller.applySecurityGroupsToLoadBalancer(loadBalancer["FARM_NO"], loadBalancerNo, groupmap, subnets)
        except Exception:
            self.logger.error(traceback.format_exc())
            # ロードバランサが無効な場合は例外を握りつぶす
            if isBit(loadBalancer["ENABLED"]):
                raise

        # インスタンスの振り分け設定
        try :
            self.loadBalancercontroller.configureInstances(loadBalancer["FARM_NO"], loadBalancerNo);
        except Exception:
            self.logger.error(traceback.format_exc())
            # ロードバランサが無効な場合は例外を握りつぶす
            if isBit(loadBalancer["ENABLED"]):
                raise

        self.logger.info(None, "IPROCESS-200106", [loadBalancerNo, loadBalancer["LOAD_BALANCER_NAME"]])

        self.conn.commit()
        return "RESULT:TRUE"
    def configureInstances(self, loadBalancerNo):
        tableLBINS = self.conn.getTable("LOAD_BALANCER_INSTANCE")
        loadBalancerInstances = self.conn.select(
            tableLBINS.select(tableLBINS.c.LOAD_BALANCER_NO == loadBalancerNo))

        # 振り分け設定するインスタンスがない場合はスキップ
        if not loadBalancerInstances or len(loadBalancerInstances) == 0:
            return

        tableLB = self.conn.getTable("LOAD_BALANCER")
        loadBalancer = self.conn.selectOne(
            tableLB.select(tableLB.c.LOAD_BALANCER_NO == loadBalancerNo))

        # 振り分けを登録・解除するインスタンスを仕分けする
        enabledInstances = []
        disabledInstances = []

        # 振り分けするインスタンス情報を取得
        instanceMap = {}
        for loadBalancerInstance in loadBalancerInstances:
            table = self.conn.getTable("INSTANCE")
            instanceNo = loadBalancerInstance["INSTANCE_NO"]

            #インスタンス獲得
            instance = self.conn.selectOne(
                table.select(table.c.INSTANCE_NO == instanceNo))
            instanceMap.update({instanceNo: instance})

            # ロードバランサが無効の場合は振り分けを解除する
            if not isBit(loadBalancer["ENABLED"]):
                disabledInstances.append(instance)
                continue
            # インスタンスが無効の場合は振り分けを解除する
            if not isBit(instance["ENABLED"]):
                disabledInstances.append(instance)
                continue

            if isBit(loadBalancerInstance["ENABLED"]):
                enabledInstances.append(instance)
            else:
                disabledInstances.append(instance)

        # 振り分けを登録する
        self.registerInstances(loadBalancerNo, loadBalancer["FARM_NO"],
                               enabledInstances, loadBalancerInstances)
        # 振り分けを解除する
        self.unregisterInstances(loadBalancerNo, loadBalancer["FARM_NO"],
                                 disabledInstances, loadBalancerInstances)
Esempio n. 5
0
    def stopInstance(self, instanceNo):
        #VAPPロック
        self.doWaitingExecution(self.getVappName(instanceNo=instanceNo))

        #仮想マシンを停止
        self.instancecontroller.stopInstance(instanceNo)

        # ボリュームに関する処理
        tableDsk = self.conn.getTable("VCLOUD_DISK")
        volumes = self.conn.select(tableDsk.select(tableDsk.c.INSTANCE_NO==instanceNo))
        for disk in volumes:
            #アンデタッチの場合抜ける
            if getTrueFalseProperty("unDetachVolume"):
                break

            # filestorage は外さない
            if isBit(disk["DATA_DISK"]):
                continue

            #Volumのストップ
            self.volumecontroller.stopVolume(instanceNo, disk["DISK_NO"])

        #VAPPロック解除
        self.doWaitingExecutionEnd()
        self.conn.commit()
        return True
    def configureInstances(self, loadBalancerNo) :
        tableLBINS = self.conn.getTable("LOAD_BALANCER_INSTANCE")
        loadBalancerInstances = self.conn.select(tableLBINS.select(tableLBINS.c.LOAD_BALANCER_NO==loadBalancerNo))

        # 振り分け設定するインスタンスがない場合はスキップ
        if not loadBalancerInstances or len(loadBalancerInstances) == 0:
            return

        tableLB = self.conn.getTable("LOAD_BALANCER")
        loadBalancer = self.conn.selectOne(tableLB.select(tableLB.c.LOAD_BALANCER_NO==loadBalancerNo))

        # 振り分けを登録・解除するインスタンスを仕分けする
        enabledInstances = []
        disabledInstances = []

        # 振り分けするインスタンス情報を取得
        instanceMap = {}
        for loadBalancerInstance in loadBalancerInstances :
            table = self.conn.getTable("INSTANCE")
            instanceNo = loadBalancerInstance["INSTANCE_NO"]

            #インスタンス獲得
            instance = self.conn.selectOne(table.select(table.c.INSTANCE_NO == instanceNo))
            instanceMap.update({instanceNo:instance})

            # ロードバランサが無効の場合は振り分けを解除する
            if not isBit(loadBalancer["ENABLED"]):
                disabledInstances.append(instance)
                continue;
            # インスタンスが無効の場合は振り分けを解除する
            if not isBit(instance["ENABLED"]):
                disabledInstances.append(instance);
                continue;

            if isBit(loadBalancerInstance["ENABLED"]):
                enabledInstances.append(instance)
            else :
                disabledInstances.append(instance)

        # 振り分けを登録する
        self.registerInstances(loadBalancerNo, loadBalancer["FARM_NO"], enabledInstances, loadBalancerInstances)
        # 振り分けを解除する
        self.unregisterInstances(loadBalancerNo, loadBalancer["FARM_NO"], disabledInstances, loadBalancerInstances)
 def configureLoadBalancer(self, loadBalancerNo):
     table = self.conn.getTable("LOAD_BALANCER")
     loadBalancer = self.conn.selectOne(table.select(table.c.LOAD_BALANCER_NO==loadBalancerNo))
     # インスタンスの振り分け設定
     try :
         self.loadBalancercontroller.configureInstances(loadBalancerNo);
     except Exception, e:
         self.logger.error(traceback.format_exc())
         # ロードバランサが無効な場合は例外を握りつぶす
         if not isBit(loadBalancer["ENABLED"]):
             raise
    def _change_vm_nw(self, vm_id, vm_nw):
        rasd_ns = "{http://www.vmware.com/vcloud/v1.5}"

        indexList = ["0","1","2","3","4","5","6","7","8","9","10",]

        #リストを名称キーのマップへ変換
        editmap = {}
        makemap = {}
        for nw in vm_nw:
            if nw["NETWORK_INDEX"] is not None:
                editmap[str(nw["NETWORK_INDEX"])] = nw
            else:
                makemap[str(nw["NETWORK_NO"])] = nw

        isEdit = False
        vms = self._get_vm_elements(vm_id)
        for vm in vms:
            res = self.requestLoop('%s/networkConnectionSection' % get_url_path(vm.get('href')))
            def_primary_index = res.object.find(fixxpath(res.object, 'PrimaryNetworkConnectionIndex')).text
            primary_index = def_primary_index
            net_conns = res.object.findall(fixxpath(res.object, 'NetworkConnection'))
            for item in net_conns:
                name = item.get('network')
                index = item.find(fixxpath(item, 'NetworkConnectionIndex')).text
                #対象の設定を取得
                if not editmap.has_key(index):
                    #取得できなければこのNWは削除
                    res.object.remove(item)
                    isEdit = True
                else:
                    #利用済インデックスをリストから削除
                    indexList.remove(index)
                    #取得できれば設定を比較
                    newNw = editmap.pop(index)

                    #Primary チェック
                    if isBit(newNw["IS_PRIMARY"]):
                        primary_index = newNw["NETWORK_INDEX"]

                    #IPMODE
                    if newNw["IP_MODE"] != item.find(fixxpath(item, 'IpAddressAllocationMode')).text:
                        item.find(fixxpath(item, 'IpAddressAllocationMode')).text = newNw["IP_MODE"]
                        isEdit = True
                        if newNw["IP_MODE"] == "MANUAL":
                            #設定「MANUAL」の場合はアドレスも変更する
                            item.find(fixxpath(item, 'IpAddress')).text = newNw["IP_ADDRESS"]
                    else:
                        if newNw["IP_ADDRESS"] != item.find(fixxpath(item, 'IpAddress')).text:
                            #IPアドレスのみ変更する場合
                            item.find(fixxpath(item, 'IpAddress')).text = newNw["IP_ADDRESS"]
                            isEdit = True

            #邪魔なのでLinkタグを消す
            link = res.object.find(fixxpath(res.object, 'Link'))
            res.object.remove(link)

            #追加ネットワークの登録
            if len(makemap) > 0:
                for key in makemap:
                    newNw = makemap[key]
                    networkConnection = ET.Element('%sNetworkConnection' % rasd_ns,
                                              {'network': newNw["NETWORK_NAME"]}
                                            )
                    ET.SubElement(networkConnection, '%sNetworkConnectionIndex' % rasd_ns).text = str(indexList[0])

                    #Primary チェック
                    if isBit(newNw["IS_PRIMARY"]):
                        primary_index = indexList[0]

                    if isNotEmpty(newNw["IP_ADDRESS"]):
                        ET.SubElement(networkConnection, '%sIpAddress' % rasd_ns).text = newNw["IP_ADDRESS"]
                    ET.SubElement(networkConnection, '%sIsConnected' % rasd_ns).text = "true"
                    ET.SubElement(networkConnection, '%sIpAddressAllocationMode' % rasd_ns).text = newNw["IP_MODE"]

                    res.object.append(networkConnection)
                    isEdit  = True
                    indexList.remove(indexList[0])


            if str(def_primary_index) != str(primary_index):
                #プライマリの再設定
                res.object.find(fixxpath(res.object, 'PrimaryNetworkConnectionIndex')).text = str(primary_index)
                isEdit  = True

            #取っ払ったLinkを戻す
            res.object.append(link)
            self.logger.info(ET.tostring(res.object))
            #変更を行った場合のみ通信する
            if isEdit:
                self.logger.info(ET.tostring(res.object))
                res = self.requestLoop(
                    '%s/networkConnectionSection' % get_url_path(vm.get('href')),
                    data=ET.tostring(res.object),
                    method='PUT',
                    headers={'Content-Type': 'application/vnd.vmware.vcloud.networkConnectionSection+xml'}
                )
                self._wait_for_task_completion(res.object.get('href'))