def delete_si(self): try: confFile = "-c %s" % (self._conf_file) policyArgs = "%s %s %s %s %s" % (confFile, "del", "--proj_name", self._args.proj_name, self._args.policy_name) print "%s" % servicePolicy.main(policyArgs) si_fq_name = [self._args.domain_name, self._args.proj_name, self._args.sc_inst_name] try: si_obj = self._vnc_lib.service_instance_read(fq_name=si_fq_name) si_uuid = si_obj.uuid policy_fq_name = [self._args.domain_name, self._args.proj_name, self._args.sc_policy_name] try: netpo = self._vnc_lib.network_policy_read(policy_fq_name) netpo_uuid = netpo.uuid except NoIdError: policyArgs = "%s %s %s %s %s %s %s %s %s %s" % (confFile, "add", "--svc_list", self._args.sc_inst_name, "--vn_list", self._args.left_vn, self._args.right_vn, "--proj_name", self._args.proj_name, self._args.sc_policy_name) time.sleep(5) print "%s" % servicePolicy.main(policyArgs) except NoIdError: print "Create the service chained service instance -- EXPLICITLY" print "Deleting service instance %s" % (self._args.instance_name) self._vnc_lib.service_instance_delete(fq_name = self._si_fq_name) return "Deactivated Service" except NoIdError: print "Not Found: Service Instance -%s does not exist" % (self._args.instance_name) return "Service does not exist for this account"
def delete_si(self): try: print "Deleting Network policy attached to this instance" confFile = "-c %s" % (self._conf_file) policyArgs = "%s %s %s %s %s" % (confFile, "del", "--proj_name", self._args.proj_name, self._args.policy_name) print "Policy delete %s" % (policyArgs) print "%s" % servicePolicy.main(policyArgs) print "Deleting service instance %s" % (self._args.instance_name) self._vnc_lib.service_instance_delete(fq_name = self._si_fq_name) return "Cancelled Internet Service" except NoIdError: print "Not Found: Service Instance -%s does not exist" % (self._args.instance_name) return "Service does not exist for this account"
def create_si(self): #check if passed VNs exist if self._args.left_vn: try: self._vnc_lib.virtual_network_read(fq_name = self._left_vn_fq_name) except NoIdError: print "Error: Left VN %s not found" % (self._left_vn_fq_name) return if self._args.right_vn: try: self._vnc_lib.virtual_network_read(fq_name = self._right_vn_fq_name) except NoIdError: print "Error: Right VN %s not found" % (self._right_vn_fq_name) return #get service template try: st_obj = self._vnc_lib.service_template_read(fq_name=self._st_fq_name) st_prop = st_obj.get_service_template_properties() if st_prop == None: print "Error: Service template %s properties not found" % (self._args.template_name) return except NoIdError: return "Error: Service template %s not found" % (self._args.template_name) #create si print "Creating service instance %s" % (self._args.instance_name) project = self._vnc_lib.project_read(fq_name=self._proj_fq_name) try: si_obj = self._vnc_lib.service_instance_read(fq_name=self._si_fq_name) si_uuid = si_obj.uuid print "Service Instance - %s, already exists" % (self._args.instance_name) except NoIdError: si_obj = ServiceInstance(self._args.instance_name, parent_obj = project) si_uuid = self._vnc_lib.service_instance_create(si_obj) si_prop = ServiceInstanceType(left_virtual_network = self._args.left_vn, management_virtual_network = self._args.mgmt_vn, right_virtual_network = self._args.right_vn) #set scale out scale_out = ServiceScaleOutType(max_instances = self._args.max_instances, auto_scale = self._args.auto_scale) si_prop.set_scale_out(scale_out) si_obj.set_service_instance_properties(si_prop) st_obj = self._vnc_lib.service_template_read(id = st_obj.uuid) si_obj.set_service_template(st_obj) self._vnc_lib.service_instance_update(si_obj) if si_uuid is None: return "Error in creating Service Instance - %s" % (self._args.instance_name) else: confFile = "-c %s" % (self._conf_file) policy_fq_name = [self._args.domain_name, self._args.proj_name, self._args.sc_policy_name] try: netpo = self._vnc_lib.network_policy_read(policy_fq_name) if netpo.uuid is None: return "Error in retrieving policy info for %s" % (self._args.sc_policy_name) else: confFile = "-c %s" % (self._conf_file) policyArgs = "%s %s %s %s %s" % (confFile, "del", "--proj_name", self._args.proj_name, self._args.sc_policy_name) print "%s" % servicePolicy.main(policyArgs) except NoIdError: print "Policy %s marked for deletion. Does not exist" % (self._args.sc_policy_name) policyArgs = "%s %s %s %s %s %s %s %s %s %s" % (confFile, "add", "--svc_list", self._args.instance_name, "--vn_list", self._args.left_vn, self._args.right_vn, "--proj_name", self._args.proj_name, self._args.policy_name) time.sleep(5) print "Creating network policy for this service instance" print "%s" % servicePolicy.main(policyArgs) return "Activated Service" return si_uuid